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 ; XDOS support added 05/2016 by Christian Groessler
12 MAXARGS = 16 ; max. amount of arguments in arg. table
13 CL_SIZE = 64 ; command line buffer size
14 SPACE = 32 ; SPACE char.
17 .import __argc, __argv
20 .constructor initmainargs, 25
22 ; --------------------------------------------------------------------------
30 lda __dos_type ; which DOS?
31 cmp #MAX_DOS_WITH_CMDLINE + 1
34 ; Initialize ourcl buffer
39 ; Move SpartaDOS/XDOS command line to our own buffer
68 sta ourcl,y ; null terminate behind ATEOL
70 ; Turn command line into argv table
74 eatspc: lda ourcl,y ; eat spaces
78 bne rpar ; begin of argument found
82 beq finargs ; only spaces is no argument
84 ; Store argument vector
86 rpar: lda __argc ; low-byte
106 cpx #ATEOL ; end of line?
114 ; End of arg. -> place 0
120 cpx #ATEOL ; was it the last arg?
138 ; --------------------------------------------------------------------------
143 argv: .res (1 + MAXARGS) * 2
145 ; Buffer for command line / argv strings
147 ourcl: .res CL_SIZE+1