joeylib2/scripts/verify-ste-machine.sh
2026-10-13 14:01:46 -05:00

85 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-ste-machine.sh - Which Atari build runs where.
#
# The ST port builds twice. The ST build (make atarist) is pure 68000 and
# must run on every ST, an STe included. The STe build (make ste) uses the
# BLiTTER, DMA sound and the 4-bit palette without asking, so its jlInit
# must refuse every other machine -- with a reason in jlLastError, not a
# crash -- and run on an STe and a Mega STe.
#
# Subject: HELLO, which prints jlPlatformName after jlInit, or "jlInit
# failed: " and jlLastError when it fails. Hatari's --conout 2 copies the
# TOS console to its own output, so the gate reads what the program said:
#
# STe build on a plain ST refused, with the STe build's reason
# STe build on a Mega ST refused (a BLiTTER, but no DMA sound)
# STe build on an STe "Platform: Atari STe"
# STe build on a Mega STe "Platform: Atari STe"
# ST build on an STe "Platform: Atari ST" (the ST build runs anywhere)
#
# Usage: scripts/verify-ste-machine.sh
# Requires: ./install.sh install emulator:atarist (Hatari, EmuTOS),
# HELLO.PRG in build/atarist/bin and build/ste/bin (make atarist,
# make ste)
set -uo pipefail
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
source "$repo/scripts/lib/joeyEnv.sh"
joeyNeed HATARI hatari
joeyNeed EMUTOS_IMG emutos
wall=60 # hard cap on Hatari, whatever happens to this script
runVbls=900 # EmuTOS boot + HELLO's lines: ~500 frames
refused='jlInit failed: this is the STe build'
work=$(mktemp -d -t joeylib-ste-machine.XXXXXX)
trap 'rm -rf "$work"' EXIT
fails=0
# build machine expected-line
while read -r build machine expect; do
prog=$repo/build/$build/bin/HELLO.PRG
[ -f "$prog" ] || { echo "verify-ste-machine: missing $prog (run 'make $build')" >&2; exit 2; }
rm -rf "$work/c"
mkdir -p "$work/c"
cp "$prog" "$work/c/"
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy timeout -s KILL "$wall" "$HATARI" \
--machine "$machine" \
--tos "$EMUTOS_IMG" \
--harddrive "$work/c" \
--gemdos-drive C \
--drive-a off --drive-b off \
--sound off \
--fast-forward on \
--run-vbls "$runVbls" \
--conout 2 \
--auto 'C:\HELLO.PRG' > "$work/out.txt" 2>&1
case $expect in
refused) want=$refused ;;
ste) want='Platform: Atari STe' ;;
st) want='Platform: Atari ST$' ;;
esac
said=$(grep -a -E 'jlInit failed|Platform:' "$work/out.txt" | tr -d '\r' | head -1)
if printf '%s\n' "$said" | grep -q -E "^$want"; then
echo "verify-ste-machine: $build build on $machine: $said"
else
echo "verify-ste-machine: FAIL - $build build on $machine said '${said:-nothing}', want '$want'" >&2
fails=$((fails + 1))
fi
done <<EOF
ste st refused
ste megast refused
ste ste ste
ste megaste ste
atarist ste st
EOF
if [ "$fails" -gt 0 ]; then
echo "verify-ste-machine: FAIL" >&2
exit 1
fi
echo "verify-ste-machine: PASS"