diff --git a/emul/Makefile b/emul/Makefile index 7c5f45a..c78c3c9 100644 --- a/emul/Makefile +++ b/emul/Makefile @@ -1,4 +1,4 @@ -TARGETS = forth stage +TARGETS = forth stage blkfs OBJS = emul.o libz80/libz80.o BIN2C = ../tools/bin2c BLKPACK = ../tools/blkpack @@ -18,17 +18,14 @@ $(BLKUNPACK): $(BLKPACK) forth-bin.h: $(BIN2C) $(BIN2C) KERNEL < forth.bin > $@ -stage: stage.c $(OBJS) forth-bin.h blkfs-bin.h - $(CC) stage.c $(OBJS) -o $@ +stage: stage.c $(OBJS) forth-bin.h + $(CC) stage.c -DBLKFS_PATH=\"`pwd`/blkfs\" $(OBJS) -o $@ blkfs: $(BLKPACK) $(BLKPACK) ../blk > $@ -blkfs-bin.h: blkfs $(BIN2C) - $(BIN2C) BLKFS < blkfs > $@ - -forth: forth.c $(OBJS) forth-bin.h blkfs-bin.h - $(CC) forth.c $(OBJS) -lncurses -o $@ +forth: forth.c $(OBJS) forth-bin.h + $(CC) forth.c -DBLKFS_PATH=\"`pwd`/blkfs\" $(OBJS) -lncurses -o $@ libz80/libz80.o: libz80/z80.c $(MAKE) -C libz80/codegen opcodes @@ -39,7 +36,7 @@ emul.o: emul.c .PHONY: updatebootstrap -updatebootstrap: stage xcomp.fs +updatebootstrap: stage xcomp.fs pack ./stage < xcomp.fs > forth.bin .PHONY: pack @@ -52,5 +49,4 @@ unpack: .PHONY: clean clean: - rm -f $(TARGETS) emul.o *-bin.h stage{1,2}.bin blkfs - $(MAKE) -C ../tools clean + rm -f $(TARGETS) emul.o *-bin.h blkfs diff --git a/emul/forth.c b/emul/forth.c index 0cfc8d2..cf4a5e9 100644 --- a/emul/forth.c +++ b/emul/forth.c @@ -5,7 +5,6 @@ #include #include "emul.h" #include "forth-bin.h" -#include "blkfs-bin.h" // in sync with glue.asm #define RAMSTART 0x900 @@ -83,13 +82,15 @@ static void iowr_blkdata(uint8_t val) int run() { - blkfp = fopen("blkfs", "r+"); - if (blkfp) { - fprintf(stderr, "Using blkfs file\n"); - } else { - blkfp = fmemopen((char*)BLKFS, sizeof(BLKFS), "r"); - fprintf(stderr, "Using in-memory read-only blkfs\n"); +#ifdef BLKFS_PATH + fprintf(stderr, "Using blkfs %s\n", BLKFS_PATH); + blkfp = fopen(BLKFS_PATH, "r+"); + if (!blkfp) { + fprintf(stderr, "Can't open\n"); } +#else + blkfp = NULL; +#endif Machine *m = emul_init(); m->ramstart = RAMSTART; m->iord[STDIO_PORT] = iord_stdio; diff --git a/emul/stage.c b/emul/stage.c index 7b5b3b8..48bf19b 100644 --- a/emul/stage.c +++ b/emul/stage.c @@ -3,7 +3,10 @@ #include #include "emul.h" #include "forth-bin.h" -#include "blkfs-bin.h" + +#ifndef BLKFS_PATH +#error BLKFS_PATH needed +#endif /* Staging binaries @@ -37,7 +40,7 @@ static int running; static uint16_t start_here = 0; static uint16_t end_here = 0; static uint16_t blkid = 0; -static unsigned int blkpos = 0; +static FILE *blkfp; static uint8_t iord_stdio() { @@ -65,16 +68,22 @@ static void iowr_blk(uint8_t val) { blkid <<= 8; blkid |= val; - blkpos = blkid * 1024; + fseek(blkfp, blkid*1024, SEEK_SET); } static uint8_t iord_blkdata() { - return BLKFS[blkpos++]; + return getc(blkfp); } int main(int argc, char *argv[]) { + fprintf(stderr, "Using blkfs %s\n", BLKFS_PATH); + blkfp = fopen(BLKFS_PATH, "r+"); + if (!blkfp) { + fprintf(stderr, "Can't open\n"); + return 1; + } Machine *m = emul_init(); m->ramstart = RAMSTART; m->iord[STDIO_PORT] = iord_stdio;