1 ; get arguments from command line (when DOS supports it)
3 ; Freddy Offenga, 4/21/2000
5 ; initmainargs is forcibly included by the C compiler if it encounters a
6 ; main() function with arguments. Therefore it isn't referenced by the
7 ; startup code but is nevertheless included in the compiled program when
10 MAXARGS = 16 ; max. amount of arguments in arg. table
11 CL_SIZE = 64 ; command line buffer size
12 SPACE = 32 ; SPACE char.
15 .import __argc, __argv
18 .constructor initmainargs, 25
20 ; --------------------------------------------------------------------------
26 lda __dos_type ; which DOS?
28 beq nargdos ; DOS does not support arguments
30 bne argdos ; DOS supports arguments
33 ; Initialize ourcl buffer
38 ; Move SpartaDOS command line to our own buffer
58 sta ourcl,y ; null terminate behind ATEOL
60 ; Turn command line into argv table
64 eatspc: lda ourcl,y ; eat spaces
68 bne rpar ; begin of argument found
72 beq finargs ; only spaces is no argument
74 ; Store argument vector
76 rpar: lda __argc ; low-byte
96 cpx #ATEOL ; end of line?
104 ; End of arg. -> place 0
110 cpx #ATEOL ; was it the last arg?
128 ; --------------------------------------------------------------------------
133 argv: .res (1 + MAXARGS) * 2
135 ; Buffer for command line / argv strings
137 ourcl: .res CL_SIZE+1