]> git.sur5r.net Git - cc65/blob - libsrc/atari/getargs.s
info about c1541 in docs, lowered highest available address to $6000 due to
[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 ; Initialize ourcl buffer
40
41 argdos: lda     #ATEOL
42         sta     ourcl+CL_SIZE
43          
44 ; Move SpartaDOS command line to our own buffer
45
46         lda     DOSVEC
47         clc
48         adc     #<LBUF
49         sta     ptr1
50         lda     DOSVEC+1
51         adc     #>LBUF
52         sta     ptr1+1
53
54         ldy     #0
55 cpcl:   lda     (ptr1),y
56         sta     ourcl,y
57         iny
58         cmp     #ATEOL
59         beq     movdon
60         cpy     #CL_SIZE
61         bne     cpcl
62
63 movdon: lda     #0
64         sta     ourcl,y         ; null terminate behind ATEOL
65
66 ; Get default device (LBUF will be destroyed!!)
67
68         ldy     #BUFOFF
69         lda     #0
70         sta     (DOSVEC),y      ; reset buffer offset
71
72 ; Store dummy argument
73
74         ldy     #LBUF
75         lda     #'X'
76         sta     (DOSVEC),y
77         iny
78         lda     #ATEOL
79         sta     (DOSVEC),y
80
81 ; One extra store to avoid the buggy sequence from OS/A+ DOS:
82 ; <D><RETURN><:> => drive number = <RETURN>
83
84         iny
85         sta     (DOSVEC),y
86
87 ; Create crunch vector
88
89         ldy     #ZCRNAME+1
90         lda     (DOSVEC),y
91         sta     crvec+1
92         iny
93         lda     (DOSVEC),y
94         sta     crvec+2
95
96 crvec:  jsr     $FFFF           ; will be set to crunch vector
97
98 ; Get default device
99
100         ldy     #COMFNAM        ;  COMFNAM is always "Dn:"
101         lda     (DOSVEC),y
102         sta     defdev
103         iny
104         lda     (DOSVEC),y
105         sta     defdev+1
106
107 ; Turn command line into argv table
108
109         ldy     #0
110 eatspc: lda     ourcl,y         ; eat spaces
111         cmp     #ATEOL
112         beq     finargs
113         cmp     #SPACE
114         bne     rpar            ; begin of argument found
115         iny
116         cpy     #CL_SIZE
117         bne     eatspc
118         beq     finargs         ; only spaces is no argument
119
120 ; Store argument vector
121
122 rpar:   lda     argc            ; low-byte
123         asl
124         tax                     ; table index
125         tya                     ; ourcl index
126         clc
127         adc     #<ourcl
128         sta     argv,x
129         lda     #>ourcl
130         adc     #0
131         sta     argv+1,x
132         ldx     argc
133         inx
134         stx     argc
135         cpx     #MAXARGS
136         beq     finargs
137
138 ; Skip this arg.
139
140 skiparg:
141         ldx     ourcl,y
142         cpx     #ATEOL          ; end of line?
143         beq     eopar
144         cpx     #SPACE
145         beq     eopar
146         iny
147         cpy     #CL_SIZE
148         bne     skiparg
149
150 ; End of arg. -> place 0
151
152 eopar:
153         lda     #0
154         sta     ourcl,y
155         iny                     ; y behind arg.
156         cpx     #ATEOL          ; was it the last arg?
157         bne     eatspc
158
159 ; Finish args
160
161 finargs:
162         lda     argc
163         asl
164         tax
165         lda     #0
166         sta     argv,x
167         sta     argv+1,x
168         rts
169
170 ; DOS type detection
171
172 detect:
173         lda     DOS
174         cmp     #$53            ; "S" (SpartaDOS)
175         beq     spdos
176
177         ldy     #COMTAB
178         lda     #$4C
179         cmp     (DOSVEC),y
180         bne     nordos
181
182         ldy     #ZCRNAME
183         cmp     (DOSVEC),y
184         bne     nordos
185
186         ldy     #6              ; OS/A+ has a jmp here
187         cmp     (DOSVEC),y
188         beq     nordos
189
190 spdos:  sec                     ; SpartaDOS, OS/A+ or DOS XL
191         rts
192
193 nordos: clc                     ; normal DOS (no args) detected
194         rts
195
196 ; Get default device (set by getargs routine)
197
198 _getdefdev:
199         lda     #<defdev
200         ldx     #>defdev
201         rts
202
203         .data
204
205 ; Default device
206
207 defdev:
208         .byte   "D1:", 0
209
210         .bss
211
212 argc:   .res    2
213 argv:   .res    (1 + MAXARGS) * 2
214
215 ; Buffer for command line / argv strings
216
217 ourcl:  .res    CL_SIZE+1