aboutsummaryrefslogtreecommitdiffstats
path: root/c/build.sh
diff options
context:
space:
mode:
Diffstat (limited to 'c/build.sh')
-rwxr-xr-xc/build.sh20
1 files changed, 20 insertions, 0 deletions
diff --git a/c/build.sh b/c/build.sh
new file mode 100755
index 0000000..6a2deab
--- /dev/null
+++ b/c/build.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+# Build a gbos C program into a self-contained 16 KiB ROM-bank image.
+# SDCC native toolchain; crt0 linked FIRST so _start is the $4000 entry.
+# usage: c/build.sh <prog.c> <out.bin>
+set -e
+SRC="$1"; OUT="$2"; B=build/c
+LIBDIR=/usr/share/sdcc/lib/sm83
+mkdir -p "$B"
+sdasgb -o "$B/crt0.rel" c/crt0.s
+sdasgb -o "$B/libc.rel" c/libc.s
+sdcc -msm83 -c -Ic "$SRC" -o "$B/prog.rel"
+# link: crt0 first (=> _start at 0x4000), then libc, program, and sm83 lib
+sdldgb -n -m -w -j -i "$B/prog.ihx" \
+ -b _CODE=0x4000 -b _DATA=0xa000 \
+ -k "$LIBDIR" -l sm83 \
+ "$B/crt0.rel" "$B/libc.rel" "$B/prog.rel"
+makebin -Z -p "$B/prog.ihx" "$B/prog.bin"
+dd if="$B/prog.bin" of="$OUT" bs=1024 skip=16 count=16 2>/dev/null
+echo "wrote $OUT ($(wc -c < "$OUT") bytes); entry:"
+grep -iE ' _start| _main' "$B/prog.map" | head -2