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

blkdev: make load command stop and the end of the stream

This allows us to reliably and easily load a file until the end of it.
This commit is contained in:
Virgil Dupras 2019-06-02 11:18:06 -04:00
parent 73c3fc7947
commit 95f1a8ddaf
2 changed files with 10 additions and 14 deletions

View File

@ -146,16 +146,6 @@ blkGetC:
ld ix, (BLOCKDEV_GETC) ld ix, (BLOCKDEV_GETC)
jr _blkCall jr _blkCall
; Repeatedly call blkGetC until the call is a success.
blkGetCW:
ld ix, (BLOCKDEV_GETC)
.loop:
push ix ; fs messes with IX a lot
call callIX
pop ix
jr nz, .loop
ret
; Reads B chars from blkGetC and copy them in (HL). ; Reads B chars from blkGetC and copy them in (HL).
; Sets Z if successful, unset Z if there was an error. ; Sets Z if successful, unset Z if there was an error.
blkRead: blkRead:

View File

@ -45,9 +45,11 @@ blkSeekCmd:
ret ret
; Load the specified number of bytes (max 0xff) from IO and write them in the ; Load the specified number of bytes (max 0xff) from IO and write them in the
; current memory pointer (which doesn't change). This gets chars from ; current memory pointer (which doesn't change). If the blkdev hits end of
; blkGetCW. ; stream before we reach our specified number of bytes, we stop loading.
; Control is returned to the shell only after all bytes are read. ;
; Returns a SHELL_ERR_IO_ERROR only if we couldn't read any byte (if the first
; call to GetC failed)
; ;
; Example: load 42 ; Example: load 42
blkLoadCmd: blkLoadCmd:
@ -59,11 +61,15 @@ blkLoad:
ld a, (hl) ld a, (hl)
ld b, a ld b, a
ld hl, (SHELL_MEM_PTR) ld hl, (SHELL_MEM_PTR)
.loop: call blkGetCW call blkGetC
jr nz, .ioError jr nz, .ioError
.loop:
ld (hl), a ld (hl), a
inc hl inc hl
call blkGetC
jr nz, .loopend
djnz .loop djnz .loop
.loopend:
; success ; success
xor a xor a
jr .end jr .end