diff options
author | Bobby Bingham <koorogi@koorogi.info> | 2015-09-12 14:11:23 -0500 |
---|---|---|
committer | Bobby Bingham <koorogi@koorogi.info> | 2015-09-15 22:43:32 -0500 |
commit | f39b2b31fc8a604d7a3972cd15473bc8cab28684 (patch) | |
tree | 0480b2ca50965fb5c3c4863ff275850e4196a994 /tools |
tool to create saturn boot sector
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/bin2c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/bin2c b/tools/bin2c new file mode 100755 index 0000000..25bb6f7 --- /dev/null +++ b/tools/bin2c @@ -0,0 +1,35 @@ +#! /bin/sh + +readbyte() +{ + read dummy hex << EOF + $(dd bs=1 count=1 2> /dev/null | od -t xC) +EOF + printf "%s\n" $hex +} + +if [ $# -ne 1 ] ; then + echo "usage: $0 in.bin > out.c" + exit +fi + +varname=$(basename $1 .bin | tr -d "\n" | tr -c a-zA-Z _) +length=0 + +exec < $1 +printf "#include <stddef.h>\n" +printf "const unsigned char %s[] = {" $varname + +byte=$(readbyte) +until [ -z $byte ] ; do + [ $(($length % 12)) -eq 0 ] && printf "\n\t" + printf "0x%s," $byte + let length+=1 + + byte=$(readbyte) +done + +[ $length -ne 0 ] && printf "\n" +printf "};\n" + +printf "const size_t %s_size = %s;\n" $varname $length |