]> git.sur5r.net Git - cc65/blob - libsrc/atari/getdefdev.s
Merge pull request #294 from greg-king5/standard-functions
[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 ; 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         .include        "atari.inc"
18         .import         __dos_type
19         .export         __getdefdev             ; get default device
20         .export         __defdev                ; this is the default device string (e.g. "D1:")
21 .ifdef  DYNAMIC_DD
22         .constructor    __getdefdev, 24
23 .endif
24
25 ; Get default device (LBUF will be destroyed!!)
26
27 __getdefdev:
28
29         lda     __dos_type      ; which DOS?
30         cmp     #ATARIDOS
31         beq     finish
32         cmp     #MYDOS
33         beq     finish
34
35         ldy     #BUFOFF
36         lda     #0
37         sta     (DOSVEC),y      ; reset buffer offset
38
39 ; Store dummy argument
40
41         ldy     #LBUF
42         lda     #'X'
43         sta     (DOSVEC),y
44         iny
45         lda     #ATEOL
46         sta     (DOSVEC),y
47
48 ; One extra store to avoid the buggy sequence from OS/A+ DOS:
49 ; <D><RETURN><:> => drive number = <RETURN>
50
51         iny
52         sta     (DOSVEC),y
53
54 ; Create crunch vector
55
56         ldy     #ZCRNAME+1
57         lda     (DOSVEC),y
58         sta     crvec+1
59         iny
60         lda     (DOSVEC),y
61         sta     crvec+2
62
63 crvec:  jsr     $FFFF           ; will be set to crunch vector
64
65 ; Get default device
66
67         ldy     #COMFNAM        ;  COMFNAM is always "Dn:"
68         lda     (DOSVEC),y
69         sta     __defdev
70         iny
71         lda     (DOSVEC),y
72         sta     __defdev+1
73
74 ; Return pointer to default device
75
76 finish: lda     #<__defdev
77         ldx     #>__defdev
78         rts
79
80         .data
81
82 ; Default device
83
84 __defdev:
85 .ifdef  DEFAULT_DEVICE
86         .byte   'D', '0'+DEFAULT_DEVICE, ':', 0
87 .else
88         .byte   "D1:", 0
89 .endif
90