#!/usr/bin/env bash # runViaFinder.sh — boot real GS/OS 6.0.2 in MAME, drive Finder via # Lua keyboard automation to launch a user OMF, sample memory at # specific frames to verify the program executed. # # Usage: runViaFinder.sh --check =... # The OMF file is injected as /SYSTEM.DISK/HELLO (top-level on the # boot disk). Lua then waits for Finder, types S+Cmd-O to open the # System.Disk volume window, then H+Cmd-O to launch HELLO. # # Memory checks happen at frame 5400 (~90s emulated, well after the # launch path completes) and exit 0 / 1 depending on whether each # requested address holds the requested value. # # Requires: # - tools/gsos/sys602.po (GS/OS 6.0.2 boot disk) # - /tmp/cadius/cadius (forked-file-aware ProDOS tool) # - mame apple2gs in PATH set -euo pipefail OMF="$1" shift [ -f "$OMF" ] || { echo "missing: $OMF" >&2; exit 2; } [ "${1:-}" = "--check" ] || { echo "usage: $0 --check =..." >&2; exit 2; } shift PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" CADIUS=${CADIUS:-/tmp/cadius/cadius} SYSDISK=${SYSDISK:-$PROJECT_ROOT/tools/gsos/sys602.po} [ -x "$CADIUS" ] || { echo "cadius not found at $CADIUS" >&2; exit 2; } [ -f "$SYSDISK" ] || { echo "sysdisk not found at $SYSDISK" >&2; exit 2; } WORK=$(mktemp -d -t finderlaunch.XXXXXX) trap 'rm -rf "$WORK"' EXIT cp "$SYSDISK" "$WORK/disk.po" cp "$OMF" "$WORK/HELLO#B30000" "$CADIUS" ADDFILE "$WORK/disk.po" /SYSTEM.DISK "$WORK/HELLO#B30000" >/dev/null LUA_CHECKS="" EXPECTS=() for pair in "$@"; do [ "$pair" = "--check" ] && continue addr="${pair%=*}"; val="${pair#*=}" EXPECTS+=("$pair") LUA_CHECKS="$LUA_CHECKS print(string.format('MAME-READ %s=%02x', '$addr', mem:read_u8($addr)))"$'\n' done cat > "$WORK/finder.lua" <= steps[idx][1] do steps[idx][2]() idx = idx + 1 end end) LUA OUT=$(timeout 130 mame apple2gs -rompath "$PROJECT_ROOT/tools/mame/roms" \ -window -nothrottle -sound none \ -seconds_to_run 110 -flop3 "$WORK/disk.po" \ -autoboot_script "$WORK/finder.lua" &1) # Verify each expected value. fail=0 for pair in "${EXPECTS[@]}"; do addr="${pair%=*}"; want="${pair#*=}" line=$(echo "$OUT" | grep "MAME-READ $addr=" | tail -1) got=$(echo "$line" | sed -E 's/.*=([0-9a-f]+).*/\1/') # Compare numerically (handles case differences and 0x prefix variants). gotN=$(printf '%d' "0x$got" 2>/dev/null || echo -1) wantN=$(printf '%d' "$want" 2>/dev/null || echo -2) if [ "$gotN" = "$wantN" ]; then echo " $addr = 0x$got (want $want) ✓" else echo " $addr = 0x$got (want $want) ✗" fail=1 fi done exit $fail