joeylib2/scripts/verify-atarist-tilebank.sh
2026-09-29 17:23:29 -05:00

70 lines
2.6 KiB
Bash
Executable file

#!/usr/bin/env bash
# verify-atarist-tilebank.sh - Tile-bank gate for the Atari ST: proves that
# assetbake's atarist encoder (interleaved planes, 4 plane bytes per row)
# writes exactly the layout the ST's native tile paste (src/atarist/stTile.h)
# reads, and that the ST build refuses a bank baked for any other target.
#
# Runs TILEBANK.PRG (examples/tilebank) under Hatari from a scratch GEMDOS
# drive holding it and the DATA/tilebank make/atarist.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 log line 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. Hatari is stopped as soon as the line appears.
#
# Usage: scripts/verify-atarist-tilebank.sh
# Env: TILEBANK_DATA_DIR stage this DATA/tilebank instead (negative controls)
# Requires: hatari, EmuTOS, a host cc; build/atarist/bin/TILEBANK.PRG and its
# DATA/tilebank (make atarist).
set -uo pipefail
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
source "$repo/scripts/lib/joeyEnv.sh"
source "$repo/scripts/lib/tileBankGate.sh"
joeyNeed HATARI hatari
joeyNeed EMUTOS_IMG emutos
binDir=$repo/build/atarist/bin
dataDir=$(tileBankData "$binDir")
wall=150 # hard cap on Hatari, whatever happens to this script
lineSeconds=120 # boot plus the checks, fast-forwarded, take ~10 s
tileBankNeedBuild "$binDir/TILEBANK.PRG" "$dataDir" "make atarist"
tileBankReference
work=$(mktemp -d -t joeylib-st-tilebank.XXXXXX)
guard=""
hatari=""
# 2>/dev/null: bash reports the SIGKILLed timeout wrapper as "Killed".
cleanup() {
joeyStop "$hatari" "$guard" 2> /dev/null
rm -rf "$work"
}
trap cleanup EXIT
mkdir -p "$work/c/DATA"
cp "$binDir/TILEBANK.PRG" "$work/c/"
cp -r "$dataDir" "$work/c/DATA/tilebank"
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy timeout -s KILL "$wall" "$HATARI" \
--tos "$EMUTOS_IMG" \
--harddrive "$work/c" \
--gemdos-drive C \
--drive-a off --drive-b off \
--sound off \
--fast-forward on \
--auto 'C:\TILEBANK.PRG' > "$work/hatari.log" 2>&1 &
guard=$!
hatari=$(tileBankChild "$guard")
log=$(tileBankAwaitLine "$work/c" "$lineSeconds" "$guard")
joeyStop "$hatari" "$guard" 2> /dev/null
hatari=""
guard=""
if [ -z "$log" ]; then
echo "verify-atarist-tilebank: FAIL - no TILEBANK line within ${lineSeconds}s" >&2
tail -5 "$work/hatari.log" >&2
exit 1
fi
tileBankJudge "$log"