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

blockdev: change GetC API

Instead of waiting, GetC always return immediately, with Z indicating if
something was fetched. The "wait" loop is implemented by the called (and
in the new `blkGetCW`).

This simplifies out-of-bounds verifications for storage blockdevs.
This commit is contained in:
Virgil Dupras 2019-04-22 14:26:16 -04:00
parent 63afa5798b
commit b4694225c5
6 changed files with 37 additions and 8 deletions

View File

@ -20,6 +20,7 @@ ret
#include "tok.asm"
; TODO: call from core
unsetZ:
push bc
ld b, a

View File

@ -95,17 +95,18 @@ aciaInt:
ei
reti
; Read a character from the input buffer. If the buffer is empty, loop until
; there something to fetch. Returns value in A.
; *** BLOCKDEV ***
; These function below follow the blockdev API.
aciaGetC:
push de
.loop:
ld a, (ACIA_BUFWRIDX)
ld e, a
ld a, (ACIA_BUFRDIDX)
cp e
jr z, .loop ; equal? buffer empty, wait.
jr z, .nothingToRead ; equal? nothing to read.
; Alrighty, buffer not empty. let's read.
ld de, ACIA_BUF
@ -117,7 +118,12 @@ aciaGetC:
; And finally, fetch the value.
ld a, (de)
cp a ; ensure Z
jr .end
.nothingToRead:
call unsetZ
.end:
pop de
ret

View File

@ -97,13 +97,21 @@ _blkCall:
pop ix
ret
; Reads one character from selected device and returns its value in A. Always
; returns a character and waits until read if it has to.
; Reads one character from selected device and returns its value in A.
; Sets Z according to whether read was successful: Set if successful, unset
; if not.
blkGetC:
ld iyl, 0
jr _blkCall
; Writes character in A in current position in the selected device
; Repeatedly call blkGetC until the call is a success.
blkGetCW:
call blkGetC
jr nz, blkGetCW
ret
; Writes character in A in current position in the selected device. Sets Z
; according to whether the operation was successful.
blkPutC:
ld iyl, 2
jr _blkCall

View File

@ -7,7 +7,7 @@
ASCII_CR .equ 0x0d
ASCII_LF .equ 0x0a
; *** CODE ***
; *** REGISTER FIDDLING ***
; add the value of A into DE
addDE:
@ -59,6 +59,17 @@ callIX:
jp (ix)
ret
; Ensures that Z is unset (more complicated than it sounds...)
unsetZ:
push bc
ld b, a
inc b
cp b
pop bc
ret
; *** STRINGS ***
; Increase HL until the memory address it points to is null for a maximum of
; 0xff bytes. Returns the new HL value as well as the number of bytes iterated
; in A.

View File

@ -32,11 +32,13 @@ _mmapAddr:
ret
; if out of bounds, will continually return the last char
; TODO: add bounds check and return Z accordingly.
mmapGetC:
push hl
call _mmapAddr
ld a, (hl)
call _mmapForward
cp a ; ensure Z
pop hl
ret

View File

@ -77,6 +77,7 @@ shellInit:
shellLoop:
; First, let's wait until something is typed.
SHELL_GETC
jr nz, shellLoop ; nothing typed? loop
; got it. Now, is it a CR or LF?
cp ASCII_CR
jr z, .do ; char is CR? do!