]> git.sur5r.net Git - cc65/blob - libsrc/atari/getargs.s
This commit was generated by cvs2svn to compensate for changes in r2,
[cc65] / libsrc / atari / getargs.s
1 ; get arguments from command line (when DOS supports it)
2 ; and supply function to get default device: char *getdefdev(void);
3
4 ; Freddy Offenga, 4/21/2000
5
6 ; SpartaDOS:
7 ; the ZCRNAME routine is only used to get the default drive because
8 ; ZCRNAME has two disadvantages:
9 ; 1. It will convert D: into D1: instead of Dn: (n = default drive)
10 ; 2. It will give a 'no arguments' status if it detects something
11 ;    like Dn: (without filename).
12
13 ; OS/A+ DOS:
14 ; ZCRNAME is slightly different from SpartaDOS. It will convert D:
15 ; into Dn: where n is the default drive.
16
17 MAXARGS = 16            ; max. amount of arguments in arg. table
18 CL_SIZE = 64            ; command line buffer size
19 SPACE   = 32            ; SPACE char.
20
21         .include "atari.inc"
22         .export getargs, argc, argv
23         .export _getdefdev              ; get default device (e.g. "D1:")
24         .importzp ptr1
25
26 ; Get command line
27
28 getargs:
29         lda     #0
30         sta     argc
31         sta     argc+1
32         sta     argv
33         sta     argv+1
34
35         jsr     detect
36         bcs     argdos          ; carry set = DOS supports arguments
37         rts
38  
39 ; Move SpartaDOS command line to our own buffer
40
41 argdos: lda     DOSVEC
42         clc
43         adc     #<LBUF
44         sta     ptr1
45         lda     DOSVEC+1
46         adc     #>LBUF
47         sta     ptr1+1
48
49         ldy     #0
50 cpcl:   lda     (ptr1),y
51         sta     ourcl,y
52         iny
53         cmp     #ATEOL
54         beq     movdon
55         cpy     #CL_SIZE
56         bne     cpcl
57
58 movdon: lda     #0
59         sta     ourcl,y         ; null terminate behind ATEOL
60
61 ; Get default device (LBUF will be destroyed!!)
62
63         ldy     #BUFOFF
64         lda     #0
65         sta     (DOSVEC),y      ; reset buffer offset
66
67 ; Store dummy argument
68
69         ldy     #LBUF
70         lda     dumpar1
71         sta     (DOSVEC),y
72         iny
73         lda     dumpar2
74         sta     (DOSVEC),y
75
76 ; One extra store to avoid the buggy sequence from OS/A+ DOS:
77 ; <D><RETURN><:> => drive number = <RETURN>
78
79         iny
80         sta     (DOSVEC),y
81
82 ; Create crunch vector
83
84         ldy     #ZCRNAME+1
85         lda     (DOSVEC),y
86         sta     crvec+1
87         iny
88         lda     (DOSVEC),y
89         sta     crvec+2
90
91 crvec:  jsr     $FFFF           ; will be set to crunch vector
92
93 ; Get default device
94
95         ldy     #COMFNAM        ;  COMFNAM is always "Dn:"
96         lda     (DOSVEC),y
97         sta     defdev
98         iny
99         lda     (DOSVEC),y
100         sta     defdev+1
101
102 ; Turn command line into argv table
103
104         ldy     #0
105 eatspc: lda     ourcl,y         ; eat spaces
106         cmp     #ATEOL
107         beq     finargs
108         cmp     #SPACE
109         bne     rpar            ; begin of argument found
110         iny
111         cpy     #CL_SIZE
112         bne     eatspc
113         beq     finargs         ; only spaces is no argument
114
115 ; Store argument vector
116
117 rpar:   lda     argc            ; low-byte
118         asl
119         tax                     ; table index
120         tya                     ; ourcl index
121         clc
122         adc     #<ourcl
123         sta     argv,x
124         lda     #>ourcl
125         adc     #0
126         sta     argv+1,x
127         ldx     argc
128         inx
129         stx     argc
130         cpx     #MAXARGS
131         beq     finargs
132
133 ; Skip this arg.
134
135 skiparg:
136         ldx     ourcl,y
137         cpx     #ATEOL          ; end of line?
138         beq     eopar
139         cpx     #SPACE
140         beq     eopar
141         iny
142         cpy     #CL_SIZE
143         bne     skiparg
144
145 ; End of arg. -> place 0
146
147 eopar:
148         lda     #0
149         sta     ourcl,y
150         iny                     ; y behind arg.
151         cpx     #ATEOL          ; was it the last arg?
152         bne     eatspc
153
154 ; Finish args
155
156 finargs:
157         lda     argc
158         asl
159         tax
160         lda     #0
161         sta     argv,x
162         sta     argv+1,x
163         rts
164
165 ; DOS type detection
166
167 detect:
168         lda     DOS
169         cmp     #$53            ; "S" (SpartaDOS)
170         beq     spdos
171
172         ldy     #COMTAB
173         lda     #$4C
174         cmp     (DOSVEC),y
175         bne     nordos
176
177         ldy     #ZCRNAME
178         cmp     (DOSVEC),y
179         bne     nordos
180
181         ldy     #6              ; OS/A+ has a jmp here
182         cmp     (DOSVEC),y
183         beq     nordos
184
185 spdos:  sec                     ; SpartaDOS, OS/A+ or DOS XL
186         rts
187
188 nordos: clc                     ; normal DOS (no args) detected
189         rts
190
191 ; Get default device (set by getargs routine)
192
193 _getdefdev:
194         lda     #<defdev
195         ldx     #>defdev
196         rts
197
198         .data
199
200 ; Dummy argument to get default device
201
202 dumpar1:
203         .byte   "X"
204 dumpar2:
205         .byte   ATEOL
206
207 ; Buffer for command line / argv strings
208
209 ourcl:  .res    CL_SIZE
210         .byte   ATEOL
211
212 ; Default device
213
214 defdev:
215         .byte   "D1:", 0
216
217         .bss
218
219 argc:   .res    2
220 argv:   .res    (1 + MAXARGS) * 2