diff --git a/blk/262 b/blk/262 index bb7e6d5..d657f75 100644 --- a/blk/262 +++ b/blk/262 @@ -1 +1 @@ -263 LOAD 265 LOAD 268 LOAD +263 LOAD 265 LOAD 268 LOAD 269 LOAD diff --git a/emul/Makefile b/emul/Makefile index 94a01b5..7f4e648 100644 --- a/emul/Makefile +++ b/emul/Makefile @@ -1,10 +1,5 @@ TARGETS = forth stage2 -# Those Forth source files are in a particular order -FORTHSRCS = core.fs cmp.fs print.fs parse.fs readln.fs fmt.fs blk.fs -FORTHSRC_PATHS = ${FORTHSRCS:%=../forth/%} run.fs OBJS = emul.o libz80/libz80.o -SLATEST = ../tools/slatest -STRIPFC = ../tools/stripfc BIN2C = ../tools/bin2c BLKPACK = ../tools/blkpack BLKUNPACK = ../tools/blkunpack @@ -15,40 +10,26 @@ all: $(TARGETS) $(BLKPACK): $(MAKE) -C ../tools -.PHONY: $(STRIPFC) $(SLATEST) $(BIN2C) -$(STRIPFC): $(BLKPACK) -$(SLATEST): $(BLKPACK) +.PHONY: $(BIN2C) $(BLKUNPACK) $(BIN2C): $(BLKPACK) $(BLKUNPACK): $(BLKPACK) -# z80c.bin is not in the prerequisites because it's a bootstrap -# binary that should be updated manually through make updatebootstrap. -forth0.bin: - cp z80c.bin $@ - cat stage1.fs >> $@ +stage0-bin.h: $(BIN2C) + $(BIN2C) KERNEL < stage0.bin > $@ -forth0-bin.h: forth0.bin $(BIN2C) - $(BIN2C) KERNEL < forth0.bin | tee $@ > /dev/null - -stage1: stage.c $(OBJS) forth0-bin.h +stage1: stage.c $(OBJS) stage0-bin.h $(CC) stage.c $(OBJS) -o $@ -stage1dbg: stage.c $(OBJS) forth0-bin.h +stage1dbg: stage.c $(OBJS) stage0-bin.h $(CC) -DDEBUG stage.c $(OBJS) -o $@ -# We don't really need to use stripfc, but we do it anyway to test that we -# don't mistakenly break our code with that tool. It's easier to debug here. -core.bin: $(FORTHSRC_PATHS) stage1 - cat $(FORTHSRC_PATHS) stop.fs | $(STRIPFC) | ./stage1 > $@ +stage1.bin: stage1.fs stage1 + ./stage1 < stage1.fs > $@ -forth1.bin: core.bin $(SLATEST) - cat z80c.bin core.bin > $@ - $(SLATEST) $@ +stage1-bin.h: stage1.bin $(BIN2C) + $(BIN2C) KERNEL < stage1.bin > $@ -forth1-bin.h: forth1.bin $(BIN2C) - $(BIN2C) KERNEL < forth1.bin > $@ - -stage2: stage.c $(OBJS) forth1-bin.h blkfs-bin.h +stage2: stage.c $(OBJS) stage1-bin.h blkfs-bin.h $(CC) -DSTAGE2 stage.c $(OBJS) -o $@ blkfs: $(BLKPACK) @@ -57,7 +38,7 @@ blkfs: $(BLKPACK) blkfs-bin.h: blkfs $(BIN2C) $(BIN2C) BLKFS < blkfs > $@ -forth: forth.c $(OBJS) forth1-bin.h blkfs-bin.h +forth: forth.c $(OBJS) stage1-bin.h blkfs-bin.h $(CC) forth.c $(OBJS) -o $@ libz80/libz80.o: libz80/z80.c @@ -70,7 +51,7 @@ emul.o: emul.c .PHONY: updatebootstrap updatebootstrap: stage2 - cat xcomp.fs | ./stage2 > z80c.bin + cat xcomp.fs | ./stage2 > stage0.bin .PHONY: pack pack: @@ -82,5 +63,5 @@ unpack: .PHONY: clean clean: - rm -f $(TARGETS) emul.o *-bin.h forth?.bin blkfs + rm -f $(TARGETS) emul.o *-bin.h stage{1,2}.bin blkfs $(MAKE) -C ../tools clean diff --git a/emul/forth.c b/emul/forth.c index 4677eac..cd10bbb 100644 --- a/emul/forth.c +++ b/emul/forth.c @@ -3,7 +3,7 @@ #include #include #include "emul.h" -#include "forth1-bin.h" +#include "stage1-bin.h" #include "blkfs-bin.h" // in sync with glue.asm diff --git a/emul/stage.c b/emul/stage.c index b6cef1d..27d4aea 100644 --- a/emul/stage.c +++ b/emul/stage.c @@ -3,10 +3,10 @@ #include #include "emul.h" #ifdef STAGE2 -#include "forth1-bin.h" +#include "stage1-bin.h" #include "blkfs-bin.h" #else -#include "forth0-bin.h" +#include "stage0-bin.h" #endif /* Staging binaries @@ -29,8 +29,7 @@ trouble of compiling defs to binary. // By the way: there's a double-echo in stagedbg. It's normal. Don't panic. //#define DEBUG -// in sync with glue.asm -#define RAMSTART 0x840 +#define RAMSTART 0 #define STDIO_PORT 0x00 // To know which part of RAM to dump, we listen to port 2, which at the end of // its compilation process, spits its HERE addr to port 2 (MSB first) @@ -112,11 +111,6 @@ int main(int argc, char *argv[]) #ifndef DEBUG // We're done, now let's spit dict data - if (start_here == 0) { - // No starting offset? Let's use LATEST - start_here = m->mem[0x08]; - start_here += m->mem[0x09] << 8; - } for (int i=start_here; imem[i]); } diff --git a/emul/stage0.bin b/emul/stage0.bin new file mode 100644 index 0000000..2a06379 Binary files /dev/null and b/emul/stage0.bin differ diff --git a/emul/stage1.fs b/emul/stage1.fs index a2ab67d..62fb584 100644 --- a/emul/stage1.fs +++ b/emul/stage1.fs @@ -1,4 +1,28 @@ -CURRENT @ HERE ! -: EMIT 0 PC! ; -: KEY 0 PC@ ; -CURRENT @ 12 RAM+ ! +: EFS@ + 256 /MOD 3 PC! 3 PC! + 1024 0 DO + 4 PC@ + BLK( I + C! + LOOP +; +: EFS! + 256 /MOD 3 PC! 3 PC! + 1024 0 DO + BLK( I + C@ 4 PC! + LOOP +; + +: INIT + CURRENT @ HERE ! + BLK$ + ['] EFS@ BLK@* ! + ['] EFS! BLK!* ! + RDLN$ + LIT< _sys [entry] + ." Collapse OS" CRLF + INTERPRET +; + +(entry) _ +H@ 256 /MOD 2 PC! 2 PC! +H@ 0x08 ! ( update LATEST ) diff --git a/emul/xcomp.fs b/emul/xcomp.fs index 360d603..cb05a61 100644 --- a/emul/xcomp.fs +++ b/emul/xcomp.fs @@ -16,4 +16,9 @@ H@ XOFF ! (entry) _ ( Update LATEST ) H@ XOFF @ - XOFF @ 8 + ! +," CURRENT @ HERE ! " +," : EMIT 0 PC! ; " +," : KEY 0 PC@ ; " +422 470 XPACKR +," ' KEY 12 RAM+ ! " H@ 256 /MOD 2 PC! 2 PC! diff --git a/emul/z80c.bin b/emul/z80c.bin deleted file mode 100644 index a3e8a94..0000000 Binary files a/emul/z80c.bin and /dev/null differ diff --git a/recipes/rc2014/Makefile b/recipes/rc2014/Makefile index e53bdc8..0825dd6 100644 --- a/recipes/rc2014/Makefile +++ b/recipes/rc2014/Makefile @@ -14,14 +14,12 @@ PATHS = \ $(FDIR)/fmt.fs \ $(FDIR)/link.fs \ run.fs -SLATEST = $(BASEDIR)/tools/slatest STRIPFC = $(BASEDIR)/tools/stripfc .PHONY: all all: $(TARGET) -$(TARGET): z80c.bin $(SLATEST) $(PATHS) +$(TARGET): z80c.bin $(PATHS) cp z80c.bin $@ - $(SLATEST) $@ cat $(PATHS) | $(STRIPFC) >> $@ z80c.bin: xcomp.fs diff --git a/recipes/rc2014/xcomp.fs b/recipes/rc2014/xcomp.fs index c6adf40..a3fbebe 100644 --- a/recipes/rc2014/xcomp.fs +++ b/recipes/rc2014/xcomp.fs @@ -22,4 +22,6 @@ H@ XOFF ! 372 LOAD ( sdc.z80 ) 393 LOAD ( icore ) (entry) _ +( Update LATEST ) +H@ XOFF @ - XOFF @ 8 + ! H@ 256 /MOD 2 PC! 2 PC! diff --git a/tools/Makefile b/tools/Makefile index d1e88fc..96609a5 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -4,14 +4,13 @@ UPLOAD_TGT = upload FONTCOMPILE_TGT = fontcompile TTYSAFE_TGT = ttysafe PINGPONG_TGT = pingpong -SLATEST_TGT = slatest STRIPFC_TGT = stripfc BIN2C_TGT = bin2c EXEC_TGT = exec BLKPACK_TGT = blkpack BLKUNPACK_TGT = blkunpack TARGETS = $(MEMDUMP_TGT) $(BLKDUMP_TGT) $(UPLOAD_TGT) $(FONTCOMPILE_TGT) \ - $(TTYSAFE_TGT) $(PINGPONG_TGT) $(SLATEST_TGT) $(STRIPFC_TGT) \ + $(TTYSAFE_TGT) $(PINGPONG_TGT) $(STRIPFC_TGT) \ $(BIN2C_TGT) $(EXEC_TGT) $(BLKPACK_TGT) $(BLKUNPACK_TGT) OBJS = common.o @@ -27,7 +26,6 @@ $(UPLOAD_TGT): $(UPLOAD_TGT).c $(FONTCOMPILE_TGT): $(FONTCOMPILE_TGT).c $(TTYSAFE_TGT): $(TTYSAFE_TGT).c $(PINGPONG_TGT): $(PINGPONG_TGT).c -$(SLATEST_TGT): $(SLATEST_TGT).c $(STRIPFC_TGT): $(STRIPFC_TGT).c $(BIN2C_TGT): $(BIN2C_TGT).c $(EXEC_TGT): $(EXEC_TGT).c diff --git a/tools/slatest.c b/tools/slatest.c deleted file mode 100644 index 06af597..0000000 --- a/tools/slatest.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include -#include - -/* Update the "LATEST" offset of target Forth binary according to filesize. */ - -#define OFFSET 0x08 - -int main(int argc, char **argv) -{ - if (argc != 2) { - fprintf(stderr, "Usage: ./slatest fname\n"); - return 1; - } - FILE *fp = fopen(argv[1], "r+"); - if (!fp) { - fprintf(stderr, "Can't open %s.\n", argv[1]); - return 1; - } - fseek(fp, 0, SEEK_END); - unsigned int bytecount = ftell(fp); - fseek(fp, OFFSET, SEEK_SET); - char buf[2]; - buf[0] = bytecount & 0xff; - buf[1] = bytecount >> 8; - fwrite(buf, 2, 1, fp); - fclose(fp); -}