2012-06-01 19:23:34 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 2012-06-01
|
|
|
|
;
|
2012-06-03 13:59:31 +00:00
|
|
|
; Helper functions for open-/read-/closedir
|
|
|
|
|
2012-06-01 19:23:34 +00:00
|
|
|
|
|
|
|
.include "dir.inc"
|
|
|
|
.include "errno.inc"
|
|
|
|
.include "zeropage.inc"
|
2012-06-03 13:59:31 +00:00
|
|
|
|
|
|
|
.import pushax
|
2012-06-01 19:23:34 +00:00
|
|
|
.import _read
|
|
|
|
|
|
|
|
|
2012-06-03 13:59:31 +00:00
|
|
|
;---------------------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; unsigned char __fastcall__ _dirread1 (DIR* dir, void* buf);
|
|
|
|
; /* Read one byte from the directory into the supplied buffer. Makes sure,
|
|
|
|
; * errno is set in case of a short read. Return true if the read was
|
|
|
|
; * successful and false otherwise.
|
|
|
|
; */
|
2012-06-01 19:23:34 +00:00
|
|
|
|
2012-06-03 13:59:31 +00:00
|
|
|
__dirread1:
|
2012-06-01 19:23:34 +00:00
|
|
|
|
2012-06-03 13:59:31 +00:00
|
|
|
jsr pushax ; Push buf
|
|
|
|
lda #1 ; Load count = 1
|
2012-06-01 19:23:34 +00:00
|
|
|
|
2012-06-03 13:59:31 +00:00
|
|
|
; Run directly into __dirread
|
2012-06-01 19:23:34 +00:00
|
|
|
|
2012-06-03 13:59:31 +00:00
|
|
|
;---------------------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; unsigned char __fastcall__ _dirread (DIR* dir, void* buf, unsigned char count);
|
|
|
|
; /* Read characters from the directory into the supplied buffer. Makes sure,
|
|
|
|
; * errno is set in case of a short read. Return true if the read was
|
|
|
|
; * successful and false otherwise.
|
|
|
|
; */
|
2012-06-01 19:23:34 +00:00
|
|
|
|
2012-06-03 13:59:31 +00:00
|
|
|
__dirread:
|
2012-06-01 19:23:34 +00:00
|
|
|
|
2012-06-03 13:59:31 +00:00
|
|
|
; Save count
|
2012-06-01 19:23:34 +00:00
|
|
|
|
2012-06-03 13:59:31 +00:00
|
|
|
pha
|
2012-06-01 19:23:34 +00:00
|
|
|
|
2012-06-03 13:59:31 +00:00
|
|
|
; Replace dir by dir->fd
|
2012-06-01 19:23:34 +00:00
|
|
|
|
2012-06-03 13:59:31 +00:00
|
|
|
ldy #2
|
|
|
|
lda (sp),y
|
|
|
|
sta ptr1
|
|
|
|
iny
|
|
|
|
lda (sp),y
|
|
|
|
sta ptr1+1
|
|
|
|
ldy #DIR::fd+1
|
|
|
|
lda (ptr1),y
|
|
|
|
pha
|
|
|
|
dey
|
|
|
|
lda (ptr1),y
|
|
|
|
ldy #2
|
|
|
|
sta (sp),y
|
2012-06-01 19:23:34 +00:00
|
|
|
pla
|
2012-06-03 13:59:31 +00:00
|
|
|
iny
|
|
|
|
sta (sp),y
|
2012-06-01 19:23:34 +00:00
|
|
|
|
2012-06-03 13:59:31 +00:00
|
|
|
; Get count, save it again, clear the high byte and call read(). By the
|
|
|
|
; previous actions, the stack frame is as read() needs it, and read() will
|
|
|
|
; also drop it.
|
2012-06-01 19:23:34 +00:00
|
|
|
|
|
|
|
pla
|
|
|
|
pha
|
|
|
|
ldx #0
|
|
|
|
jsr _read
|
|
|
|
|
2012-06-03 13:59:31 +00:00
|
|
|
; Check for errors.
|
2012-06-01 19:23:34 +00:00
|
|
|
|
|
|
|
cpx #$FF
|
2012-06-03 13:59:31 +00:00
|
|
|
bne L3
|
2012-06-01 19:23:34 +00:00
|
|
|
|
2012-06-03 13:59:31 +00:00
|
|
|
; read() returned an error, so errno is already set
|
2012-06-01 19:23:34 +00:00
|
|
|
|
2012-06-03 13:59:31 +00:00
|
|
|
pla ; Drop count
|
|
|
|
inx ; X = 0
|
|
|
|
L1: txa ; Return zero
|
|
|
|
L2: rts
|
2012-06-01 19:23:34 +00:00
|
|
|
|
|
|
|
; read() was successful, check number of bytes read. We assume that read will
|
|
|
|
; not return more than count, so X is zero if we come here.
|
|
|
|
|
2012-06-03 13:59:31 +00:00
|
|
|
L3: sta tmp1 ; Save returned count
|
|
|
|
pla ; Our count
|
2012-06-01 19:23:34 +00:00
|
|
|
cmp tmp1
|
2012-06-03 13:59:31 +00:00
|
|
|
beq L2 ; Ok, return count
|
2012-06-01 19:23:34 +00:00
|
|
|
|
|
|
|
; Didn't read enough bytes. This is an error for us, but errno is not set
|
|
|
|
|
|
|
|
lda #<EIO
|
|
|
|
sta __errno
|
2012-06-03 13:59:31 +00:00
|
|
|
stx __errno+1 ; X is zero
|
|
|
|
bne L1 ; Branch always
|
2012-06-01 19:23:34 +00:00
|
|
|
|
|
|
|
|