1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-17 07:08:05 +11:00

fs: standardize file handle routine argument to IX

Using HL/DE was awkward and error-prone.
This commit is contained in:
Virgil Dupras 2019-05-31 14:06:24 -04:00
parent 83771b538f
commit 7c191fd978
3 changed files with 57 additions and 59 deletions

View File

@ -79,10 +79,8 @@ ioGetC:
call ioInInclude call ioInInclude
jr z, .normalmode jr z, .normalmode
; We're in "include mode", read from FS ; We're in "include mode", read from FS
push de ld ix, IO_INCLUDE_HDL
ld de, IO_INCLUDE_HDL
call fsGetC call fsGetC
pop de
cp 0x0a ; newline cp 0x0a ; newline
jr nz, .notNewline jr nz, .notNewline
; We have newline. Increase lineno and return (the rest of the ; We have newline. Increase lineno and return (the rest of the
@ -190,11 +188,8 @@ _ioSeek:
jp (ix) jp (ix)
.include: .include:
; We're in "include mode", seek in FS ; We're in "include mode", seek in FS
push de ld ix, IO_INCLUDE_HDL
ld de, IO_INCLUDE_HDL jp fsSeek ; returns
call fsSeek
pop de
ret
_ioTell: _ioTell:
call ioInInclude call ioInInclude
@ -204,11 +199,8 @@ _ioTell:
jp (ix) jp (ix)
.include: .include:
; We're in "include mode", tell from FS ; We're in "include mode", tell from FS
push de ld ix, IO_INCLUDE_HDL
ld de, IO_INCLUDE_HDL jp fsTell ; returns
call fsTell
pop de
ret
; Sets Z according to whether we're inside an include ; Sets Z according to whether we're inside an include
ioInInclude: ioInInclude:
@ -221,7 +213,7 @@ ioInInclude:
ioOpenInclude: ioOpenInclude:
call fsFindFN call fsFindFN
ret nz ret nz
ld hl, IO_INCLUDE_HDL ld ix, IO_INCLUDE_HDL
call fsOpen call fsOpen
ld a, 1 ld a, 1
ld (IO_IN_INCLUDE), a ld (IO_IN_INCLUDE), a

View File

@ -347,66 +347,84 @@ fsIsDeleted:
; below mimic blkdev's methods, but for our private mount. ; below mimic blkdev's methods, but for our private mount.
fsblkGetC: fsblkGetC:
push ix
ld ix, (FS_GETC) ld ix, (FS_GETC)
jp _blkCall call _blkCall
pop ix
ret
fsblkRead: fsblkRead:
push ix
ld ix, (FS_GETC) ld ix, (FS_GETC)
jp _blkRead call _blkRead
pop ix
ret
fsblkPutC: fsblkPutC:
push ix
ld ix, (FS_PUTC) ld ix, (FS_PUTC)
jp _blkCall call _blkCall
pop ix
ret
fsblkWrite: fsblkWrite:
push ix
ld ix, (FS_PUTC) ld ix, (FS_PUTC)
jp _blkWrite call _blkWrite
pop ix
ret
fsblkSeek: fsblkSeek:
push ix
push iy
ld ix, (FS_SEEK) ld ix, (FS_SEEK)
ld iy, (FS_TELL) ld iy, (FS_TELL)
jp _blkSeek call _blkSeek
pop iy
pop ix
ret
fsblkTell: fsblkTell:
push ix
ld de, 0 ld de, 0
ld ix, (FS_TELL) ld ix, (FS_TELL)
jp _blkCall call _blkCall
pop ix
ret
; *** Handling *** ; *** Handling ***
; Open file at current position into handle at (HL) ; Open file at current position into handle at (IX)
fsOpen: fsOpen:
push bc
push hl push hl
push de
push af push af
ex de, hl
; Starting pos ; Starting pos
ld hl, FS_PTR ld a, (FS_PTR)
ld bc, 4 ld (ix), a
ldir ld a, (FS_PTR+1)
ld (ix+1), a
ld a, (FS_PTR+2)
ld (ix+2), a
ld a, (FS_PTR+3)
ld (ix+3), a
; Current pos ; Current pos
ld hl, FS_METASIZE ld hl, FS_METASIZE
call writeHLinDE ld (ix+4), l
inc de ld (ix+5), h
inc de
; file size ; file size
ld hl, (FS_META+FS_META_FSIZE_OFFSET) ld hl, (FS_META+FS_META_FSIZE_OFFSET)
call writeHLinDE ld (ix+6), l
ld (ix+7), h
pop af pop af
pop de
pop hl pop hl
pop bc
ret ret
; Place FS blockdev at proper position for file handle in (DE). ; Place FS blockdev at proper position for file handle in (IX).
fsPlaceH: fsPlaceH:
push af push af
push bc push bc
push hl push hl
push de push de
pop ix
push ix
ld e, (ix) ld e, (ix)
ld d, (ix+1) ld d, (ix+1)
ld l, (ix+2) ld l, (ix+2)
@ -419,7 +437,7 @@ fsPlaceH:
.nocarry: .nocarry:
ld a, BLOCKDEV_SEEK_ABSOLUTE ld a, BLOCKDEV_SEEK_ABSOLUTE
call fsblkSeek call fsblkSeek
pop ix pop de
pop hl pop hl
pop bc pop bc
pop af pop af
@ -435,14 +453,13 @@ fsAdvanceH:
pop af pop af
ret ret
; Sets Z according to whether file handle at (DE) is within bounds, that is, if ; Sets Z according to whether file handle at (IX) is within bounds, that is, if
; current position is smaller than file size. ; current position is smaller than file size.
fsHandleWithinBounds: fsHandleWithinBounds:
push hl push hl
push de
; current pos in HL, adjusted to remove FS_METASIZE ; current pos in HL, adjusted to remove FS_METASIZE
call fsTell call fsTell
push de
push de \ pop ix
; file size ; file size
ld e, (ix+6) ld e, (ix+6)
ld d, (ix+7) ld d, (ix+7)
@ -455,7 +472,7 @@ fsHandleWithinBounds:
.outOfBounds: .outOfBounds:
jp unsetZ ; returns jp unsetZ ; returns
; Read a byte in handle at (DE), put it into A and advance the handle's ; Read a byte in handle at (IX), put it into A and advance the handle's
; position. ; position.
; Z is set on success, unset if handle is at the end of the file. ; Z is set on success, unset if handle is at the end of the file.
fsGetC: fsGetC:
@ -466,43 +483,32 @@ fsGetC:
xor a xor a
jp unsetZ ; returns jp unsetZ ; returns
.proceed: .proceed:
push ix
call fsPlaceH call fsPlaceH
push ix ; Save handle in IX for fsAdvanceH
call fsblkGetC call fsblkGetC
ret nz ; error, don't advance
; increase current pos ; increase current pos
pop ix ; recall handle in IX jp fsAdvanceH ; returns
jr nz, .end ; error, don't advance
call fsAdvanceH
.end:
pop ix
ret
; Write byte A in handle (DE) and advance the handle's position. ; Write byte A in handle (IX) and advance the handle's position.
; Z is set on success, unset if handle is at the end of the file. ; Z is set on success, unset if handle is at the end of the file.
; TODO: detect end of block alloc ; TODO: detect end of block alloc
fsPutC: fsPutC:
call fsPlaceH call fsPlaceH
push ix
call fsblkPutC call fsblkPutC
; increase current pos jp fsAdvanceH ; returns
pop ix ; recall
call fsAdvanceH
ret
; Sets position of handle (DE) to HL. This position does *not* include metadata. ; Sets position of handle (IX) to HL. This position does *not* include metadata.
; It is an offset that starts at actual data. ; It is an offset that starts at actual data.
; Sets Z if offset is within bounds, unsets Z if it isn't. ; Sets Z if offset is within bounds, unsets Z if it isn't.
fsSeek: fsSeek:
push de \ pop ix
ld a, FS_METASIZE ld a, FS_METASIZE
call addHL call addHL
ld (ix+4), l ld (ix+4), l
ld (ix+5), h ld (ix+5), h
ret ret
; Returns current position of file handle at (IX) in HL.
fsTell: fsTell:
push de \ pop ix
ld l, (ix+4) ld l, (ix+4)
ld h, (ix+5) ld h, (ix+5)
ld a, FS_METASIZE ld a, FS_METASIZE

View File

@ -76,7 +76,7 @@ fopnCmd:
jr nz, .notfound jr nz, .notfound
; Found! ; Found!
; FS_PTR points to the file we want to open ; FS_PTR points to the file we want to open
ex de, hl ; HL now points to the file handle. push de \ pop ix ; IX now points to the file handle.
call fsOpen call fsOpen
jr .end jr .end
.notfound: .notfound: