2 ; Ullrich von Bassewitz, 2003-03-07
3 ; Stefan Haubenthal, 2008-08-11
5 ; Setup arguments for main
8 .constructor initmainargs, 24
13 MAXARGS = 10 ; Maximum number of arguments allowed
14 REM = $8f ; BASIC token-code
15 NAME_LEN = 16 ; maximum length of command-name
19 ;---------------------------------------------------------------------------
20 ; Get possible command-line arguments. Goes into the special INIT segment,
21 ; which may be reused after the startup code is run
27 ; Assume that the program was loaded, a moment ago, by the traditional LOAD
28 ; statement. Save the "most-recent filename" as argument #0.
29 ; Because the buffer, that we're copying into, was zeroed out,
30 ; we don't need to add a NUL character.
35 ldy #NAME_LEN - 1 ; limit the length
40 inc __argc ; argc always is equal to, at least, 1
42 ; Find the "rem" token.
46 beq done ; no "rem," no args.
52 ; Find the next argument
55 beq done ; End of line reached
57 cmp #' ' ; Skip leading spaces
60 ; Found start of next argument. We've incremented the pointer in X already, so
61 ; it points to the second character of the argument. This is useful since we
62 ; will check now for a quoted argument, in which case we will have to skip this
65 found: cmp #'"' ; Is the argument quoted?
66 beq setterm ; Jump if so
67 dex ; Reset pointer to first argument character
68 lda #' ' ; A space ends the argument
69 setterm:sta term ; Set end of argument marker
71 ; Now store a pointer to the argument into the next slot. Since the BASIC
72 ; input buffer is located at the start of a RAM page, no calculations are
76 sta argv,y ; argv[y]= &arg
81 inc __argc ; Found another arg
83 ; Search for the end of the argument
85 argloop:lda BASIC_BUF,x
91 ; We've found the end of the argument. X points one character behind it, and
92 ; A contains the terminating character. To make the argument a valid C string,
93 ; replace the terminating character by a zero.
98 ; Check if the maximum number of command line arguments is reached. If not,
101 lda __argc ; Get low byte of argument count
102 cmp #MAXARGS ; Maximum number of arguments reached?
103 bcc next ; Parse next one if not
105 ; (The last vector in argv[] already is NULL.)
115 ; These arrays are zeroed before initmainargs is called.
117 ; char* argv[MAXARGS+1]={name};
121 name: .res NAME_LEN + 1