joeylib2/scripts/verify-dos-tilebank.sh
2026-09-29 19:31:34 -05:00

75 lines
2.8 KiB
Bash
Executable file

#!/usr/bin/env bash
# verify-dos-tilebank.sh - Tile-bank gate for DOS: proves that assetbake's
# dos encoder (chunky 4bpp, high nibble = left pixel) writes exactly the
# layout the DOS tile paste reads, and that the DOS build refuses a bank baked
# for any other target.
#
# Runs TILEBANK.EXE (examples/tilebank) in DOSBox Staging on the 386SX-16
# reference config, from a scratch C: holding it and the DATA/tilebank
# make/dos.mk staged from the host gate's fixture. The program loads its own
# bake through jlTileBankLoadToSurface and through jlTileBankLoad +
# jlTilePaste, checks every pixel of both against the PNG, hashes both, and
# tries every other target's bake; its TILEBANK line in JOEYLOG.TXT must say
# PASS with both hashes equal to the host gate's (scripts/check-tilebank.sh,
# run here for the value) and every other target refused. DOSBox is stopped
# as soon as the line appears.
#
# Usage: scripts/verify-dos-tilebank.sh
# Env: TILEBANK_DATA_DIR stage this DATA/tilebank instead (negative controls)
# Requires: DOSBox Staging, Xvfb, a host cc; build/dos/bin/TILEBANK.EXE and
# its DATA/tilebank (make dos).
set -uo pipefail
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
source "$repo/scripts/lib/joeyEnv.sh"
source "$repo/scripts/lib/tileBankGate.sh"
joeyNeed DOSBOX dosbox
binDir=$repo/build/dos/bin
dataDir=$(tileBankData "$binDir")
conf=$repo/scripts/dosbox-386sx16.conf
wall=150 # hard cap on DOSBox, whatever happens to this script
lineSeconds=120 # DOS boot plus the checks at 386SX-16 speed
tileBankNeedBuild "$binDir/TILEBANK.EXE" "$dataDir" "make dos"
tileBankReference
work=$(mktemp -d -t joeylib-dos-tilebank.XXXXXX)
guard=""
dosbox=""
xvfb=""
# 2>/dev/null: bash reports the SIGKILLed timeout wrapper as "Killed".
cleanup() {
joeyStop "$dosbox" "$guard" "$xvfb" 2> /dev/null
rm -rf "$work"
}
trap cleanup EXIT
mkdir -p "$work/c/DATA" "$work/xdg"
cp "$binDir/TILEBANK.EXE" "$work/c/"
cp -r "$dataDir" "$work/c/DATA/tilebank"
display=":$((RANDOM % 400 + 1300))"
Xvfb "$display" -screen 0 800x600x24 -nolisten tcp > /dev/null 2>&1 &
xvfb=$!
sleep 1
# The mount is an explicit -c: DOSBox runs every -c line before it would
# auto-mount a trailing directory (see bench-dos.sh).
XDG_CONFIG_HOME="$work/xdg" DISPLAY="$display" SDL_AUDIODRIVER=dummy \
timeout -s KILL "$wall" "$DOSBOX" "${JOEY_DOSBOX_ISOLATE[@]}" \
--conf "$conf" \
-c "MOUNT C \"$work/c\"" -c "C:" -c "TILEBANK.EXE" > "$work/dosbox.log" 2>&1 &
guard=$!
dosbox=$(joeyChild "$guard")
log=$(tileBankAwaitLine "$work/c" "$lineSeconds" "$guard")
joeyStop "$dosbox" "$guard" 2> /dev/null
dosbox=""
guard=""
if [ -z "$log" ]; then
echo "verify-dos-tilebank: FAIL - no TILEBANK line within ${lineSeconds}s" >&2
tail -5 "$work/dosbox.log" >&2
exit 1
fi
tileBankJudge "$log"