From 25b6e75cf7a4a7febd9355502a621143a1d1289a Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 17 Mar 2020 15:22:13 -0400 Subject: [PATCH] forth: add words "."" and "(print)" --- apps/forth/dict.asm | 47 ++++++++++++++++++++++++++++++++++++++- apps/forth/dictionary.txt | 3 +++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/apps/forth/dict.asm b/apps/forth/dict.asm index 3b8d958..3da919f 100644 --- a/apps/forth/dict.asm +++ b/apps/forth/dict.asm @@ -192,10 +192,55 @@ EMIT: call stdioPutC jp next + .db "(print)" + .dw EMIT + .db 0 +PRINT: + .dw nativeWord + pop hl + call chkPS + call printstr + jp next + + + .db '.', '"' + .fill 5 + .dw PRINT + .db 1 ; IMMEDIATE +PRINTI: + .dw nativeWord + ld hl, (HERE) + ld de, LIT + call DEinHL + ex de, hl ; (HERE) now in DE + ld hl, (INPUTPOS) +.loop: + ld a, (hl) + or a ; null? not cool + jp z, abort + cp '"' + jr z, .loopend + ld (de), a + inc hl + inc de + jr .loop +.loopend: + inc hl ; inputpos to char afterwards + ld (INPUTPOS), hl + ; null-terminate LIT + inc de + xor a + ld (de), a + ex de, hl ; (HERE) in HL + ld de, PRINT + call DEinHL + ld (HERE), hl + jp next + ; ( c port -- ) .db "PC!" .fill 4 - .dw EMIT + .dw PRINTI .db 0 PSTORE: .dw nativeWord diff --git a/apps/forth/dictionary.txt b/apps/forth/dictionary.txt index fc86b72..a2fc6e2 100644 --- a/apps/forth/dictionary.txt +++ b/apps/forth/dictionary.txt @@ -146,8 +146,11 @@ wait until another line is entered. KEY input, however, is direct. Regardless of the input buffer's state, KEY will return the next typed key. +(print) a -- Print string at addr a. . n -- Print n in its decimal form .X n -- Print n in its hexadecimal form. In hex, numbers +." xxx" -- *I* Compiles string literal xxx followed by a call + to (print) are never considered negative. "-1 .X -> ffff" EMIT c -- Spit char c to output stream IN> -- a Address of variable containing current pos in input