]> git.sur5r.net Git - cc65/blob - libsrc/cbm/dir.s
Remove trailings spaces from CBM-related asm files
[cc65] / libsrc / cbm / dir.s
1 ;
2 ; Ullrich von Bassewitz, 2012-06-01
3 ;
4 ; Helper functions for open-/read-/closedir
5
6
7         .include        "dir.inc"
8         .include        "errno.inc"
9         .include        "zeropage.inc"
10
11         .import         pushax
12         .import         _read
13
14
15 ;---------------------------------------------------------------------------
16 ;
17 ; unsigned char __fastcall__ _dirread1 (DIR* dir, void* buf);
18 ; /* Read one byte from the directory into the supplied buffer. Makes sure,
19 ; ** errno is set in case of a short read. Return true if the read was
20 ; ** successful and false otherwise.
21 ; */
22
23 __dirread1:
24
25         jsr     pushax          ; Push buf
26         lda     #1              ; Load count = 1
27
28 ; Run directly into __dirread
29
30 ;---------------------------------------------------------------------------
31 ;
32 ; unsigned char __fastcall__ _dirread (DIR* dir, void* buf, unsigned char count);
33 ; /* Read characters from the directory into the supplied buffer. Makes sure,
34 ; ** errno is set in case of a short read. Return true if the read was
35 ; ** successful and false otherwise.
36 ; */
37
38 __dirread:
39
40 ; Save count
41
42         pha
43
44 ; Replace dir by dir->fd
45
46         ldy     #2
47         lda     (sp),y
48         sta     ptr1
49         iny
50         lda     (sp),y
51         sta     ptr1+1
52         ldy     #DIR::fd+1
53         lda     (ptr1),y
54         pha
55         dey
56         lda     (ptr1),y
57         ldy     #2
58         sta     (sp),y
59         pla
60         iny
61         sta     (sp),y
62
63 ; Get count, save it again, clear the high byte and call read(). By the
64 ; previous actions, the stack frame is as read() needs it, and read() will
65 ; also drop it.
66
67         pla
68         pha
69         ldx     #0
70         jsr     _read
71
72 ; Check for errors.
73
74         cpx     #$FF
75         bne     L3
76
77 ; read() returned an error, so errno is already set
78
79         pla                     ; Drop count
80         inx                     ; X = 0
81 L1:     txa                     ; Return zero
82 L2:     rts
83
84 ; read() was successful, check number of bytes read. We assume that read will
85 ; not return more than count, so X is zero if we come here.
86
87 L3:     sta     tmp1            ; Save returned count
88         pla                     ; Our count
89         cmp     tmp1
90         beq     L2              ; Ok, return count
91
92 ; Didn't read enough bytes. This is an error for us, but errno is not set
93
94         lda     #<EIO
95         sta     __errno
96         stx     __errno+1       ; X is zero
97         bne     L1              ; Branch always
98
99