]> git.sur5r.net Git - cc65/blob - libsrc/apple2/diosectcount.s
Fixed gcc compiler warning (#867)
[cc65] / libsrc / apple2 / diosectcount.s
1 ;
2 ; Oliver Schmidt, 31.03.2005
3 ;
4 ; unsigned __fastcall__ dio_query_sectcount (dhandle_t handle);
5 ;
6
7         .export         _dio_query_sectcount
8         .import         _dio_query_sectsize, _malloc, _free
9
10         .include        "zeropage.inc"
11         .include        "errno.inc"
12         .include        "mli.inc"
13
14 _dio_query_sectcount:
15
16         ; Set handle
17         sta     mliparam + MLI::ON_LINE::UNIT_NUM
18
19         ; Get ProDOS 8 block size (clears __oserror)
20         jsr     _dio_query_sectsize
21
22         ; Alloc buffer
23         jsr     _malloc
24         sta     ptr4
25         stx     ptr4+1
26
27         ; Set buffer
28         sta     mliparam + MLI::ON_LINE::DATA_BUFFER
29         stx     mliparam + MLI::ON_LINE::DATA_BUFFER+1
30
31         ; Check buffer (hibyte is enough)
32         txa
33         beq     nomem
34
35         ; Get device state
36         lda     #ON_LINE_CALL
37         ldx     #ON_LINE_COUNT
38         jsr     callmli
39         bcs     check
40
41         ; UNIT_NUM already set
42         .assert MLI::RW_BLOCK::UNIT_NUM = MLI::ON_LINE::UNIT_NUM, error
43
44         ; DATA_BUFFER already set
45         .assert MLI::RW_BLOCK::DATA_BUFFER = MLI::ON_LINE::DATA_BUFFER, error
46
47         ; Read volume directory key block
48         tax                     ; A = 0
49         lda     #$02
50         sta     mliparam + MLI::RW_BLOCK::BLOCK_NUM
51         stx     mliparam + MLI::RW_BLOCK::BLOCK_NUM+1
52         lda     #READ_BLOCK_CALL
53         ldx     #RW_BLOCK_COUNT
54         jsr     callmli
55         bcs     oserr
56
57         ; Get and save total blocks from volume directory header
58         ldy     #$29
59         lda     (ptr4),y
60         pha
61         iny
62         lda     (ptr4),y
63         pha
64
65         ; Cleanup buffer
66 done:   lda     ptr4
67         ldx     ptr4+1
68         jsr     _free
69
70         ; Restore total blocks and return
71         pla
72         tax
73         pla
74         rts
75
76 nomem:  lda     #$FF            ; Error code for sure not used by MLI
77 oserr:  sta     __oserror
78
79         ; Save total blocks for failure
80         lda     #$00
81         pha
82         pha
83         beq     done            ; Branch always
84
85         ; Check for non-ProDOS disk
86 check:  cmp     #$52            ; "Not a ProDOS volume"
87         bne     oserr
88         sta     __oserror
89
90         ; Save total blocks for a 16-sector disk
91         lda     #<280
92         pha
93         lda     #>280
94         pha
95         bne     done            ; Branch always