From 4ba84dac5cffbbd98540f33980086dde102739ff Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sat, 30 Nov 2019 21:13:44 -0500 Subject: [PATCH] basic: add getc/putc commands --- apps/basic/README.md | 5 +++++ apps/basic/blk.asm | 2 ++ apps/basic/main.asm | 25 ++++++++++++++++++++----- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/apps/basic/README.md b/apps/basic/README.md index 50144e0..47360db 100644 --- a/apps/basic/README.md +++ b/apps/basic/README.md @@ -149,6 +149,11 @@ input I/O on port 42 and stores the byte result in `A`. **out **: Same thing as `poke`, but for a I/O port. `out 42 1+2` generates an output I/O on port 42 with value 3. +**getc**: Waits for a single character to be typed in the console and then puts +that value in `A`. + +**putc **: Puts the specified character to the console. + **sleep **: Sleep a number of "units" specified by the supplied expression. A "unit" depends on the CPU clock speed. At 4MHz, it is roughly 8 microseconds. diff --git a/apps/basic/blk.asm b/apps/basic/blk.asm index ac3a28b..3df4383 100644 --- a/apps/basic/blk.asm +++ b/apps/basic/blk.asm @@ -26,6 +26,8 @@ basGETB: call blkGetB ret nz ld (VAR_TBL), a + xor a + ld (VAR_TBL+1), a ret basPUTB: diff --git a/apps/basic/main.asm b/apps/basic/main.asm index 1b532ff..15c4958 100644 --- a/apps/basic/main.asm +++ b/apps/basic/main.asm @@ -126,16 +126,11 @@ basERR: ; ; Commands are expected to set Z on success. basBYE: - ld hl, .sBye - call printstr - call printcrlf ; To quit the loop, let's return the stack to its initial value and ; then return. xor a ld sp, (BAS_INITSP) ret -.sBye: - .db "Goodbye!", 0 basLIST: call bufFirst @@ -349,6 +344,22 @@ basIN: ; Z set from rdExpr ret +basGETC: + call stdioGetC + ld (VAR_TBL), a + xor a + ld (VAR_TBL+1), a + ret + +basPUTC: + call rdExpr + ret nz + push ix \ pop hl + ld a, l + call stdioPutC + xor a ; set Z + ret + basSLEEP: call rdExpr ret nz @@ -457,6 +468,10 @@ basCmds2: .db "out", 0, 0, 0 .dw basIN .db "in", 0, 0, 0, 0 + .dw basGETC + .db "getc", 0, 0 + .dw basPUTC + .db "putc", 0, 0 .dw basSLEEP .db "sleep", 0 .dw basADDR