mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-23 19:48:06 +11:00
blockdev: add Tell and fix blkGetCW
Calling on blkGetC repeatedly was somehow very unstable and often failed. I didn't pinpoint exactly why, but keeping the call addr around and calling that instead seems like a better idea anyway.
This commit is contained in:
parent
196d22c4ab
commit
1bcceb949c
@ -17,9 +17,9 @@ BLOCKDEV_ERR_OUT_OF_BOUNDS .equ 0x03
|
|||||||
BLOCKDEV_ERR_UNSUPPORTED .equ 0x04
|
BLOCKDEV_ERR_UNSUPPORTED .equ 0x04
|
||||||
|
|
||||||
; *** VARIABLES ***
|
; *** VARIABLES ***
|
||||||
; Pointer to the selected block device. A block device is a 6 bytes block of
|
; Pointer to the selected block device. A block device is a 8 bytes block of
|
||||||
; memory with pointers to GetC, PutC and Seek routines, in that order. 0 means
|
; memory with pointers to GetC, PutC, Seek and Tell routines, in that order.
|
||||||
; unsupported.
|
; 0 means unsupported.
|
||||||
BLOCKDEV_SEL .equ BLOCKDEV_RAMSTART
|
BLOCKDEV_SEL .equ BLOCKDEV_RAMSTART
|
||||||
BLOCKDEV_RAMEND .equ BLOCKDEV_SEL+2
|
BLOCKDEV_RAMEND .equ BLOCKDEV_SEL+2
|
||||||
|
|
||||||
@ -34,13 +34,13 @@ blkSel:
|
|||||||
push bc
|
push bc
|
||||||
ld b, a
|
ld b, a
|
||||||
.loop:
|
.loop:
|
||||||
ld a, 6
|
ld a, 8
|
||||||
call addHL
|
call addHL
|
||||||
djnz .loop
|
djnz .loop
|
||||||
pop bc
|
pop bc
|
||||||
.afterloop:
|
.afterloop:
|
||||||
ld (BLOCKDEV_SEL), hl
|
ld (BLOCKDEV_SEL), hl
|
||||||
pop Hl
|
pop hl
|
||||||
pop af
|
pop af
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@ -60,9 +60,8 @@ blkBselCmd:
|
|||||||
; In those routines below, IY is destroyed (we don't push it to the stack). We
|
; In those routines below, IY is destroyed (we don't push it to the stack). We
|
||||||
; seldom use it anyways...
|
; seldom use it anyways...
|
||||||
|
|
||||||
; call routine in BLOCKDEV_SEL with offset IYL.
|
; set IX to the address of the routine in BLOCKDEV_SEL with offset IYL.
|
||||||
_blkCall:
|
_blkCallAddr:
|
||||||
push ix
|
|
||||||
push de
|
push de
|
||||||
ld de, (BLOCKDEV_SEL)
|
ld de, (BLOCKDEV_SEL)
|
||||||
; DE now points to the *address table*, not the routine addresses
|
; DE now points to the *address table*, not the routine addresses
|
||||||
@ -77,19 +76,23 @@ _blkCall:
|
|||||||
ld ixh, d
|
ld ixh, d
|
||||||
ld ixl, e
|
ld ixl, e
|
||||||
pop de
|
pop de
|
||||||
; Before we call... is it zero? We don't want to call a zero.
|
ret
|
||||||
|
|
||||||
|
; call routine in BLOCKDEV_SEL with offset IYL.
|
||||||
|
_blkCall:
|
||||||
|
push ix
|
||||||
|
call _blkCallAddr
|
||||||
|
; Before we call... is IX zero? We don't want to call a zero.
|
||||||
push af
|
push af
|
||||||
ld a, ixh
|
xor a
|
||||||
add a, ixl
|
cp ixh
|
||||||
jr c, .ok ; if there's a carry, it isn't zero
|
jr nz, .ok ; not zero, ok
|
||||||
cp 0
|
cp ixl
|
||||||
jr z, .error ; if no carry and zero, then both numbers are
|
jr z, .error ; zero, error
|
||||||
; zero
|
|
||||||
.ok:
|
.ok:
|
||||||
pop af
|
pop af
|
||||||
call callIX
|
call callIX
|
||||||
jr .end
|
jr .end
|
||||||
|
|
||||||
.error:
|
.error:
|
||||||
pop af
|
pop af
|
||||||
ld a, BLOCKDEV_ERR_UNSUPPORTED
|
ld a, BLOCKDEV_ERR_UNSUPPORTED
|
||||||
@ -106,8 +109,23 @@ blkGetC:
|
|||||||
|
|
||||||
; Repeatedly call blkGetC until the call is a success.
|
; Repeatedly call blkGetC until the call is a success.
|
||||||
blkGetCW:
|
blkGetCW:
|
||||||
|
ld iyl, 0
|
||||||
|
call _blkCallAddr
|
||||||
|
.loop:
|
||||||
|
call callIX
|
||||||
|
jr nz, .loop
|
||||||
|
ret
|
||||||
|
|
||||||
|
; Reads B chars from blkGetC and copy them in (HL).
|
||||||
|
; Sets Z if successful, unset Z if there was an error.
|
||||||
|
blkRead:
|
||||||
|
.loop:
|
||||||
call blkGetC
|
call blkGetC
|
||||||
jr nz, blkGetCW
|
ret nz
|
||||||
|
ld (hl), a
|
||||||
|
inc hl
|
||||||
|
djnz .loop
|
||||||
|
cp a ; ensure Z
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Writes character in A in current position in the selected device. Sets Z
|
; Writes character in A in current position in the selected device. Sets Z
|
||||||
@ -133,8 +151,13 @@ blkSeek:
|
|||||||
ld iyl, 4
|
ld iyl, 4
|
||||||
jr _blkCall
|
jr _blkCall
|
||||||
|
|
||||||
|
; Returns the current position of the selected device in HL.
|
||||||
|
blkTell:
|
||||||
|
ld iyl, 6
|
||||||
|
jr _blkCall
|
||||||
|
|
||||||
; This label is at the end of the file on purpose: the glue file should include
|
; This label is at the end of the file on purpose: the glue file should include
|
||||||
; a list of device routine table entries just after the include. Each line
|
; a list of device routine table entries just after the include. Each line
|
||||||
; has 3 word addresses: GetC, PutC and Seek. An entry could look like:
|
; has 4 word addresses: GetC, PutC and Seek, Tell. An entry could look like:
|
||||||
; .dw mmapGetC, mmapPutC, mmapSeek
|
; .dw mmapGetC, mmapPutC, mmapSeek, mmapTell
|
||||||
blkDevTbl:
|
blkDevTbl:
|
||||||
|
@ -11,6 +11,12 @@ MMAP_RAMEND .equ MMAP_PTR+2
|
|||||||
|
|
||||||
; *** CODE ***
|
; *** CODE ***
|
||||||
|
|
||||||
|
mmapInit:
|
||||||
|
xor a
|
||||||
|
ld (MMAP_PTR), a
|
||||||
|
ld (MMAP_PTR+1), a
|
||||||
|
ret
|
||||||
|
|
||||||
; Increase mem pointer by one
|
; Increase mem pointer by one
|
||||||
_mmapForward:
|
_mmapForward:
|
||||||
ld hl, (MMAP_PTR)
|
ld hl, (MMAP_PTR)
|
||||||
@ -54,3 +60,7 @@ mmapSeek:
|
|||||||
ld (MMAP_PTR), hl
|
ld (MMAP_PTR), hl
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
mmapTell:
|
||||||
|
ld hl, (MMAP_PTR)
|
||||||
|
ret
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user