#!/usr/bin/env bash # Launch the built Apple IIgs examples in GSplus. GSplus is booted from # a GS/OS 6.0.4 System disk (toolchains/emulators/support/gsos-system.po) # with joey.2mg mounted as the data disk on slot 5 drive 2. The user # navigates to the JOEYLIB volume in Finder and double-clicks the # example to run it. # # Unlike the other emulators, GS/OS does not auto-run on boot -- it # drops to Finder. The argument just prints a reminder of which # example to launch. # # scripts/run-iigs.sh # boots (Pattern hint) # scripts/run-iigs.sh hello # boots, hints HELLO # scripts/run-iigs.sh draw # boots, hints DRAW # # Argument is any built example name (case-insensitive); upper-case # it for the Finder hint and existence-check. set -euo pipefail if [[ $# -gt 1 ]]; then echo "usage: $0 [example-name]" >&2 exit 2 fi prog=${1:-pattern} repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) # profuse looks up its FST helpers under $GOLDEN_GATE / $ORCA_ROOT and # falls back to /usr/share/orca which we don't install. Point both at # our staged GoldenGate tree. export GOLDEN_GATE="$repo/toolchains/iigs/goldengate" export ORCA_ROOT="$GOLDEN_GATE" gsplus=$repo/toolchains/emulators/gsplus/bin/gsplus rom=$repo/toolchains/emulators/support/apple-iigs.rom sys_disk=$repo/toolchains/emulators/support/gsos-system.po data_disk=$repo/build/iigs/bin/joey.2mg null_c600=$repo/toolchains/emulators/support/iigs-null-c600.rom target=${prog^^} bin_dir=$repo/build/iigs/bin if [[ ! -f "$bin_dir/$target" ]]; then echo "$bin_dir/$target not built. Run 'make iigs' first." >&2 if compgen -G "$bin_dir/*" > /dev/null; then echo "available examples in $bin_dir:" >&2 find "$bin_dir" -maxdepth 1 -type f -printf '%f\n' \ | grep -vE '\.2mg$|\.txt$' >&2 || true fi exit 1 fi for f in "$gsplus" "$rom" "$sys_disk" "$data_disk" "$null_c600"; do if [[ ! -f $f ]]; then echo "missing: $f" >&2 if [[ $f == "$data_disk" ]]; then echo "run 'make iigs-disk' to build it." >&2 else echo "run ./toolchains/install.sh (support files should have been staged)." >&2 fi exit 1 fi done # GSplus writes back to disk images during the session; stage writable # copies so repeated runs do not mutate the originals. work=$(mktemp -d -t joeylib-iigs.XXXXXX) # After GSplus exits, mount the work copy of joey.2mg via profuse and # pull joeylog.txt out (if the demo wrote one) before tearing down the # scratch dir. This is a debug aid: the demos use joeyLog* to leave a # breadcrumb file on the JOEYLIB volume, but the volume only lives # inside the scratch dir while GSplus is running. log_out=$repo/build/iigs/bin/joeylog.txt extract_log() { local profuse=$repo/toolchains/iigs/gg-tools/bin/profuse local mnt=$work/_log_mnt # Stash the post-run disk image for manual inspection. if [[ -f $work/joey.2mg ]]; then cp "$work/joey.2mg" "$repo/build/iigs/bin/joey-after-run.2mg" echo "run-iigs: saved post-run disk -> $repo/build/iigs/bin/joey-after-run.2mg" >&2 fi if [[ ! -x $profuse ]]; then echo "run-iigs: profuse not found at $profuse" >&2 elif [[ ! -f $work/joey.2mg ]]; then echo "run-iigs: $work/joey.2mg missing" >&2 else mkdir -p "$mnt" if "$profuse" -oro "$work/joey.2mg" "$mnt"; then echo "run-iigs: mounted $mnt; contents:" >&2 ls -la "$mnt" >&2 || true if [[ -f $mnt/JOEYLOG.TXT ]]; then cp "$mnt/JOEYLOG.TXT" "$log_out" echo "run-iigs: extracted joeylog.txt -> $log_out" >&2 elif [[ -f $mnt/joeylog.txt ]]; then cp "$mnt/joeylog.txt" "$log_out" echo "run-iigs: extracted joeylog.txt -> $log_out" >&2 else echo "run-iigs: no JOEYLOG.TXT on disk" >&2 fi fusermount -u "$mnt" 2>/dev/null || true else echo "run-iigs: profuse mount FAILED" >&2 fi fi rm -rf "$work" } trap extract_log EXIT cp "$sys_disk" "$work/boot.po" cp "$data_disk" "$work/joey.2mg" # Stage the null slot-6 PROM as c600.rom in the work dir. GSplus loads # any file named c600.rom in its search path (cwd first) as the slot 6 # ROM card, overriding the built-in Disk II firmware. The staged image # is 256 bytes with a leading RTS and no Pascal 1.1 firmware signature, # so the IIgs boot ROM's slot scan skips slot 6 and the two empty 5.25 # drives never get probed. Source: toolchains/install.sh's # install_support_iigs_null_c600. cp "$null_c600" "$work/c600.rom" cat < # ". g_limit_speed=2 caps emulation at the IIgs's native # 2.8 MHz; without this override GSplus boots at 8 MHz and our # performance characteristics don't match real hardware. The other # settings (0=unlimited, 1=1.024 MHz, 3=8 MHz) are reachable through # the in-emulator speed-cycle key if needed. # # No exec: let the bash EXIT trap fire so the scratch dir (and the # config.kegs GSplus auto-creates) gets cleaned up. "$gsplus" -rom "$rom" \ -s5d1 "$work/boot.po" \ -s5d2 "$work/joey.2mg" \ -g_limit_speed 2