2020-03-07 12:13:15 -05:00
|
|
|
; *** Const ***
|
|
|
|
; Base of the Return Stack
|
|
|
|
.equ RS_ADDR 0xf000
|
|
|
|
; Number of bytes we keep as a padding between HERE and the scratchpad
|
|
|
|
.equ PADDING 0x20
|
2020-03-07 17:09:45 -05:00
|
|
|
; Max length of dict entry names
|
|
|
|
.equ NAMELEN 8
|
2020-03-07 12:13:15 -05:00
|
|
|
; Offset of the code link relative to the beginning of the word
|
2020-03-09 15:12:44 -04:00
|
|
|
.equ CODELINK_OFFSET NAMELEN+2
|
2020-03-07 12:13:15 -05:00
|
|
|
|
|
|
|
; *** Variables ***
|
|
|
|
.equ INITIAL_SP FORTH_RAMSTART
|
|
|
|
.equ CURRENT @+2
|
|
|
|
.equ HERE @+2
|
|
|
|
.equ INPUTPOS @+2
|
2020-03-07 17:09:45 -05:00
|
|
|
; Buffer where we compile the current input line. Same size as STDIO_BUFSIZE.
|
2020-03-09 08:49:51 -04:00
|
|
|
.equ COMPBUF @+2
|
2020-03-07 17:09:45 -05:00
|
|
|
.equ FORTH_RAMEND @+0x40
|
2020-03-07 12:13:15 -05:00
|
|
|
|
|
|
|
; *** Code ***
|
|
|
|
forthMain:
|
2020-03-07 20:20:11 -05:00
|
|
|
; STACK OVERFLOW PROTECTION:
|
|
|
|
; To avoid having to check for stack underflow after each pop operation
|
|
|
|
; (which can end up being prohibitive in terms of costs), we give
|
|
|
|
; ourselves a nice 6 bytes buffer. 6 bytes because we seldom have words
|
|
|
|
; requiring more than 3 items from the stack. Then, at each "exit" call
|
|
|
|
; we check for stack underflow.
|
|
|
|
push af \ push af \ push af
|
2020-03-07 12:13:15 -05:00
|
|
|
ld (INITIAL_SP), sp
|
2020-03-07 22:18:14 -05:00
|
|
|
ld hl, CONSTANT ; last entry in hardcoded dict
|
2020-03-07 12:13:15 -05:00
|
|
|
ld (CURRENT), hl
|
|
|
|
ld hl, FORTH_RAMEND
|
|
|
|
ld (HERE), hl
|
2020-03-07 17:09:45 -05:00
|
|
|
forthRdLine:
|
|
|
|
ld hl, msgOk
|
|
|
|
call printstr
|
|
|
|
call printcrlf
|
|
|
|
call stdioReadLine
|
|
|
|
ld (INPUTPOS), hl
|
|
|
|
forthInterpret:
|
2020-03-09 08:49:51 -04:00
|
|
|
ld ix, RS_ADDR-2 ; -2 because we inc-before-push
|
2020-03-09 15:12:44 -04:00
|
|
|
ld iy, INTERPRET
|
2020-03-07 12:13:15 -05:00
|
|
|
jp executeCodeLink
|
2020-03-07 17:09:45 -05:00
|
|
|
msgOk:
|
|
|
|
.db " ok", 0
|