From 966f6df0c505e37695487416100e47df597107ba Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Thu, 26 Mar 2020 12:12:11 -0400 Subject: [PATCH] forth: Forth-ify "KEY" --- emul/forth/emul.fs | 7 +++++++ emul/forth/stagec.asm | 8 -------- emul/forth/z80c.bin | Bin 301 -> 318 bytes forth/forth.asm | 19 +++++-------------- 4 files changed, 12 insertions(+), 22 deletions(-) diff --git a/emul/forth/emul.fs b/emul/forth/emul.fs index bf4a857..16ec637 100644 --- a/emul/forth/emul.fs +++ b/emul/forth/emul.fs @@ -8,3 +8,10 @@ CODE (emit) A L LDrr, 0 OUTnA, ;CODE + +CODE KEY + 0 INAn, + H 0 LDrn, + L A LDrr, + HL PUSHqq, +;CODE diff --git a/emul/forth/stagec.asm b/emul/forth/stagec.asm index 0488a8b..b146d21 100644 --- a/emul/forth/stagec.asm +++ b/emul/forth/stagec.asm @@ -9,11 +9,3 @@ init: ld sp, 0xffff call forthMain halt - -emulGetC: - ; Blocks until a char is returned - in a, (STDIO_PORT) - cp a ; ensure Z - ret - -.equ GETC emulGetC diff --git a/emul/forth/z80c.bin b/emul/forth/z80c.bin index 48ac1db1d71efd0d06f93a228319f6ca12338c56..326ad7c0c13c37fa20a7f3eae77d26b2288d9373 100644 GIT binary patch delta 29 kcmZ3>w2x_nCZnjgYa~AdvpBEcF9Rb07&`*H diff --git a/forth/forth.asm b/forth/forth.asm index 813e260..f38889d 100644 --- a/forth/forth.asm +++ b/forth/forth.asm @@ -141,7 +141,8 @@ forthMain: call find jr z, .skip ; no? then use KEY - ld de, KEY + ld hl, .keyName + call find .skip: ld (CINPTR), de ; Set up SYSVNXT @@ -157,6 +158,8 @@ forthMain: .db "(c<)", 0 .emitName: .db "(emit)", 0 +.keyName: + .db "KEY", 0 BEGIN: .dw compiledWord @@ -985,22 +988,10 @@ FIND_: push de jp next -; ( -- c ) - .db "KEY" - .dw $-FIND_ - .db 3 -KEY: - .dw nativeWord - call GETC - ld h, 0 - ld l, a - push hl - jp next - ; This is an indirect word that can be redirected through "CINPTR" ; code: it is replaced in readln.fs. .db "C<" - .dw $-KEY + .dw $-FIND_ .db 2 CIN: .dw compiledWord