Files
vt1200/harness/mame/run.sh
T

160 lines
7.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# run.sh -- launch the VT1200 MAME harness.
#
# ./run.sh faithful boot: POST, then fails level 0's I/O data path
# test (nothing attached) -> diagnostics menu
# ./run.sh skip skip ALL 15 level-1 tests (DUART1 IP3 high) -> OS
# ./run.sh pie runtime-patch the failing checks -> level 1 RUNS (pie graph)
# ./run.sh headless [N] no window; dump frame N (default 600) into this directory
# ./run.sh stub faithful, plus an opt-in stand-in for the level-0
# keyboard-port test fixture -> reaches level 1
# ./run.sh net skip + tablet + the LANCE attached to a host tap
# (networkprovider taptun): the crash-work configuration
# ./run.sh mouse skip + VSXXX-AA mouse: the *faithful* pointing device.
# The tablet is the default; this sets VT1200_MOUSE=1
# ./run.sh <mode> -- <extra MAME options>
#
# Reboot the running machine with Shift+F3 (MAME's UI_RESET_MACHINE; plain F3 is a
# *machine* key on other drivers, not this one). Tab opens MAME's menu. Esc quits.
#
# If the menu stops responding: press ScrollLock. That toggles MAME's UI controls
# on and off (UI_TOGGLE_UI, inpttype.ipp:910), and the LK401 keyboard has no
# ScrollLock key, so the emulated terminal ignores it. Closing the window is also a
# normal exit, and MAME writes NVRAM on exit -- which is where the terminal's TCP/IP
# settings live, so quit normally rather than killing it.
#
# No environment variables are needed for the faithful boot -- the working
# configuration is the default. This harness is a visibility tool, not an
# accurate VT1200 emulation, so read the caveats:
#
# skip drives a MODELLED BOARD INPUT (DUART1 IP3). The real machine reads IP3
# low, so a skipped run tells you about the OS, graphics and crash path --
# NOT about the real terminal's POST.
# pie patches the ROM image IN MEMORY at runtime. The on-disk ROM is never
# modified (hash it before and after if you like), but it is still a debug
# view: it shows which tests OUR MODEL fails, not what the hardware does.
# stub supplies ten bytes on the keyboard port so the level-0 I/O data path test
# passes, so the faithful boot reaches level 1 instead of stopping at level 0.
# It is NOT a keyboard model: that test checks only the byte *count* and never
# compares the content, so the bytes are arbitrary. It stands in for an
# unknown test fixture, and it is opt-in so the default stays honest.
# mouse forces the VSXXX-AA mouse (VT1200_MOUSE=1) -- the *faithful* pointing device,
# since the real terminal almost certainly has a mouse. The DEFAULT is the
# VSXXX-AB tablet: it is ABSOLUTE, so the host pointer position maps directly
# to where the cursor is rather than being integrated from deltas, and it does
# not grab the pointer. That default is a deliberate divergence -- see the
# divergences table in harness/mame/README.md.
#
# Modes other than 'headless' open a window at real speed, so you can watch.
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MAME="${MAME:-/home/arti/code/k-space/mame0289/vt1200}"
ROMPATH="$HERE/roms"
ROM="$ROMPATH/vt1200/vt1200_v22.bin"
if [ ! -x "$MAME" ]; then
echo "run.sh: no MAME binary at $MAME" >&2
echo " set MAME=/path/to/vt1200, or build it with ./build.sh" >&2
exit 1
fi
if [ ! -e "$ROM" ]; then
echo "run.sh: ROM not found at $ROM" >&2
exit 1
fi
MODE="${1:-faithful}"
if [ $# -gt 0 ]; then shift; fi
usage() { awk 'NR>1 && /^set -euo pipefail/{exit} NR>1{print}' "$0"; }
# common: correct rompath, no sound (the driver has no audio), no licence screen.
# The lightgun options give MAME an absolute host pointer, which the DEFAULT VSXXX-AB
# tablet needs and the VSXXX-AA mouse (VT1200_MOUSE=1) also uses to follow the host.
# They are harmless either way, and they do NOT grab the pointer.
COMMON=(-rompath "$ROMPATH" -sound none -skip_gameinfo -lightgun -lightgun_device mouse)
case "$MODE" in
faithful|"")
exec "$MAME" vt1200 "${COMMON[@]}" -window "$@"
;;
skip)
# IP3 high -> the boot gate at 3F2042D0 jumps to the OS cold-start,
# skipping all 15 level-1 tests. Also flips DUART1's IRQ to INT2, which
# is the routing the OS's DUART driver expects (POST uses INT1).
#
# DUART2 (keyboard/mouse) is modelled as well, and is REQUIRED for the OS:
# with it unmodelled the board write-back latch echoes the OS's IWR write
# when the OS reads DUART2's ISR (0x06200005), producing a phantom
# interrupt that can never clear -- the OS spins forever at the X11 weave.
# With it real, the Terminal Manager appears.
exec env VT1200_SKIP_LEVEL1=1 VT1200_DUART2=1 \
"$MAME" vt1200 "${COMMON[@]}" -window "$@"
;;
net)
# the crash-work configuration: skip + tablet (already the default) + the LANCE
# attached to a host tap.
#
# A private cfg directory keeps the harness's network choice out of your
# ~/.mame, but note it must PERSIST: MAME stores the provider PER DEVICE in
# cfg/<game>.cfg, and -networkprovider only says which module may be used --
# it does NOT choose an interface. With nothing saved, a network device
# defaults to "none" and no tap is ever opened (verified: an empty cfg dir
# produces no tap). So choose it ONCE via MAME's UI while running this mode:
# Tab -> Network Devices -> the LANCE -> taptun
# That selection is saved here and reused on every later `net` run.
CFGDIR="$HERE/cfg-net"
mkdir -p "$CFGDIR"
exec env VT1200_SKIP_LEVEL1=1 \
"$MAME" vt1200 "${COMMON[@]}" -cfg_directory "$CFGDIR" \
-networkprovider taptun -window "$@"
;;
mouse)
# force the faithful VSXXX-AA mouse. The tablet is the default (absolute
# pointing), so this is the opt-out. Both need the lightgun options in COMMON
# for the host pointer to reach them.
exec env VT1200_SKIP_LEVEL1=1 VT1200_MOUSE=1 \
"$MAME" vt1200 "${COMMON[@]}" -window "$@"
;;
pie)
# `-debug -debugger none` is required: l1patch.lua needs the debugger API.
exec env VT1200_L1PATCH=1 \
"$MAME" vt1200 "${COMMON[@]}" -window \
-debug -debugger none \
-autoboot_script "$HERE/l1patch.lua" -autoboot_delay 0 "$@"
;;
stub)
# opt-in stand-in for the unknown level-0 keyboard-port test fixture.
# NOT a keyboard model -- that test checks only the byte count and never
# the content. See reference/level0-10byte-puzzle.md.
exec env VT1200_IO_PATH_STUB=1 \
"$MAME" vt1200 "${COMMON[@]}" -window "$@"
;;
headless)
N="${1:-600}"
if [ $# -gt 0 ]; then shift; fi
# enough emulated seconds to reach frame N at ~72 Hz
SECS=$(( N / 72 + 5 ))
exec env VT1200_DUMP_FRAME="$N" VT1200_DUMP_DIR="$HERE" \
"$MAME" vt1200 "${COMMON[@]}" -video none -nothrottle \
-seconds_to_run "$SECS" "$@"
;;
-h|--help|help)
usage
;;
*)
echo "run.sh: unknown mode '$MODE'" >&2
echo " try: faithful | skip | pie | headless [N]" >&2
exit 2
;;
esac