diff --git a/emul/Makefile b/emul/Makefile index 54270c4..f64568a 100644 --- a/emul/Makefile +++ b/emul/Makefile @@ -16,6 +16,7 @@ $(SLATEST): forth/forth0.bin: $(SLATEST) cat forth/boot.bin forth/z80c.bin > $@ $(SLATEST) $@ + cat forth/emul.fs >> $@ forth/forth0-bin.h: forth/forth0.bin ./bin2c.sh KERNEL < forth/forth0.bin | tee $@ > /dev/null @@ -56,7 +57,7 @@ emul.o: emul.c .PHONY: updatebootstrap updatebootstrap: forth/stage2 cat ./forth/conf.fs ../forth/boot.fs | ./forth/stage2 | tee forth/boot.bin > /dev/null - cat ./forth/conf.fs ../forth/z80c.fs forth/emul.fs ../forth/icore.fs | ./forth/stage2 | tee forth/z80c.bin > /dev/null + cat ./forth/conf.fs ../forth/z80c.fs ../forth/icore.fs | ./forth/stage2 | tee forth/z80c.bin > /dev/null .PHONY: clean clean: diff --git a/emul/forth/emul.fs b/emul/forth/emul.fs index 0f4607b..639426f 100644 --- a/emul/forth/emul.fs +++ b/emul/forth/emul.fs @@ -1,17 +1,3 @@ -( Implementation fo KEY and EMIT in the emulator - stdio port is 0 -) - -CODE EMIT - HL POPqq, - chkPS, - A L LDrr, - 0 OUTnA, -;CODE - -CODE KEY - 0 INAn, - H 0 LDrn, - L A LDrr, - HL PUSHqq, -;CODE +: EMIT 0 PC! ; +: KEY 0 PC@ ; +: (c<) KEY ; diff --git a/forth/icore.fs b/forth/icore.fs index 9299a36..c82be2c 100644 --- a/forth/icore.fs +++ b/forth/icore.fs @@ -189,13 +189,22 @@ AGAIN ; +( system c< simply reads source from binary, starting at + LATEST. Convenient way to bootstrap a new system. ) +: (c<) + ( 51 == SYSTEM SCRATCHPAD ) + 0x51 _c RAM+ _c @ ( a ) + _c DUP _c C@ ( a c ) + _c SWAP 1 _c + ( c a+1 ) + 0x51 _c RAM+ _c ! ( c ) +; + : BOOT LIT< (parse) _c (find) _c DROP _c (parse*) _c ! - LIT< (c<) _c (find) _c - NOT IF LIT< KEY _c (find) _c DROP THEN + ( 51 == SYSTEM SCRATCHPAD ) + _c CURRENT _c @ 0x51 _c RAM+ _c ! ( 0c == CINPTR ) - 0x0c _c RAM+ _c ! - LIT< (c<$) _c (find) IF EXECUTE ELSE _c DROP THEN + LIT< (c<) _c (find) _c DROP 0x0c _c RAM+ _c ! LIT< INIT _c (find) IF EXECUTE ELSE _c DROP _c INTERPRET THEN diff --git a/forth/notes.txt b/forth/notes.txt index f178961..5f203a0 100644 --- a/forth/notes.txt +++ b/forth/notes.txt @@ -88,7 +88,8 @@ RAMSTART INITIAL_SP +0e WORDBUF +2e SYSVNXT +4e INTJUMP -+51 RAMEND ++51 SYSTEM SCRATCHPAD ++60 RAMEND INITIAL_SP holds the initial Stack Pointer value so that we know where to reset it on ABORT @@ -113,3 +114,30 @@ INTJUMP All RST offsets (well, not *all* at this moment, I still have to free those slots...) in boot binaries are made to jump to this address. If you use one of those slots for an interrupt, write a jump to the appropriate offset in that RAM location. + +SYSTEM SCRATCHPAD is reserved for temporary system storage. + +*** Initialization sequence + +On boot, we jump to the "main" routine in boot.fs which does very few things. +It sets up the SP register, CURRENT and HERE to LATEST (saved in stable ABI), +then look for the BOOT word and calls it. + +In a normal system, BOOT is in icore and does a few things: + +1. Find "(parse)" and set "(parse*)" to it. +2. Find "(c<)" a set CINPTR to it (what C< calls). +3. Write LATEST in SYSTEM SCRATCHPAD ( see below ) +4. Find "INIT". If found, execute. Otherwise, execute "INTERPRET" + +On a bare system (only boot+icore), this sequence will result in "(parse)" +reading only decimals and (c<) reading characters from memory starting from +CURRENT (this is why we put CURRENT in SYSTEM SCRATCHPAD, it tracks current +pos ). + +This means that you can put initialization code in source form right into your +binary, right after your last compiled dict entry and it's going to be executed +as such until you set a new (c<). + +Note that there is no EMIT in a bare system. You have to take care of supplying +one before your load core.fs and its higher levels.