File: getdevice.s

package info (click to toggle)
cc65 2.19-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,268 kB
  • sloc: ansic: 117,151; asm: 66,339; pascal: 4,248; makefile: 1,009; perl: 607
file content (65 lines) | stat: -rw-r--r-- 1,626 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
;
; Oliver Schmidt, 2012-09-04
;
; unsigned char getfirstdevice (void);
; unsigned char __fastcall__ getnextdevice (unsigned char device);
;

        .export         _getfirstdevice
        .export         _getnextdevice
        .import         isdisk
        .import         opencmdchannel
        .import         closecmdchannel
        .importzp       ST
        .importzp       tmp2

;------------------------------------------------------------------------------
; _getfirstdevice

_getfirstdevice:
        lda     #$FF
        ; Fall through

;------------------------------------------------------------------------------
; _getnextdevice

_getnextdevice:
        tax
next:   inx
        cpx     #$FF
        beq     done

; [open|close]cmdchannel already call isdisk internally but they
; interpret a non-disk as a no-op while we need to interpret it
; as an error here

        jsr     isdisk
        bcs     next

; [open|close]cmdchannel don't call into the Kernal at all if they
; only [in|de]crement the reference count of the shared cmdchannel
; so we need to explicitly initialize ST here

        lda     #$00
        sta     ST

        stx     tmp2
        jsr     opencmdchannel
        ldx     tmp2
        jsr     closecmdchannel
        ldx     tmp2

; As we had to reference ST above anyway we can as well do so
; here too (instead of calling READST)

        lda     ST

; Either the Kernal calls above were successfull or there was
; already a cmdchannel to the device open - which is a pretty
; good indication of its existence ;-)

        bmi     next

done:   txa
        ldx     #$00
        rts