1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-27 14:48: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" #include "tok.asm"
; TODO: call from core
unsetZ: unsetZ:
push bc push bc
ld b, a ld b, a

View File

@ -95,17 +95,18 @@ aciaInt:
ei ei
reti 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: aciaGetC:
push de push de
.loop:
ld a, (ACIA_BUFWRIDX) ld a, (ACIA_BUFWRIDX)
ld e, a ld e, a
ld a, (ACIA_BUFRDIDX) ld a, (ACIA_BUFRDIDX)
cp e cp e
jr z, .loop ; equal? buffer empty, wait. jr z, .nothingToRead ; equal? nothing to read.
; Alrighty, buffer not empty. let's read. ; Alrighty, buffer not empty. let's read.
ld de, ACIA_BUF ld de, ACIA_BUF
@ -117,7 +118,12 @@ aciaGetC:
; And finally, fetch the value. ; And finally, fetch the value.
ld a, (de) ld a, (de)
cp a ; ensure Z
jr .end
.nothingToRead:
call unsetZ
.end:
pop de pop de
ret ret

View File

@ -97,13 +97,21 @@ _blkCall:
pop ix pop ix
ret ret
; Reads one character from selected device and returns its value in A. Always ; Reads one character from selected device and returns its value in A.
; returns a character and waits until read if it has to. ; Sets Z according to whether read was successful: Set if successful, unset
; if not.
blkGetC: blkGetC:
ld iyl, 0 ld iyl, 0
jr _blkCall 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: blkPutC:
ld iyl, 2 ld iyl, 2
jr _blkCall jr _blkCall

View File

@ -7,7 +7,7 @@
ASCII_CR .equ 0x0d ASCII_CR .equ 0x0d
ASCII_LF .equ 0x0a ASCII_LF .equ 0x0a
; *** CODE *** ; *** REGISTER FIDDLING ***
; add the value of A into DE ; add the value of A into DE
addDE: addDE:
@ -59,6 +59,17 @@ callIX:
jp (ix) jp (ix)
ret 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 ; 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 ; 0xff bytes. Returns the new HL value as well as the number of bytes iterated
; in A. ; in A.

View File

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

View File

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