Browse Source

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.
pull/95/head
Byron A. Grobe 4 years ago
parent
commit
f65c189e9b
No known key found for this signature in database GPG Key ID: A031592157C3D920
4 changed files with 63 additions and 18 deletions
  1. +18
    -13
      emul/Makefile
  2. +0
    -5
      emul/bin2c.sh
  3. +12
    -0
      tools/bin2c/Makefile
  4. +33
    -0
      tools/bin2c/bin2c.c

+ 18
- 13
emul/Makefile View File

@@ -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

+ 0
- 5
emul/bin2c.sh View File

@@ -1,5 +0,0 @@
#!/bin/sh

echo "unsigned char $1[] = { "
xxd -i -
echo " };"

+ 12
- 0
tools/bin2c/Makefile View File

@@ -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

+ 33
- 0
tools/bin2c/bin2c.c View File

@@ -0,0 +1,33 @@
#include <stdio.h>
#include <stdlib.h>

#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");
}

Loading…
Cancel
Save