forth: add word "bye"
And make interpret action looping until BYE.
This commit is contained in:
parent
391ddb9984
commit
6f9d28b325
@ -45,10 +45,19 @@ exit:
|
|||||||
push hl \ pop iy
|
push hl \ pop iy
|
||||||
jp compiledWord
|
jp compiledWord
|
||||||
|
|
||||||
|
BYE:
|
||||||
|
.db "BYE"
|
||||||
|
.fill 5
|
||||||
|
.dw EXIT
|
||||||
|
.dw nativeWord
|
||||||
|
ld hl, FLAGS
|
||||||
|
set FLAG_ENDPGM, (hl)
|
||||||
|
jp exit
|
||||||
|
|
||||||
; ( c -- )
|
; ( c -- )
|
||||||
EMIT:
|
EMIT:
|
||||||
.db "EMIT", 0, 0, 0, 0
|
.db "EMIT", 0, 0, 0, 0
|
||||||
.dw EXIT
|
.dw BYE
|
||||||
.dw nativeWord
|
.dw nativeWord
|
||||||
pop hl
|
pop hl
|
||||||
ld a, l
|
ld a, l
|
||||||
@ -87,6 +96,7 @@ INTERPRET:
|
|||||||
.db "INTERPRE"
|
.db "INTERPRE"
|
||||||
.dw KEY
|
.dw KEY
|
||||||
.dw nativeWord
|
.dw nativeWord
|
||||||
|
interpret:
|
||||||
call pad
|
call pad
|
||||||
push hl \ pop iy
|
push hl \ pop iy
|
||||||
call stdioReadLine
|
call stdioReadLine
|
||||||
|
@ -5,32 +5,45 @@
|
|||||||
.equ PADDING 0x20
|
.equ PADDING 0x20
|
||||||
; Offset of the code link relative to the beginning of the word
|
; Offset of the code link relative to the beginning of the word
|
||||||
.equ CODELINK_OFFSET 10
|
.equ CODELINK_OFFSET 10
|
||||||
|
; When set, the interpret should quit
|
||||||
|
.equ FLAG_ENDPGM 1
|
||||||
|
|
||||||
; *** Variables ***
|
; *** Variables ***
|
||||||
.equ INITIAL_SP FORTH_RAMSTART
|
.equ INITIAL_SP FORTH_RAMSTART
|
||||||
.equ CURRENT @+2
|
.equ CURRENT @+2
|
||||||
.equ HERE @+2
|
.equ HERE @+2
|
||||||
.equ INPUTPOS @+2
|
.equ INPUTPOS @+2
|
||||||
.equ FORTH_RAMEND @+2
|
.equ FLAGS @+2
|
||||||
|
.equ FORTH_RAMEND @+1
|
||||||
|
|
||||||
; *** Code ***
|
; *** Code ***
|
||||||
MAIN:
|
MAIN:
|
||||||
.dw compiledWord
|
.dw compiledWord
|
||||||
.dw INTERPRET+CODELINK_OFFSET
|
.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
|
.dw nativeWord
|
||||||
|
ld hl, FLAGS
|
||||||
|
bit FLAG_ENDPGM, (hl)
|
||||||
|
jr nz, .endpgm
|
||||||
|
; not quitting, loop
|
||||||
|
jr forthLoop
|
||||||
|
.endpgm:
|
||||||
ld sp, (INITIAL_SP)
|
ld sp, (INITIAL_SP)
|
||||||
xor a
|
xor a
|
||||||
ret
|
ret
|
||||||
|
|
||||||
forthMain:
|
forthMain:
|
||||||
|
xor a
|
||||||
|
ld (FLAGS), a
|
||||||
ld (INITIAL_SP), sp
|
ld (INITIAL_SP), sp
|
||||||
ld hl, DOT ; last entry in hardcoded dict
|
ld hl, DOT ; last entry in hardcoded dict
|
||||||
ld (CURRENT), hl
|
ld (CURRENT), hl
|
||||||
ld hl, FORTH_RAMEND
|
ld hl, FORTH_RAMEND
|
||||||
ld (HERE), hl
|
ld (HERE), hl
|
||||||
|
forthLoop:
|
||||||
ld ix, RS_ADDR
|
ld ix, RS_ADDR
|
||||||
ld iy, MAIN
|
ld iy, MAIN
|
||||||
jp executeCodeLink
|
jp executeCodeLink
|
||||||
|
Loading…
Reference in New Issue
Block a user