joeylib2/scripts/run-x68000.sh
2026-09-17 17:46:47 -05:00

87 lines
3.9 KiB
Bash
Executable file

#!/usr/bin/env bash
# run-x68000.sh - launch a built X68000 example under MAME.
#
# scripts/run-x68000.sh staxi Space Taxi (binary + its DATA tree)
# scripts/run-x68000.sh uber any other built example, by name
# X68K_HEADLESS=1 scripts/run-x68000.sh staxi windowless + snapshots
#
# TWO FLOPPIES, the same split verify-x68000-golden.sh uses: Human68k plus
# AUTOEXEC on A:, and the program with its assets on B:. A 1232 KB floppy
# cannot hold Human68k and a ~285 KB .X together, and AUTOEXEC switches to
# B: first so the program's CWD is the disk its DATA/ tree is on.
#
# Needs toolchains/x68mame (HUMAN302.XDF + roms/) -- see the X68000 memory
# note for where to copy it from.
set -euo pipefail
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
prog=${1:-staxi}
PROG=$(echo "$prog" | tr '[:lower:]' '[:upper:]')
bin=$repo/build/x68000/bin/$PROG.X
x68=${X68K_DIR:-$repo/toolchains/x68mame}
template=$x68/HUMAN302.XDF
# MAME: the x68k build this repo carries, unless one is installed or named.
MAME="${MAME:-$repo/toolchains/cache/mame-mame0264/x68k}"
if [[ ! -x $MAME ]]; then
MAME="$(command -v mame || true)"
fi
[[ -n ${MAME:-} && -x $MAME ]] || { echo "run-x68000: no MAME (set MAME=...)" >&2; exit 2; }
[[ -f $bin ]] || { echo "run-x68000: $bin not built (make -f make/x68000.mk)" >&2; exit 2; }
[[ -f $template ]] || { echo "run-x68000: missing $template (copy toolchains/x68mame in)" >&2; exit 2; }
work=$(mktemp -d -t joey-x68run.XXXXXX)
trap 'rm -rf "$work"' EXIT
printf 'B:\r\nB:\\%s.X\r\n\x1a' "$PROG" > "$work/AUTOEXEC.BAT"
cp "$template" "$work/boot.xdf"
cp "$template" "$work/data.xdf"
# Data disk = the template emptied (keeps the BPB and boot sector intact).
# `empty` and not a list of filenames: the stock disk carries ~900 KB of
# Human68k utilities in SUBDIRECTORIES (SYS, BIN, BASIC2, ...), and deleting
# only the root files leaves every one of those clusters allocated -- which is
# what made a 1232 KB floppy look like it had 330 KB to give.
python3 "$repo/tools/xdftool.py" empty "$work/data.xdf" >/dev/null
# Boot disk keeps only what it takes to boot and launch one .X.
for f in USKCG.SYS BEEP.SYS KEY.SYS STARTUP.ENV; do
python3 "$repo/tools/xdftool.py" delete "$work/boot.xdf" "$f" >/dev/null 2>&1 || true
done
for d in SYS HIS BIN BASIC2 ASK ETC; do
python3 "$repo/tools/xdftool.py" deltree "$work/boot.xdf" "$d" >/dev/null 2>&1 || true
done
python3 "$repo/tools/xdftool.py" add "$work/boot.xdf" "$work/AUTOEXEC.BAT" AUTOEXEC.BAT >/dev/null
python3 "$repo/tools/xdftool.py" add "$work/data.xdf" "$bin" "$PROG.X" >/dev/null
# The example's DATA tree, if it has one, at the same paths jlDataOpen builds
# ("DATA/" + the app's relative name). Human68k names are 8.3 upper case.
data_dir=$repo/build/x68000/bin/DATA
if [[ -d $data_dir ]]; then
while IFS= read -r f; do
rel=${f#"$data_dir"/}
python3 "$repo/tools/xdftool.py" add "$work/data.xdf" "$f" \
"DATA/$(echo "$rel" | tr '[:lower:]' '[:upper:]')" >/dev/null
done < <(find "$data_dir" -type f | sort)
fi
echo "run-x68000: $(python3 "$repo/tools/xdftool.py" free "$work/data.xdf")"
if [[ ${X68K_HEADLESS:-0} == 1 ]]; then
snap=${X68K_SNAP:-/tmp/run-x68000-snap}
rm -rf "$snap"; mkdir -p "$snap"
cat > "$work/snap.lua" <<'LUA'
local n = 0
emu.register_frame_done(function()
n = n + 1
if n % 1200 == 0 then manager.machine.video:snapshot() end
if n >= 24000 then manager.machine:exit() end
end)
LUA
"$MAME" x68000 -bios ipl10 -rompath "$x68/roms" \
-flop1 "$work/boot.xdf" -flop2 "$work/data.xdf" \
-video none -sound none -nothrottle \
-snapshot_directory "$snap" -autoboot_script "$work/snap.lua" </dev/null >/dev/null 2>&1 || true
echo "run-x68000: snapshots -> $snap"
else
echo "run-x68000: booting Human68k, then B:\\$PROG.X. Quit MAME to end."
"$MAME" x68000 -bios ipl10 -rompath "$x68/roms" \
-flop1 "$work/boot.xdf" -flop2 "$work/data.xdf" -skip_gameinfo
fi