forth: Forth-ify "(emit)"

This commit is contained in:
Virgil Dupras 2020-03-26 12:05:48 -04:00
parent d1f572d2ed
commit 636407969d
7 changed files with 31 additions and 13 deletions

View File

@ -103,7 +103,7 @@ updatebootstrap: $(ZASMBIN)
# words and they write to HERE at initialization.
.PHONY: fbootstrap
fbootstrap: forth/stage2
cat ../forth/dummy.fs ../forth/z80c.fs ../forth/dummy.fs | ./forth/stage2 | tee forth/z80c.bin > /dev/null
cat ../forth/dummy.fs ../forth/z80c.fs forth/emul.fs ../forth/dummy.fs | ./forth/stage2 | tee forth/z80c.bin > /dev/null
.PHONY: clean
clean:

10
emul/forth/emul.fs Normal file
View File

@ -0,0 +1,10 @@
( Implementation fo KEY and EMIT in the emulator
stdio port is 0
)
CODE (emit)
HL POPqq,
chkPS,
A L LDrr,
0 OUTnA,
;CODE

View File

@ -16,9 +16,4 @@ emulGetC:
cp a ; ensure Z
ret
emulPutC:
out (STDIO_PORT), a
ret
.equ GETC emulGetC
.equ PUTC emulPutC

Binary file not shown.

View File

@ -56,6 +56,8 @@
; interface in Forth, which we plug in during init. If "(c<)" exists in the
; dict, CINPTR is set to it. Otherwise, we set KEY
.equ CINPTR @+2
; Pointer to (emit) word
.equ EMITPTR @+2
.equ WORDBUF @+2
; Sys Vars are variables with their value living in the system RAM segment. We
; need this mechanisms for core Forth source needing variables. Because core
@ -129,6 +131,10 @@ forthMain:
ld hl, .parseName
call find
ld (PARSEPTR), de
; Set up EMITPTR
ld hl, .emitName
call find
ld (EMITPTR), de
; Set up CINPTR
; do we have a (c<) impl?
ld hl, .cinName
@ -149,6 +155,8 @@ forthMain:
.db "(parse)", 0
.cinName:
.db "(c<)", 0
.emitName:
.db "(emit)", 0
BEGIN:
.dw compiledWord
@ -685,12 +693,13 @@ BYE:
.dw $-BYE
.db 4
EMIT:
.dw nativeWord
pop hl
call chkPS
ld a, l
call PUTC
jp next
.dw compiledWord
.dw NUMBER
.dw EMITPTR
.dw FETCH
.dw EXECUTE
.dw EXIT
.db "(print)"
.dw $-EMIT

View File

@ -61,6 +61,7 @@
0xa0 OP1r0 ANDr,
0xb0 OP1r0 ORr,
0xa8 OP1r0 XORr,
0xb8 OP1r0 CPr,
( qq -- also works for ss )
: OP1qq
@ -93,7 +94,7 @@
DOES>
C@ A, A,
;
0xd3 OP2n OUTAn,
0xd3 OP2n OUTnA,
0xdb OP2n INAn,
( r n -- )

View File

@ -17,6 +17,9 @@
These restrictions are temporary, I'll figure something out
so that we can end up fully bootstrap Forth from within
itself.
Oh, also: KEY and EMIT are not defined here. There're
expected to be defined in platform-specific code.
)
( a b c -- b c a )