]> git.sur5r.net Git - cc65/blob - libsrc/atari/getdefdev.s
Merge pull request #297 from groessler/something_to_pull
[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     #OSADOS+1
31         bcs     finish          ; only supported on OS/A+ and SpartaDOS
32                                 ; (TODO: add XDOS support)
33
34         ldy     #BUFOFF
35         lda     #0
36         sta     (DOSVEC),y      ; reset buffer offset
37
38 ; Store dummy argument
39
40         ldy     #LBUF
41         lda     #'X'
42         sta     (DOSVEC),y
43         iny
44         lda     #ATEOL
45         sta     (DOSVEC),y
46
47 ; One extra store to avoid the buggy sequence from OS/A+ DOS:
48 ; <D><RETURN><:> => drive number = <RETURN>
49
50         iny
51         sta     (DOSVEC),y
52
53 ; Create crunch vector
54
55         ldy     #ZCRNAME+1
56         lda     (DOSVEC),y
57         sta     crvec+1
58         iny
59         lda     (DOSVEC),y
60         sta     crvec+2
61
62 crvec:  jsr     $FFFF           ; will be set to crunch vector
63
64 ; Get default device
65
66         ldy     #COMFNAM        ;  COMFNAM is always "Dn:"
67         lda     (DOSVEC),y
68         sta     __defdev
69         iny
70         lda     (DOSVEC),y
71         sta     __defdev+1
72
73 ; Return pointer to default device
74
75 finish: lda     #<__defdev
76         ldx     #>__defdev
77         rts
78
79         .data
80
81 ; Default device
82
83 __defdev:
84 .ifdef  DEFAULT_DEVICE
85         .byte   'D', '0'+DEFAULT_DEVICE, ':', 0
86 .else
87         .byte   "D1:", 0
88 .endif
89