joeylib2/scripts/run-atarist-headless.sh
2026-09-24 22:01:56 -05:00

83 lines
2.8 KiB
Bash
Executable file

#!/usr/bin/env bash
# run-atarist-headless.sh - Run one built Atari ST example under Hatari
# with no window, wait, then hand back its joeylog.txt and a screenshot.
#
# The ST twin of run-amiga-headless.sh, and for the same reason:
# bench-atarist.sh runs UBER and waits for its "press any key to exit"
# line, which a game never prints.
#
# Hatari mounts the program's directory as GEMDOS drive C, so the app's
# joeylog.txt lands there and can be read off the host while it runs.
#
# Usage: scripts/run-atarist-headless.sh [example] [seconds]
# example PRG base name in build/atarist/bin, default STAXI
# seconds how long to let it run, default 90
# Env: ST_SOUND=on keep the YM running (default off, it is faster)
# ST_MEMSIZE=n machine RAM in MB, passed to Hatari. Default is
# Hatari's own; 1 is a stock 1040 ST.
# Requires: hatari, Xvfb, toolchains/emulators/support/emutos-512k.img
set -euo pipefail
prog=${1:-STAXI}
seconds=${2:-90}
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
binDir=$repo/build/atarist/bin
tos=$repo/toolchains/emulators/support/emutos-512k.img
outDir=${ST_OUT_DIR:-$repo/build/atarist/headless}
# Most examples are a bare PRG in bin/; Space Taxi ships as its own
# folder holding the PRG and its DATA tree.
if [ -d "$binDir/$prog" ]; then
driveDir=$binDir/$prog
else
driveDir=$binDir
fi
[ -f "$driveDir/$prog.PRG" ] || { echo "run-atarist-headless: $driveDir/$prog.PRG not built" >&2; exit 2; }
[ -f "$tos" ] || { echo "run-atarist-headless: missing $tos" >&2; exit 2; }
mkdir -p "$outDir"
rm -f "$driveDir/joeylog.txt"
display=:$((90 + RANDOM % 9))
Xvfb "$display" -screen 0 800x600x24 -nolisten tcp >/dev/null 2>&1 &
xvfbPid=$!
sleep 1
DISPLAY=$display hatari \
--tos "$tos" \
--harddrive "$driveDir" \
--gemdos-drive C \
--drive-a off --drive-b off \
--sound "${ST_SOUND:-off}" \
${ST_MEMSIZE:+--memsize "$ST_MEMSIZE"} \
--fast-forward on \
--auto "C:\\$prog.PRG" > "$outDir/$prog-hatari.log" 2>&1 &
hatPid=$!
cleanup() {
kill "$hatPid" 2>/dev/null || true
kill "$xvfbPid" 2>/dev/null || true
wait 2>/dev/null || true
}
trap cleanup EXIT
echo "run-atarist-headless: $prog for ${seconds}s..." >&2
elapsed=0
while [ "$elapsed" -lt "$seconds" ]; do
sleep 5
elapsed=$((elapsed + 5))
kill -0 "$hatPid" 2>/dev/null || { echo "run-atarist-headless: Hatari exited early" >&2; break; }
done
DISPLAY=$display import -window root "$outDir/$prog.png" 2>/dev/null || true
cp "$driveDir/joeylog.txt" "$outDir/$prog-joeylog.txt" 2>/dev/null || true
cleanup
trap - EXIT
echo "run-atarist-headless: wrote $outDir/$prog.png"
if [ -f "$outDir/$prog-joeylog.txt" ]; then
echo "--- joeylog.txt (last 25 lines)"
tail -25 "$outDir/$prog-joeylog.txt"
else
echo "run-atarist-headless: NO joeylog.txt -- the example never logged anything" >&2
fi