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
18 ;---------------------------------------------------------------------------
19 ; Get possible command-line arguments. Goes into the special ONCE segment,
20 ; which may be reused after the startup code is run
26 ; Assume that the program was loaded, a moment ago, by the traditional LOAD
27 ; statement. Save the "most-recent filename" as argument #0.
29 lda #0 ; The terminating NUL character
33 ldy #NAME_LEN ; Limit the length
34 bne L1 ; Branch always
39 inc __argc ; argc always is equal to, at least, 1
41 ; Find the "rem" token.
45 beq done ; No "rem," no args.
51 ; Find the next argument
54 beq done ; End of line reached
56 cmp #' ' ; Skip leading spaces
59 ; Found start of next argument. We've incremented the pointer in X already, so
60 ; it points to the second character of the argument. This is useful since we
61 ; will check now for a quoted argument, in which case we will have to skip this
64 found: cmp #'"' ; Is the argument quoted?
65 beq setterm ; Jump if so
66 dex ; Reset pointer to first argument character
67 lda #' ' ; A space ends the argument
68 setterm:sta term ; Set end of argument marker
70 ; Now store a pointer to the argument into the next slot. Since the BASIC
71 ; input buffer is located at the start of a RAM page, no calculations are
75 sta argv,y ; argv[y]= &arg
80 inc __argc ; Found another arg
82 ; Search for the end of the argument
84 argloop:lda BASIC_BUF,x
90 ; We've found the end of the argument. X points one character behind it, and
91 ; A contains the terminating character. To make the argument a valid C string,
92 ; replace the terminating character by a zero.
97 ; Check if the maximum number of command line arguments is reached. If not,
100 lda __argc ; Get low byte of argument count
101 cmp #MAXARGS ; Maximum number of arguments reached?
102 bcc next ; Parse next one if not
104 ; (The last vector in argv[] already is NULL.)
117 name: .res NAME_LEN + 1
121 ; char* argv[MAXARGS+1]={name};