From 8cf9904f33bb2a639256945f9ab1dfc3d867d3e2 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 17 Jun 2019 08:19:03 -0400 Subject: [PATCH] blockdev: fix load command over-loading a byte Calling `load` would always read one more byte than specified. Also, make `0` mean `0x100`. --- kernel/blockdev_cmds.asm | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/kernel/blockdev_cmds.asm b/kernel/blockdev_cmds.asm index c8cdc97..70a5485 100644 --- a/kernel/blockdev_cmds.asm +++ b/kernel/blockdev_cmds.asm @@ -44,9 +44,10 @@ blkSeekCmd: xor a ret -; Load the specified number of bytes (max 0xff) from IO and write them in the -; current memory pointer (which doesn't change). If the blkdev hits end of -; stream before we reach our specified number of bytes, we stop loading. +; Load the specified number of bytes (max 0x100, 0 means 0x100) from IO and +; write them in the current memory pointer (which doesn't change). If the +; blkdev hits end of stream before we reach our specified number of bytes, we +; stop loading. ; ; Returns a SHELL_ERR_IO_ERROR only if we couldn't read any byte (if the first ; call to GetC failed) @@ -63,11 +64,13 @@ blkLoad: ld hl, (SHELL_MEM_PTR) call blkGetC jr nz, .ioError + jr .intoLoop ; properly dec B + check on first iteration. .loop: ld (hl), a inc hl call blkGetC jr nz, .loopend +.intoLoop: djnz .loop .loopend: ; success @@ -80,9 +83,9 @@ blkLoad: pop bc ret -; Load the specified number of bytes (max 0xff) from the current memory pointer -; and write them to I/O. Memory pointer doesn't move. This puts chars to -; blkPutC. Raises error if not all bytes could be written. +; Load the specified number of bytes (max 0x100, 0 means 0x100) from the current +; memory pointer and write them to I/O. Memory pointer doesn't move. This puts +; chars to blkPutC. Raises error if not all bytes could be written. ; ; Example: save 42 blkSaveCmd: