]> git.sur5r.net Git - cc65/blob - libsrc/atari/getdefdev.s
atari5200: conio now uses just four colors altogether
[cc65] / libsrc / atari / getdefdev.s
1 ;
2 ; Freddy Offenga & Christian Groessler, December 2004
3 ;
4 ; function to get default device: char *_getdefdev(void);
5 ;
6 ; AtariDOS/MyDOS:
7 ; Default device number is derived from DUNIT. Therefore "default
8 ; device" is the one the program was loaded from.
9 ;
10 ; SpartaDOS/RealDOS:
11 ; the ZCRNAME routine is only used to get the default drive because
12 ; ZCRNAME has two disadvantages:
13 ; 1. It will convert D: into D1: instead of Dn: (n = default drive)
14 ; 2. It will give a 'no arguments' status if it detects something
15 ;    like Dn: (without filename).
16 ;
17 ; OS/A+ DOS:
18 ; ZCRNAME is slightly different from SpartaDOS. It will convert D:
19 ; into Dn: where n is the default drive.
20
21         .include        "atari.inc"
22         .import         __dos_type
23         .export         __getdefdev             ; get default device
24         .export         __defdev                ; this is the default device string (e.g. "D1:")
25 .ifdef  DYNAMIC_DD
26         .constructor    __getdefdev, 24
27 .endif
28
29 ; Get default device (LBUF will be destroyed!!)
30
31 __getdefdev:
32
33         lda     __dos_type      ; which DOS?
34         cmp     #XDOS
35         beq     xdos            ; XDOS detected
36 ;       cmp     #OSADOS+1       ; (redundant: #OSADOS+1 = #XDOS)
37         bcs     use_DUNIT       ; neither XDOS, nor OS/A+ or SpartaDOS
38
39         ldy     #BUFOFF
40         lda     #0
41         sta     (DOSVEC),y      ; reset buffer offset
42
43 ; Store dummy argument
44
45         ldy     #LBUF
46         lda     #'X'
47         sta     (DOSVEC),y
48         iny
49         lda     #ATEOL
50         sta     (DOSVEC),y
51
52 ; One extra store to avoid the buggy sequence from OS/A+ DOS:
53 ; <D><RETURN><:> => drive number = <RETURN>
54
55         iny
56         sta     (DOSVEC),y
57
58 ; Create crunch vector
59
60         ldy     #ZCRNAME+1
61         lda     (DOSVEC),y
62         sta     crvec+1
63         iny
64         lda     (DOSVEC),y
65         sta     crvec+2
66
67         jsr     crvec
68
69 ; Get default device
70
71         ldy     #COMFNAM        ;  COMFNAM is always "Dn:"
72         lda     (DOSVEC),y
73         sta     __defdev
74         iny
75         lda     (DOSVEC),y
76 done:   sta     __defdev+1
77
78 ; Return pointer to default device
79
80 finish: lda     #<__defdev
81         ldx     #>__defdev
82         rts
83
84 ; On AtariDOS or MyDOS, use the DUNIT variable to setup the default
85 ; device. The default device will then be the one the program was
86 ; loaded from.
87
88 use_DUNIT:
89         lda     DUNIT
90         clc
91         adc     #'0'
92         bne     done            ; jump always
93
94 ; XDOS default device retrieval
95
96 xdos:
97
98 ; check XDOS version (we need >= 2.4)
99
100         lda     XGLIN
101         cmp     #$4C            ; there needs to be a 'JMP' opcode here
102         bne     finish          ; older version, use DEFAULT_DEVICE or D1:
103         lda     XVER            ; get BCD encoded version ($24 for 2.4)
104         cmp     #$24
105         bcc     finish          ; too old, below 2.4
106
107 ; good XDOS version, get default drive
108
109         lda     #ATEOL
110         sta     XLINE           ; simulate empty command line
111         ldy     #0
112         jsr     XMOVE           ; create an FMS filename (which in this case only contains the drive)
113         lda     XFILE+1
114         bne     done
115
116         .data
117
118 crvec:  jmp     $FFFF           ; target address will be set to crunch vector
119
120 ; Default device string
121
122 __defdev:
123 .ifdef  DEFAULT_DEVICE
124         .byte   'D', '0'+DEFAULT_DEVICE, ':', 0
125 .else
126         .byte   "D1:", 0
127 .endif