]> git.sur5r.net Git - cc65/blob - libsrc/cbm/getdevice.s
Remove trailings spaces from CBM-related asm files
[cc65] / libsrc / cbm / 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         .import         isdisk
11         .import         opencmdchannel
12         .import         closecmdchannel
13         .importzp       ST
14         .importzp       tmp2
15
16 ;------------------------------------------------------------------------------
17 ; _getfirstdevice
18
19 _getfirstdevice:
20         lda     #$FF
21         ; Fall through
22
23 ;------------------------------------------------------------------------------
24 ; _getnextdevice
25
26 _getnextdevice:
27         tax
28 next:   inx
29         cpx     #$FF
30         beq     done
31
32 ; [open|close]cmdchannel already call isdisk internally but they
33 ; interpret a non-disk as a no-op while we need to interpret it
34 ; as an error here
35
36         jsr     isdisk
37         bcs     next
38
39 ; [open|close]cmdchannel don't call into the Kernal at all if they
40 ; only [in|de]crement the reference count of the shared cmdchannel
41 ; so we need to explicitly initialize ST here
42
43         lda     #$00
44         sta     ST
45
46         stx     tmp2
47         jsr     opencmdchannel
48         ldx     tmp2
49         jsr     closecmdchannel
50         ldx     tmp2
51
52 ; As we had to reference ST above anyway we can as well do so
53 ; here too (instead of calling READST)
54
55         lda     ST
56
57 ; Either the Kernal calls above were successfull or there was
58 ; already a cmdchannel to the device open - which is a pretty
59 ; good indication of its existence ;-)
60
61         bmi     next
62
63 done:   txa
64         ldx     #$00
65         rts