1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
; get arguments from command line (when DOS supports it)
; Freddy Offenga, 4/21/2000
; initmainargs is forcibly included by the C compiler if it encounters a
; main() function with arguments. Therefore it isn't referenced by the
; startup code but is nevertheless included in the compiled program when
; needed.
; XDOS support added 05/2016 by Christian Groessler
MAXARGS = 16 ; max. amount of arguments in arg. table
CL_SIZE = 64 ; command line buffer size
SPACE = 32 ; SPACE char.
.include "atari.inc"
.import __argc, __argv
.importzp ptr1
.import __dos_type
.constructor initmainargs, 25
; --------------------------------------------------------------------------
; Get command line
.segment "ONCE"
nargdos:rts
initmainargs:
lda __dos_type ; which DOS?
cmp #MAX_DOS_WITH_CMDLINE + 1
bcs nargdos
; Initialize ourcl buffer
argdos: ldy #ATEOL
sty ourcl+CL_SIZE
; Move SpartaDOS/XDOS command line to our own buffer
cmp #XDOS
bne sparta
lda #<XLINE
sta ptr1
lda #>XLINE
sta ptr1+1
bne cpcl0
sparta: lda DOSVEC
clc
adc #<LBUF
sta ptr1
lda DOSVEC+1
adc #>LBUF
sta ptr1+1
cpcl0: ldy #0
cpcl: lda (ptr1),y
sta ourcl,y
iny
cmp #ATEOL
beq movdon
cpy #CL_SIZE
bne cpcl
movdon: lda #0
sta ourcl,y ; null terminate behind ATEOL
; Turn command line into argv table
;ldy #0
tay
eatspc: lda ourcl,y ; eat spaces
cmp #ATEOL
beq finargs
cmp #SPACE
bne rpar ; begin of argument found
iny
cpy #CL_SIZE
bne eatspc
beq finargs ; only spaces is no argument
; Store argument vector
rpar: lda __argc ; low-byte
asl
tax ; table index
tya ; ourcl index
clc
adc #<ourcl
sta argv,x
lda #>ourcl
adc #0
sta argv+1,x
ldx __argc
inx
stx __argc
cpx #MAXARGS
beq finargs
; Skip this arg.
skiparg:
ldx ourcl,y
cpx #ATEOL ; end of line?
beq eopar
cpx #SPACE
beq eopar
iny
cpy #CL_SIZE
bne skiparg
; End of arg. -> place 0
eopar:
lda #0
sta ourcl,y
iny ; y behind arg.
cpx #ATEOL ; was it the last arg?
bne eatspc
; Finish args
finargs:
lda __argc
asl
tax
lda #0
sta argv,x
sta argv+1,x
lda #<argv
ldx #>argv
sta __argv
stx __argv+1
rts
; --------------------------------------------------------------------------
; Data
.segment "INIT"
argv: .res (1 + MAXARGS) * 2
; Buffer for command line / argv strings
ourcl: .res CL_SIZE+1
|