diff --git a/emul/.gitignore b/emul/.gitignore index 7843c19..0f177a7 100644 --- a/emul/.gitignore +++ b/emul/.gitignore @@ -1,14 +1,8 @@ -/shell/shell /forth/stage1 /forth/stage1dbg /forth/stage2 /forth/stage2dbg /forth/forth -/zasm/zasm -/zasm/avra /runbin/runbin /*/*-bin.h /*/*.bin -/cfsin/zasm -/cfsin/ed -/cfsin/user.h diff --git a/emul/Makefile b/emul/Makefile index ad24183..75f73b3 100644 --- a/emul/Makefile +++ b/emul/Makefile @@ -1,4 +1,5 @@ TARGETS = runbin/runbin forth/forth +BIN2C = ../tools/bin2c # Those Forth source files are in a particular order FORTHSRCS = core.fs cmp.fs print.fs str.fs parse.fs readln.fs fmt.fs z80a.fs \ link.fs @@ -12,6 +13,7 @@ all: $(TARGETS) $(STRIPFC): $(SLATEST): +$(BIN2C): $(MAKE) -C ../tools # z80c.bin and boot.bin are not in the prerequisites because they're bootstrap @@ -21,8 +23,8 @@ forth/forth0.bin: $(SLATEST) $(SLATEST) $@ cat forth/emul.fs >> $@ -forth/forth0-bin.h: forth/forth0.bin - ./bin2c.sh KERNEL < forth/forth0.bin | tee $@ > /dev/null +forth/forth0-bin.h: forth/forth0.bin $(BIN2C) + $(BIN2C) KERNEL < forth/forth0.bin | tee $@ > /dev/null forth/stage1: forth/stage.c $(OBJS) forth/forth0-bin.h $(CC) forth/stage.c $(OBJS) -o $@ @@ -39,8 +41,8 @@ forth/forth1.bin: forth/core.bin $(SLATEST) cat forth/boot.bin forth/z80c.bin forth/core.bin > $@ $(SLATEST) $@ -forth/forth1-bin.h: forth/forth1.bin - ./bin2c.sh KERNEL < forth/forth1.bin | tee $@ > /dev/null +forth/forth1-bin.h: forth/forth1.bin $(BIN2C) + $(BIN2C) KERNEL < forth/forth1.bin | tee $@ > /dev/null forth/stage2: forth/stage.c $(OBJS) forth/forth1-bin.h $(CC) -DSTAGE2 forth/stage.c $(OBJS) -o $@ @@ -67,3 +69,4 @@ updatebootstrap: forth/stage2 .PHONY: clean clean: rm -f $(TARGETS) emul.o forth/*-bin.h forth/forth?.bin + $(MAKE) -C ../tools clean diff --git a/emul/bin2c.sh b/emul/bin2c.sh deleted file mode 100755 index 62f0c09..0000000 --- a/emul/bin2c.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -echo "unsigned char $1[] = { " -xxd -i - -echo " };" diff --git a/tools/.gitignore b/tools/.gitignore index 2de759b..bcca6b1 100644 --- a/tools/.gitignore +++ b/tools/.gitignore @@ -6,3 +6,4 @@ /pingpong /slatest /stripfc +/bin2c diff --git a/tools/Makefile b/tools/Makefile index d23016c..a676406 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -6,8 +6,10 @@ TTYSAFE_TGT = ttysafe PINGPONG_TGT = pingpong SLATEST_TGT = slatest STRIPFC_TGT = stripfc +BIN2C_TGT = bin2c TARGETS = $(MEMDUMP_TGT) $(BLKDUMP_TGT) $(UPLOAD_TGT) $(FONTCOMPILE_TGT) \ - $(TTYSAFE_TGT) $(PINGPONG_TGT) $(SLATEST_TGT) $(STRIPFC_TGT) + $(TTYSAFE_TGT) $(PINGPONG_TGT) $(SLATEST_TGT) $(STRIPFC_TGT) \ + $(BIN2C_TGT) OBJS = common.o all: $(TARGETS) @@ -24,6 +26,7 @@ $(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 $(TARGETS): $(OBJS) $(CC) $(CFLAGS) $@.c $(OBJS) -o $@ diff --git a/tools/bin2c.c b/tools/bin2c.c new file mode 100644 index 0000000..93843b7 --- /dev/null +++ b/tools/bin2c.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2020 Byron Grobe + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include + +#define BUFSZ 32 + +static const char intro[] = "static const unsigned char %s[] = {\n "; + +int main(int argc, char **argv) { + int n; + int col = 0; + uint8_t buf[BUFSZ]; + + if (argc < 2) { + fprintf(stderr, "Specify a name for the data structure...\n"); + return 1; + } + + printf(intro, argv[1]); + + while(!feof(stdin)) { + n = fread(buf, 1, BUFSZ, stdin); + for(int i = 0; i < n; ++i) { + if (col+4 >= 76) { + printf("\n "); + col = 0; + } + printf("0x%.2x, ", buf[i]); + col += 6; + } + } + + printf("};\n"); +}