]> git.sur5r.net Git - cc65/blob - libsrc/atari/getargs.s
Removed an unused .import
[cc65] / libsrc / atari / getargs.s
1 ; get arguments from command line (when DOS supports it)
2
3 ; Freddy Offenga, 4/21/2000
4
5 MAXARGS = 16            ; max. amount of arguments in arg. table
6 CL_SIZE = 64            ; command line buffer size
7 SPACE   = 32            ; SPACE char.
8
9         .include        "atari.inc"
10         .import         __argc, __argv
11         .importzp       ptr1
12         .import         __dos_type
13         .constructor    initmainargs,25
14
15 ; Get command line
16
17 initmainargs:
18         lda     #0
19         sta     __argc
20         sta     __argc+1
21         sta     __argv
22         sta     __argv+1
23
24         lda     __dos_type      ; which DOS?
25         cmp     #ATARIDOS
26         beq     nargdos         ; DOS does not support arguments
27         cmp     #MYDOS
28         bne     argdos          ; DOS supports arguments
29 nargdos:rts
30
31 ; Initialize ourcl buffer
32
33 argdos: lda     #ATEOL
34         sta     ourcl+CL_SIZE
35          
36 ; Move SpartaDOS command line to our own buffer
37
38         lda     DOSVEC
39         clc
40         adc     #<LBUF
41         sta     ptr1
42         lda     DOSVEC+1
43         adc     #>LBUF
44         sta     ptr1+1
45
46         ldy     #0
47 cpcl:   lda     (ptr1),y
48         sta     ourcl,y
49         iny
50         cmp     #ATEOL
51         beq     movdon
52         cpy     #CL_SIZE
53         bne     cpcl
54
55 movdon: lda     #0
56         sta     ourcl,y         ; null terminate behind ATEOL
57
58 ; Turn command line into argv table
59
60         ;ldy    #0
61         tay
62 eatspc: lda     ourcl,y         ; eat spaces
63         cmp     #ATEOL
64         beq     finargs
65         cmp     #SPACE
66         bne     rpar            ; begin of argument found
67         iny
68         cpy     #CL_SIZE
69         bne     eatspc
70         beq     finargs         ; only spaces is no argument
71
72 ; Store argument vector
73
74 rpar:   lda     __argc          ; low-byte
75         asl
76         tax                     ; table index
77         tya                     ; ourcl index
78         clc
79         adc     #<ourcl
80         sta     argv,x
81         lda     #>ourcl
82         adc     #0
83         sta     argv+1,x
84         ldx     __argc
85         inx
86         stx     __argc
87         cpx     #MAXARGS
88         beq     finargs
89
90 ; Skip this arg.
91
92 skiparg:
93         ldx     ourcl,y
94         cpx     #ATEOL          ; end of line?
95         beq     eopar
96         cpx     #SPACE
97         beq     eopar
98         iny
99         cpy     #CL_SIZE
100         bne     skiparg
101
102 ; End of arg. -> place 0
103
104 eopar:
105         lda     #0
106         sta     ourcl,y
107         iny                     ; y behind arg.
108         cpx     #ATEOL          ; was it the last arg?
109         bne     eatspc
110
111 ; Finish args
112
113 finargs:
114         lda     __argc
115         asl
116         tax
117         lda     #0
118         sta     argv,x
119         sta     argv+1,x
120         lda     #<argv
121         ldx     #>argv
122         sta     __argv
123         stx     __argv+1
124         rts
125
126         .bss
127
128 argv:   .res    (1 + MAXARGS) * 2
129
130 ; Buffer for command line / argv strings
131
132 ourcl:  .res    CL_SIZE+1