1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-10-07 12:30:55 +11:00
collapseos/apps/forth/main.asm

50 lines
971 B
NASM
Raw Normal View History

2020-03-08 04:13:15 +11: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
; 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
2020-03-08 04:13:15 +11:00
; *** Variables ***
.equ INITIAL_SP FORTH_RAMSTART
.equ CURRENT @+2
.equ HERE @+2
.equ INPUTPOS @+2
.equ FLAGS @+2
.equ FORTH_RAMEND @+1
2020-03-08 04:13:15 +11:00
; *** Code ***
MAIN:
.dw compiledWord
.dw INTERPRET+CODELINK_OFFSET
.dw CHKEND
2020-03-08 04:13:15 +11:00
; If FLAG_ENDPGM is set, stop the program, else, tweak the RS so that we loop.
CHKEND:
2020-03-08 04:13:15 +11:00
.dw nativeWord
ld hl, FLAGS
bit FLAG_ENDPGM, (hl)
jr nz, .endpgm
; not quitting, loop
jr forthLoop
.endpgm:
2020-03-08 04:13:15 +11:00
ld sp, (INITIAL_SP)
xor a
ret
forthMain:
xor a
ld (FLAGS), a
2020-03-08 04:13:15 +11:00
ld (INITIAL_SP), sp
2020-03-08 04:50:54 +11:00
ld hl, DOT ; last entry in hardcoded dict
2020-03-08 04:13:15 +11:00
ld (CURRENT), hl
ld hl, FORTH_RAMEND
ld (HERE), hl
forthLoop:
2020-03-08 04:13:15 +11:00
ld ix, RS_ADDR
ld iy, MAIN
jp executeCodeLink