diff --git a/apps/zasm/zasm.asm b/apps/zasm/zasm.asm index 874d602..1db1fc0 100644 --- a/apps/zasm/zasm.asm +++ b/apps/zasm/zasm.asm @@ -20,6 +20,7 @@ ret #include "tok.asm" +; TODO: call from core unsetZ: push bc ld b, a diff --git a/parts/acia.asm b/parts/acia.asm index bcf67a2..86e9b1f 100644 --- a/parts/acia.asm +++ b/parts/acia.asm @@ -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 diff --git a/parts/blockdev.asm b/parts/blockdev.asm index fd90bc6..ab1b7d1 100644 --- a/parts/blockdev.asm +++ b/parts/blockdev.asm @@ -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 diff --git a/parts/core.asm b/parts/core.asm index 3914a0d..f32de9a 100644 --- a/parts/core.asm +++ b/parts/core.asm @@ -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. diff --git a/parts/mmap.asm b/parts/mmap.asm index e8ec582..f5cdb49 100644 --- a/parts/mmap.asm +++ b/parts/mmap.asm @@ -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 diff --git a/parts/shell.asm b/parts/shell.asm index 6b5217b..af3f8e0 100644 --- a/parts/shell.asm +++ b/parts/shell.asm @@ -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!