From 6f9d28b325334ea660a46aef3e754a2d14cf69e2 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sat, 7 Mar 2020 13:15:19 -0500 Subject: [PATCH] forth: add word "bye" And make interpret action looping until BYE. --- apps/forth/dict.asm | 12 +++++++++++- apps/forth/main.asm | 19 ++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/apps/forth/dict.asm b/apps/forth/dict.asm index 44afe6e..2b128d6 100644 --- a/apps/forth/dict.asm +++ b/apps/forth/dict.asm @@ -45,10 +45,19 @@ exit: push hl \ pop iy jp compiledWord +BYE: + .db "BYE" + .fill 5 + .dw EXIT + .dw nativeWord + ld hl, FLAGS + set FLAG_ENDPGM, (hl) + jp exit + ; ( c -- ) EMIT: .db "EMIT", 0, 0, 0, 0 - .dw EXIT + .dw BYE .dw nativeWord pop hl ld a, l @@ -87,6 +96,7 @@ INTERPRET: .db "INTERPRE" .dw KEY .dw nativeWord +interpret: call pad push hl \ pop iy call stdioReadLine diff --git a/apps/forth/main.asm b/apps/forth/main.asm index b1ad497..98783e4 100644 --- a/apps/forth/main.asm +++ b/apps/forth/main.asm @@ -5,32 +5,45 @@ .equ PADDING 0x20 ; Offset of the code link relative to the beginning of the word .equ CODELINK_OFFSET 10 +; When set, the interpret should quit +.equ FLAG_ENDPGM 1 ; *** Variables *** .equ INITIAL_SP FORTH_RAMSTART .equ CURRENT @+2 .equ HERE @+2 .equ INPUTPOS @+2 -.equ FORTH_RAMEND @+2 +.equ FLAGS @+2 +.equ FORTH_RAMEND @+1 ; *** Code *** MAIN: .dw compiledWord .dw INTERPRET+CODELINK_OFFSET - .dw ENDPGM + .dw CHKEND -ENDPGM: +; If FLAG_ENDPGM is set, stop the program, else, tweak the RS so that we loop. +CHKEND: .dw nativeWord + ld hl, FLAGS + bit FLAG_ENDPGM, (hl) + jr nz, .endpgm + ; not quitting, loop + jr forthLoop +.endpgm: ld sp, (INITIAL_SP) xor a ret forthMain: + xor a + ld (FLAGS), a ld (INITIAL_SP), sp ld hl, DOT ; last entry in hardcoded dict ld (CURRENT), hl ld hl, FORTH_RAMEND ld (HERE), hl +forthLoop: ld ix, RS_ADDR ld iy, MAIN jp executeCodeLink