1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-30 20:28:05 +11:00

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. # words and they write to HERE at initialization.
.PHONY: fbootstrap .PHONY: fbootstrap
fbootstrap: forth/stage2 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 .PHONY: clean
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 cp a ; ensure Z
ret ret
emulPutC:
out (STDIO_PORT), a
ret
.equ GETC emulGetC .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 ; interface in Forth, which we plug in during init. If "(c<)" exists in the
; dict, CINPTR is set to it. Otherwise, we set KEY ; dict, CINPTR is set to it. Otherwise, we set KEY
.equ CINPTR @+2 .equ CINPTR @+2
; Pointer to (emit) word
.equ EMITPTR @+2
.equ WORDBUF @+2 .equ WORDBUF @+2
; Sys Vars are variables with their value living in the system RAM segment. We ; 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 ; need this mechanisms for core Forth source needing variables. Because core
@ -129,6 +131,10 @@ forthMain:
ld hl, .parseName ld hl, .parseName
call find call find
ld (PARSEPTR), de ld (PARSEPTR), de
; Set up EMITPTR
ld hl, .emitName
call find
ld (EMITPTR), de
; Set up CINPTR ; Set up CINPTR
; do we have a (c<) impl? ; do we have a (c<) impl?
ld hl, .cinName ld hl, .cinName
@ -149,6 +155,8 @@ forthMain:
.db "(parse)", 0 .db "(parse)", 0
.cinName: .cinName:
.db "(c<)", 0 .db "(c<)", 0
.emitName:
.db "(emit)", 0
BEGIN: BEGIN:
.dw compiledWord .dw compiledWord
@ -685,12 +693,13 @@ BYE:
.dw $-BYE .dw $-BYE
.db 4 .db 4
EMIT: EMIT:
.dw nativeWord .dw compiledWord
pop hl .dw NUMBER
call chkPS .dw EMITPTR
ld a, l .dw FETCH
call PUTC .dw EXECUTE
jp next .dw EXIT
.db "(print)" .db "(print)"
.dw $-EMIT .dw $-EMIT

View File

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

View File

@ -17,6 +17,9 @@
These restrictions are temporary, I'll figure something out These restrictions are temporary, I'll figure something out
so that we can end up fully bootstrap Forth from within so that we can end up fully bootstrap Forth from within
itself. 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 ) ( a b c -- b c a )