From f65c189e9b2250862acf5e03257be1cd0eff1b70 Mon Sep 17 00:00:00 2001 From: "Byron A. Grobe" Date: Sun, 5 Apr 2020 13:04:05 -0500 Subject: [PATCH 1/3] Replace bin2c.sh with a more portable implementation. `xxd' is not available on all systems, and on others does not support the `-i' flag. Since bin2c.sh relied on a tool that I can't seem to find a compatible version of, I have included a simple, portable replacement in C. Usage remains the same: bin2c ARRAYNAME < inputfile > outputfile. This change is also reflected in emul/Makefile. --- emul/Makefile | 31 ++++++++++++++++++------------- emul/bin2c.sh | 5 ----- tools/bin2c/Makefile | 12 ++++++++++++ tools/bin2c/bin2c.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 18 deletions(-) delete mode 100755 emul/bin2c.sh create mode 100644 tools/bin2c/Makefile create mode 100644 tools/bin2c/bin2c.c diff --git a/emul/Makefile b/emul/Makefile index 1728a8c..46a7043 100644 --- a/emul/Makefile +++ b/emul/Makefile @@ -6,6 +6,7 @@ ZASMBIN = zasm/zasm AVRABIN = zasm/avra SHELLAPPS = zasm ed SHELLTGTS = ${SHELLAPPS:%=cfsin/%} +BIN2C = ../tools/bin2c/bin2c # Those Forth source files are in a particular order FORTHSRCS = core.fs str.fs parse.fs readln.fs fmt.fs z80a.fs FORTHSRC_PATHS = ${FORTHSRCS:%=../forth/%} @@ -17,12 +18,15 @@ ZASMOBJS = $(SHELLOBJS) .PHONY: all all: $(TARGETS) $(AVRABIN) $(CFSIN_CONTENTS) +$(BIN2C): ../tools/bin2c/bin2c.c + $(MAKE) -C ../tools/bin2c + # -o in sync with SHELL_CODE in shell/glue.asm -shell/shell.bin: shell/glue.asm $(ZASMBIN) +shell/shell.bin: shell/glue.asm $(ZASMBIN) $(BIN2C) $(ZASMBIN) $(KERNEL) shell/user.h $(APPS) < shell/glue.asm | tee $@ > /dev/null -shell/shell-bin.h: shell/shell.bin - ./bin2c.sh KERNEL < shell/shell.bin | tee $@ > /dev/null +shell/shell-bin.h: shell/shell.bin $(BIN2C) + $(BIN2C) KERNEL < shell/shell.bin | tee $@ > /dev/null shell/shell: shell/shell.c $(SHELLOBJS) shell/shell-bin.h $(CC) shell/shell.c $(SHELLOBJS) -o $@ @@ -32,8 +36,8 @@ shell/shell: shell/shell.c $(SHELLOBJS) shell/shell-bin.h forth/forth0.bin: cat forth/boot.bin forth/z80c.bin > $@ -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 $@ @@ -47,8 +51,8 @@ forth/core.bin: $(FORTHSRC_PATHS) forth/stage1 forth/forth1.bin: forth/forth0.bin forth/core.bin cat forth/forth0.bin forth/core.bin > $@ -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 $@ @@ -56,11 +60,11 @@ forth/stage2: forth/stage.c $(OBJS) forth/forth1-bin.h forth/forth: forth/forth.c $(OBJS) forth/forth1-bin.h $(CC) forth/forth.c $(OBJS) -o $@ -zasm/kernel-bin.h: zasm/kernel.bin - ./bin2c.sh KERNEL < zasm/kernel.bin | tee $@ > /dev/null +zasm/kernel-bin.h: zasm/kernel.bin $(BIN2C) + $(BIN2C) KERNEL < zasm/kernel.bin | tee $@ > /dev/null -zasm/zasm-bin.h: zasm/zasm.bin - ./bin2c.sh USERSPACE < zasm/zasm.bin | tee $@ > /dev/null +zasm/zasm-bin.h: zasm/zasm.bin $(BIN2C) + $(BIN2C) USERSPACE < zasm/zasm.bin | tee $@ > /dev/null $(ZASMBIN): zasm/zasm.c $(ZASMOBJS) zasm/kernel-bin.h zasm/zasm-bin.h $(CC) zasm/zasm.c $(ZASMOBJS) -o $@ @@ -68,8 +72,8 @@ $(ZASMBIN): zasm/zasm.c $(ZASMOBJS) zasm/kernel-bin.h zasm/zasm-bin.h zasm/avra.bin: $(ZASMBIN) $(ZASMBIN) $(KERNEL) $(APPS) zasm/user.h < $(APPS)/zasm/gluea.asm > $@ -zasm/avra-bin.h: zasm/avra.bin - ./bin2c.sh USERSPACE < zasm/avra.bin | tee $@ > /dev/null +zasm/avra-bin.h: zasm/avra.bin $(BIN2C) + $(BIN2C) USERSPACE < zasm/avra.bin | tee $@ > /dev/null $(AVRABIN): zasm/zasm.c $(ZASMOBJS) zasm/kernel-bin.h zasm/avra-bin.h $(CC) -D AVRA zasm/zasm.c $(ZASMOBJS) -o $@ @@ -109,3 +113,4 @@ fbootstrap: forth/stage2 .PHONY: clean clean: rm -f $(TARGETS) $(SHELLTGTS) emul.o zasm/*-bin.h shell/*-bin.h + $(MAKE) -C ../tools/bin2c 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/bin2c/Makefile b/tools/bin2c/Makefile new file mode 100644 index 0000000..3d331f9 --- /dev/null +++ b/tools/bin2c/Makefile @@ -0,0 +1,12 @@ +.PHONY: all clean + +all: bin2c + +bin2c: bin2c.o + $(CC) -o $@ $< + +%.o: %.c + $(CC) -c -o $@ $< + +clean: + rm -rf bin2c bin2c.o diff --git a/tools/bin2c/bin2c.c b/tools/bin2c/bin2c.c new file mode 100644 index 0000000..9f65167 --- /dev/null +++ b/tools/bin2c/bin2c.c @@ -0,0 +1,33 @@ +#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"); +} From 217df20d772b5e5f4f625f6e5e7b00981245b533 Mon Sep 17 00:00:00 2001 From: "Byron A. Grobe" Date: Tue, 7 Apr 2020 16:56:55 -0500 Subject: [PATCH 2/3] Moved tools/bin2c to single-level with other tools. --- emul/Makefile | 24 +++++++++++----------- tools/Makefile | 4 +++- tools/bin2c.c | 49 ++++++++++++++++++++++++++++++++++++++++++++ tools/bin2c/Makefile | 12 ----------- tools/bin2c/bin2c.c | 33 ----------------------------- 5 files changed, 64 insertions(+), 58 deletions(-) create mode 100644 tools/bin2c.c delete mode 100644 tools/bin2c/Makefile delete mode 100644 tools/bin2c/bin2c.c diff --git a/emul/Makefile b/emul/Makefile index 46a7043..6fde382 100644 --- a/emul/Makefile +++ b/emul/Makefile @@ -6,7 +6,7 @@ ZASMBIN = zasm/zasm AVRABIN = zasm/avra SHELLAPPS = zasm ed SHELLTGTS = ${SHELLAPPS:%=cfsin/%} -BIN2C = ../tools/bin2c/bin2c +BIN2C = ../tools/bin2c # Those Forth source files are in a particular order FORTHSRCS = core.fs str.fs parse.fs readln.fs fmt.fs z80a.fs FORTHSRC_PATHS = ${FORTHSRCS:%=../forth/%} @@ -15,17 +15,17 @@ OBJS = emul.o libz80/libz80.o SHELLOBJS = $(OBJS) $(CFSPACK_OBJ) ZASMOBJS = $(SHELLOBJS) -.PHONY: all +.PHONY: all tools all: $(TARGETS) $(AVRABIN) $(CFSIN_CONTENTS) -$(BIN2C): ../tools/bin2c/bin2c.c - $(MAKE) -C ../tools/bin2c +tools: + $(MAKE) -C ../tools # -o in sync with SHELL_CODE in shell/glue.asm -shell/shell.bin: shell/glue.asm $(ZASMBIN) $(BIN2C) +shell/shell.bin: shell/glue.asm $(ZASMBIN) tools $(ZASMBIN) $(KERNEL) shell/user.h $(APPS) < shell/glue.asm | tee $@ > /dev/null -shell/shell-bin.h: shell/shell.bin $(BIN2C) +shell/shell-bin.h: shell/shell.bin tools $(BIN2C) KERNEL < shell/shell.bin | tee $@ > /dev/null shell/shell: shell/shell.c $(SHELLOBJS) shell/shell-bin.h @@ -36,7 +36,7 @@ shell/shell: shell/shell.c $(SHELLOBJS) shell/shell-bin.h forth/forth0.bin: cat forth/boot.bin forth/z80c.bin > $@ -forth/forth0-bin.h: forth/forth0.bin $(BIN2C) +forth/forth0-bin.h: forth/forth0.bin tools $(BIN2C) KERNEL < forth/forth0.bin | tee $@ > /dev/null forth/stage1: forth/stage.c $(OBJS) forth/forth0-bin.h @@ -51,7 +51,7 @@ forth/core.bin: $(FORTHSRC_PATHS) forth/stage1 forth/forth1.bin: forth/forth0.bin forth/core.bin cat forth/forth0.bin forth/core.bin > $@ -forth/forth1-bin.h: forth/forth1.bin $(BIN2C) +forth/forth1-bin.h: forth/forth1.bin tools $(BIN2C) KERNEL < forth/forth1.bin | tee $@ > /dev/null forth/stage2: forth/stage.c $(OBJS) forth/forth1-bin.h @@ -60,10 +60,10 @@ forth/stage2: forth/stage.c $(OBJS) forth/forth1-bin.h forth/forth: forth/forth.c $(OBJS) forth/forth1-bin.h $(CC) forth/forth.c $(OBJS) -o $@ -zasm/kernel-bin.h: zasm/kernel.bin $(BIN2C) +zasm/kernel-bin.h: zasm/kernel.bin tools $(BIN2C) KERNEL < zasm/kernel.bin | tee $@ > /dev/null -zasm/zasm-bin.h: zasm/zasm.bin $(BIN2C) +zasm/zasm-bin.h: zasm/zasm.bin tools $(BIN2C) USERSPACE < zasm/zasm.bin | tee $@ > /dev/null $(ZASMBIN): zasm/zasm.c $(ZASMOBJS) zasm/kernel-bin.h zasm/zasm-bin.h @@ -72,7 +72,7 @@ $(ZASMBIN): zasm/zasm.c $(ZASMOBJS) zasm/kernel-bin.h zasm/zasm-bin.h zasm/avra.bin: $(ZASMBIN) $(ZASMBIN) $(KERNEL) $(APPS) zasm/user.h < $(APPS)/zasm/gluea.asm > $@ -zasm/avra-bin.h: zasm/avra.bin $(BIN2C) +zasm/avra-bin.h: zasm/avra.bin tools $(BIN2C) USERSPACE < zasm/avra.bin | tee $@ > /dev/null $(AVRABIN): zasm/zasm.c $(ZASMOBJS) zasm/kernel-bin.h zasm/avra-bin.h @@ -113,4 +113,4 @@ fbootstrap: forth/stage2 .PHONY: clean clean: rm -f $(TARGETS) $(SHELLTGTS) emul.o zasm/*-bin.h shell/*-bin.h - $(MAKE) -C ../tools/bin2c clean + $(MAKE) -C ../tools clean diff --git a/tools/Makefile b/tools/Makefile index dd5970b..b9c09fe 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -4,8 +4,9 @@ UPLOAD_TGT = upload FONTCOMPILE_TGT = fontcompile TTYSAFE_TGT = ttysafe PINGPONG_TGT = pingpong +BIN2C_TGT = bin2c TARGETS = $(MEMDUMP_TGT) $(BLKDUMP_TGT) $(UPLOAD_TGT) $(FONTCOMPILE_TGT) \ - $(TTYSAFE_TGT) $(PINGPONG_TGT) + $(TTYSAFE_TGT) $(PINGPONG_TGT) $(BIN2C_TGT) OBJS = common.o all: $(TARGETS) @@ -20,6 +21,7 @@ $(UPLOAD_TGT): $(UPLOAD_TGT).c $(FONTCOMPILE_TGT): $(FONTCOMPILE_TGT).c $(TTYSAFE_TGT): $(TTYSAFE_TGT).c $(PINGPONG_TGT): $(PINGPONG_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..603c25a --- /dev/null +++ b/tools/bin2c.c @@ -0,0 +1,49 @@ +/* + * 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 + +#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"); +} diff --git a/tools/bin2c/Makefile b/tools/bin2c/Makefile deleted file mode 100644 index 3d331f9..0000000 --- a/tools/bin2c/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -.PHONY: all clean - -all: bin2c - -bin2c: bin2c.o - $(CC) -o $@ $< - -%.o: %.c - $(CC) -c -o $@ $< - -clean: - rm -rf bin2c bin2c.o diff --git a/tools/bin2c/bin2c.c b/tools/bin2c/bin2c.c deleted file mode 100644 index 9f65167..0000000 --- a/tools/bin2c/bin2c.c +++ /dev/null @@ -1,33 +0,0 @@ -#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"); -} From e37f4c255197093b65b2bfb26824560fe614ac6a Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 7 Apr 2020 18:13:42 -0400 Subject: [PATCH 3/3] bin2c: add missing stdtypes.h --- tools/bin2c.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/bin2c.c b/tools/bin2c.c index 603c25a..93843b7 100644 --- a/tools/bin2c.c +++ b/tools/bin2c.c @@ -16,6 +16,7 @@ #include #include +#include #define BUFSZ 32 @@ -25,7 +26,7 @@ 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;