]> git.sur5r.net Git - cc65/blob - libsrc/atari/getdevice.s
Just removed some trailing spaces.
[cc65] / libsrc / atari / getdevice.s
1 ;
2 ; Oliver Schmidt, 2012-09-04
3 ; Christian Groessler, 2017-12-28
4 ;
5 ; unsigned char getfirstdevice (void);
6 ; unsigned char __fastcall__ getnextdevice (unsigned char device);
7 ;
8
9         .include        "atari.inc"
10         .export         _getfirstdevice
11         .export         _getnextdevice
12
13 MAX_DIO_DEVICES =       8
14
15 ;------------------------------------------------------------------------------
16 ; _getfirstdevice
17
18 _getfirstdevice:
19         lda     #$FF
20         ; Fall through
21
22 ;------------------------------------------------------------------------------
23 ; _getnextdevice
24
25 _getnextdevice:
26         tax
27 next:   inx
28         cpx     #MAX_DIO_DEVICES
29         beq     none
30
31         jsr     check_device
32         bmi     next
33
34 done:   txa
35         ldx     #$00
36         rts
37
38 none:   ldx     #255            ; INVALID_DEVICE (see include/device.h)
39         bne     done            ; jump always
40
41 ;------------------------------------------------------------------------------
42 ; check_device - checks if a disk device is present
43 ; input:        X  - device id (0 = D1, 1 = D2, ...)
44 ; output:       NF - 0/1 for detected/not detected
45 ; X register preserved
46
47 check_device:
48         txa
49         pha
50         lda     #SIO_STAT
51         sta     DCOMND          ; set command into DCB
52         lda     #%01000000      ; direction value, "receive data"
53         sta     DSTATS          ; set data flow directon
54         lda     #15
55         sta     DTIMLO          ; value got from DOS source
56         lda     #4
57         sta     DAUX1           ; set sector #  (dummy: 4)
58         sta     DBYTLO          ; # of bytes to transfer
59         lda     #0
60         sta     DAUX2
61         sta     DBYTHI
62         lda     #>DVSTAT
63         sta     DBUFHI
64         lda     #<DVSTAT
65         sta     DBUFLO          ; set buffer address into DCB
66         lda     #DISKID         ; SIO bus ID of diskette drive
67         sta     DDEVIC
68         inx
69         stx     DUNIT           ; unit number (1-based)
70
71         jsr     SIOV            ; execute SIO command
72
73         pla
74         tax
75         lda     DSTATS
76         rts
77
78         .end