joeylib2/scripts/verify-dvx-tilebank.sh
2026-10-19 15:46:47 -05:00

87 lines
3.2 KiB
Bash
Executable file

#!/usr/bin/env bash
# Part of JoeyLib, Copyright (c) 2026 Scott Duensing, under the MIT License.
# See LICENSE.md for license information.
# SPDX-License-Identifier: MIT
#
# verify-dvx-tilebank.sh - Tile-bank gate for DVX: proves the DVX port loads
# the DOS bake (chunky 4bpp, high nibble = left pixel -- DVX shows the DOS
# stage and takes the DOS target byte) through the run-time DATA root beside
# the program, and refuses a bank baked for any other target.
#
# Runs TILEBANK (examples/tilebank) as the desktop of a scratch DVX in DOSBox
# Staging, with the DATA/tilebank make/dvx.mk staged beside it from the host
# gate's fixture. The program loads its 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 its joeylog.txt (in its user folder) 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-dvx-tilebank.sh
# Env: TILEBANK_DATA_DIR stage this DATA/tilebank instead (negative controls)
# Requires: DOSBox Staging, Xvfb, a host cc, the dvx component; the tilebank
# program and its DATA/tilebank (make dvx).
set -uo pipefail
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
source "$repo/scripts/lib/joeyEnv.sh"
source "$repo/scripts/lib/tileBankGate.sh"
source "$repo/scripts/lib/dvxGate.sh"
joeyNeed DOSBOX dosbox
joeyNeed DVX_ROOT dvx
program=tilebank
programDir=$(dvxAppDir "$program")
dataDir=$(tileBankData "$programDir")
wall=150 # hard cap on DOSBox, whatever happens to this script
lineSeconds=120 # DVX boot plus the checks
tileBankNeedBuild "$programDir/$program.app" "$dataDir" "make dvx"
tileBankReference
work=$(mktemp -d -t joeylib-dvx-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
dvxStage "$work/c" "$(dvxAppDir "$program")"
staged=$work/c/DVX/apps/$DVX_VENDOR/$program/DATA/tilebank
rm -rf "$staged"
mkdir -p "$(dirname "$staged")"
cp -r "$dataDir" "$staged"
dvxDosboxConf "$work/dosbox.conf" "$work/c"
mkdir -p "$work/xdg"
display=":$((RANDOM % 400 + 2100))"
Xvfb "$display" -screen 0 1024x768x24 -nolisten tcp > /dev/null 2>&1 &
xvfb=$!
sleep 1
XDG_CONFIG_HOME="$work/xdg" DISPLAY="$display" SDL_AUDIODRIVER=dummy \
timeout -s KILL "$wall" "$DOSBOX" "${JOEY_DOSBOX_ISOLATE[@]}" \
--conf "$work/dosbox.conf" > "$work/dosbox.log" 2>&1 &
guard=$!
dosbox=$(joeyChild "$guard")
log=$(dvxAwaitLog "$work/c" "$program" '^TILEBANK: ' "$lineSeconds" "$guard")
if [ -z "$log" ]; then
joeyStop "$dosbox" "$guard" 2> /dev/null
dosbox=""
guard=""
echo "verify-dvx-tilebank: FAIL - no TILEBANK line within ${lineSeconds}s (DVX.LOG follows)" >&2
dvxDvxLog "$work/c" >&2
exit 1
fi
# Judged from a copy: the emulator is stopped first, as the other gates do.
cp "$log" "$work/joeylog.txt"
joeyStop "$dosbox" "$guard" 2> /dev/null
dosbox=""
guard=""
tileBankJudge "$work/joeylog.txt"