]> git.sur5r.net Git - cc65/blob - libsrc/apple2/devicedir.s
I wasn't aware that the unit numbers in the ProDOS device list contain device type...
[cc65] / libsrc / apple2 / devicedir.s
1 ;
2 ; Oliver Schmidt, 2010-05-24
3 ;
4 ; char* __fastcall__ getdevicedir (unsigned char device, char* buf, size_t size);
5 ;
6
7         .export         _getdevicedir
8         .import         popax, popa
9
10         .include        "zeropage.inc"
11         .include        "errno.inc"
12         .include        "mli.inc"
13
14 _getdevicedir:
15         ; Save size
16         sta     ptr2
17         stx     ptr2+1
18
19         ; Save buf
20         jsr     popax
21         sta     ptr1
22         stx     ptr1+1
23
24         ; Set buf
25         sta     mliparam + MLI::ON_LINE::DATA_BUFFER
26         stx     mliparam + MLI::ON_LINE::DATA_BUFFER+1
27
28         ; Set device
29         jsr     popa
30         asl
31         asl
32         asl
33         asl
34         sta     mliparam + MLI::ON_LINE::UNIT_NUM
35
36         ; Check for valid slot
37         and     #$70
38         beq     erange
39
40         ; Check for sufficient buf size
41         lda     ptr2+1
42         bne     :++             ; Buf >= 256
43         lda     ptr2
44         cmp     #17
45         bcs     :++             ; Buf >= 17
46
47         ; Handle errors
48 erange: lda     #<ERANGE
49         jsr     __directerrno
50         bne     :+              ; Branch always
51 oserr:  jsr     __mappederrno
52 :       lda     #$00            ; Return NULL
53         tax
54         rts
55
56         ; Get volume name
57 :       lda     #ON_LINE_CALL
58         ldx     #ON_LINE_COUNT
59         jsr     callmli
60         bcs     oserr
61
62         ; Get volume name length
63         ldy     #$00
64         lda     (ptr1),y
65         and     #15             ; Max volume name length
66         sta     tmp1
67         
68         ; Add leading slash
69         lda     #'/'
70         sta     (ptr1),y
71
72         ; Add terminating zero
73         ldy     tmp1
74         iny
75         lda     #$00
76         sta     (ptr1),y
77         sta     __oserror       ; Clear _oserror
78
79         ; Success, return buf
80         lda     ptr1
81         ldx     ptr1+1
82         rts