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 ; --------------------------------------------------------------------------
32 lda __dos_type ; which DOS?
34 beq nargdos ; DOS does not support arguments
36 bne argdos ; DOS supports arguments
39 ; Initialize ourcl buffer
44 ; Move SpartaDOS command line to our own buffer
64 sta ourcl,y ; null terminate behind ATEOL
66 ; Turn command line into argv table
70 eatspc: lda ourcl,y ; eat spaces
74 bne rpar ; begin of argument found
78 beq finargs ; only spaces is no argument
80 ; Store argument vector
82 rpar: lda __argc ; low-byte
102 cpx #ATEOL ; end of line?
110 ; End of arg. -> place 0
116 cpx #ATEOL ; was it the last arg?
134 ; --------------------------------------------------------------------------
139 argv: .res (1 + MAXARGS) * 2
141 ; Buffer for command line / argv strings
143 ourcl: .res CL_SIZE+1