Files
vt1200/dwt/visual/build.sh
T

79 lines
2.4 KiB
Bash
Executable File

#!/bin/sh
# Build a VT1200 payload with the 1987 TI TMS34010 SDK (GSPA/GSPLNK under
# DOSBox), the same flow as harness/hello-world/build.sh.
#
# dwt/visual/build.sh SOURCE.asm [ORIGIN_BITS]
#
# Outputs dwt/visual/build/<name>.bin (linked bytes) and <name>.map.
# Nothing outside dwt/visual/ is written.
set -eu
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
DIR=$(cd "$(dirname "$0")" && pwd)
SRC=${1:?usage: build.sh SOURCE.asm [ORIGIN_BITS]}
ORIGIN=${2:-01800000}
NAME=$(basename "$SRC" .asm)
# DOS's 8.3 filesystem uppercases names; the tools write <NAME>.OUT etc.
BASE=$(printf '%s' "$NAME" | tr 'a-z' 'A-Z')
WORK="$DIR/work"
OUT="$DIR/build"
IMG="$ROOT/tools/tms34010-sdk/1987-05 TMS34010 SDK/1987-11-06 TMS34010 Simulator-C Tools-ASM Tools.img"
DOSBOX_CONF="$ROOT/harness/sdk-scratch/dosbox-bench.conf"
mkdir -p "$WORK" "$OUT"
if [ ! -x "$WORK/GSPA.EXE" ]; then
mcopy -s -n -i "$IMG" "::/A2/*" "$WORK/"
mcopy -s -n -i "$IMG" "::/C2/*" "$WORK/"
fi
cp "$SRC" "$WORK/$BASE.ASM"
# TI hex constants must begin with a decimal digit.
case "$ORIGIN" in
[0-9]*) ;;
*) ORIGIN="0$ORIGIN" ;;
esac
printf '%s\n' \
'-a' \
"-o $BASE.out" \
"-m $BASE.map" \
"$BASE.obj" \
'SECTIONS' \
'{' \
" .text ${ORIGIN}h: {}" \
'}' > "$WORK/$BASE.CMD"
sed -i 's/$/\r/' "$WORK/$BASE.CMD"
rm -f "$WORK/$BASE.OBJ" "$WORK/$BASE.OUT" "$WORK/$BASE.LST" \
"$WORK/$BASE.MAP" "$WORK/$BASE.HI" "$WORK/$BASE.LO"
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
timeout 180 dosbox -conf "$DOSBOX_CONF" -noprimaryconf -nolocalconf \
-c "mount c $WORK" -c "c:" \
-c "gspa $BASE $BASE.obj $BASE.lst -l" \
-c "gsplnk $BASE.cmd" \
-c "exit" -exit >/dev/null 2>&1
if [ ! -f "$WORK/$BASE.OUT" ]; then
echo "build.sh: GSPLNK produced no $BASE.OUT" >&2
exit 1
fi
if [ ! -f "$WORK/$BASE.OBJ" ]; then
echo "build.sh: GSPA produced no $BASE.OBJ" >&2
grep -n '\*\*\*\*\*' "$WORK/$BASE.LST" >&2 || true
exit 1
fi
if grep -q '\*\*\*\*\*' "$WORK/$BASE.LST"; then
echo "build.sh: assembler diagnostics:" >&2
grep -n '\*\*\*\*\*' "$WORK/$BASE.LST" >&2
exit 1
fi
python3 "$ROOT/harness/hello-world/cofextract.py" "$WORK/$BASE.OUT" "$OUT/$NAME.bin"
sed 's/\r$//' "$WORK/$BASE.MAP" > "$OUT/$NAME.map"
# Keep the listing too: it is the assembler's own record, addresses in bits.
cp "$WORK/$BASE.LST" "$OUT/$NAME.lst"
echo "build.sh: $OUT/$NAME.bin ($(wc -c < "$OUT/$NAME.bin") bytes) at bit $ORIGIN"