]> git.sur5r.net Git - cc65/blob - libsrc/c64/getdevice.s
Introduced mass-storage device enumaration - with implementation for C64 and C128.
[cc65] / libsrc / c64 / getdevice.s
1 ;
2 ; Oliver Schmidt, 2012-09-04
3 ;
4 ; unsigned char getfirstdevice (void);
5 ; unsigned char __fastcall__ getnextdevice (unsigned char device);
6 ;
7
8         .export         _getfirstdevice
9         .export         _getnextdevice
10
11         .import         isdisk
12         .import         opencmdchannel
13         .import         closecmdchannel
14         .importzp       tmp2
15
16         .include        "c64.inc"
17
18 ;------------------------------------------------------------------------------
19 ; _getfirstdevice
20
21 _getfirstdevice:
22         lda     #$FF
23         ; Fall through
24
25 ;------------------------------------------------------------------------------
26 ; _getnextdevice
27
28 _getnextdevice:
29         tax
30 next:   inx
31         cpx     #$FF
32         beq     done
33
34 ; [open|close]cmdchannel already call isdisk internally but they
35 ; interpret a non-disk as a no-op while we need to interpret it
36 ; as an error here
37
38         jsr     isdisk
39         bcs     next
40
41 ; [open|close]cmdchannel don't call into the Kernal at all if they
42 ; only [in|de]crement the reference count of the shared cmdchannel
43 ; so we need to explicitly initialize ST here
44
45         lda     #$00
46         sta     ST
47
48         stx     tmp2
49         jsr     opencmdchannel
50         ldx     tmp2
51         jsr     closecmdchannel
52         ldx     tmp2
53
54 ; As we had to reference ST above anyway we can as well do so
55 ; here too (instead of calling READST)
56
57         lda     ST
58
59 ; Either the Kernal calls above were successfull or there was
60 ; already a cmdchannel to the device open - which is a pretty
61 ; good indication of its existence ;-)
62
63         bmi     next
64
65 done:   txa
66         ldx     #$00
67         rts