File: getdefdev.s

package info (click to toggle)
cc65 2.19-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,268 kB
  • sloc: ansic: 117,151; asm: 66,339; pascal: 4,248; makefile: 1,009; perl: 607
file content (127 lines) | stat: -rw-r--r-- 3,369 bytes parent folder | download | duplicates (2)
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
;
; Freddy Offenga & Christian Groessler, December 2004
;
; function to get default device: char *_getdefdev(void);
;
; AtariDOS/MyDOS:
; Default device number is derived from DUNIT. Therefore "default
; device" is the one the program was loaded from.
;
; SpartaDOS/RealDOS:
; the ZCRNAME routine is only used to get the default drive because
; ZCRNAME has two disadvantages:
; 1. It will convert D: into D1: instead of Dn: (n = default drive)
; 2. It will give a 'no arguments' status if it detects something
;    like Dn: (without filename).
;
; OS/A+ DOS:
; ZCRNAME is slightly different from SpartaDOS. It will convert D:
; into Dn: where n is the default drive.

        .include        "atari.inc"
        .import         __dos_type
        .export         __getdefdev             ; get default device
        .export         __defdev                ; this is the default device string (e.g. "D1:")
.ifdef  DYNAMIC_DD
        .constructor    __getdefdev, 24
.endif

; Get default device (LBUF will be destroyed!!)

__getdefdev:

        lda     __dos_type      ; which DOS?
        cmp     #XDOS
        beq     xdos            ; XDOS detected
;       cmp     #OSADOS+1       ; (redundant: #OSADOS+1 = #XDOS)
        bcs     use_DUNIT       ; neither XDOS, nor OS/A+ or SpartaDOS

        ldy     #BUFOFF
        lda     #0
        sta     (DOSVEC),y      ; reset buffer offset

; Store dummy argument

        ldy     #LBUF
        lda     #'X'
        sta     (DOSVEC),y
        iny
        lda     #ATEOL
        sta     (DOSVEC),y

; One extra store to avoid the buggy sequence from OS/A+ DOS:
; <D><RETURN><:> => drive number = <RETURN>

        iny
        sta     (DOSVEC),y

; Create crunch vector

        ldy     #ZCRNAME+1
        lda     (DOSVEC),y
        sta     crvec+1
        iny
        lda     (DOSVEC),y
        sta     crvec+2

        jsr     crvec

; Get default device

        ldy     #COMFNAM        ;  COMFNAM is always "Dn:"
        lda     (DOSVEC),y
        sta     __defdev
        iny
        lda     (DOSVEC),y
done:   sta     __defdev+1

; Return pointer to default device

finish: lda     #<__defdev
        ldx     #>__defdev
        rts

; On AtariDOS or MyDOS, use the DUNIT variable to setup the default
; device. The default device will then be the one the program was
; loaded from.

use_DUNIT:
        lda     DUNIT
        clc
        adc     #'0'
        bne     done            ; jump always

; XDOS default device retrieval

xdos:

; check XDOS version (we need >= 2.4)

        lda     XGLIN
        cmp     #$4C            ; there needs to be a 'JMP' opcode here
        bne     finish          ; older version, use DEFAULT_DEVICE or D1:
        lda     XVER            ; get BCD encoded version ($24 for 2.4)
        cmp     #$24
        bcc     finish          ; too old, below 2.4

; good XDOS version, get default drive

        lda     #ATEOL
        sta     XLINE           ; simulate empty command line
        ldy     #0
        jsr     XMOVE           ; create an FMS filename (which in this case only contains the drive)
        lda     XFILE+1
        bne     done

        .data

crvec:  jmp     $FFFF           ; target address will be set to crunch vector

; Default device string

__defdev:
.ifdef  DEFAULT_DEVICE
        .byte   'D', '0'+DEFAULT_DEVICE, ':', 0
.else
        .byte   "D1:", 0
.endif