#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Ask MAME 0.285 what it knows about the GameCube: run its drivers briefly and report. MAME is a detector, never a judge (docs/mame-oracle.md, tier 5). This script runs, one process at a time, for a few emulated seconds each: - ``gcjp`` (nintendo/gamecube.cpp; ``gcus``, ``gceu``, ``gcbr`` are its clones): MAME's GameCube driver, a skeleton. The script records whether it starts at all. - ``triforce`` (sega/triforce.cpp): the arcade board built on GameCube hardware, also a skeleton, which does start. The script prints the program-space map MAME gives its CPU and the PC at reset and after 60 frames. No instruction is traced: the code running is the board's boot ROM (firmware), which is never traced, read or copied here. Romsets are read in place from ``$MAME_ROMPATH``. Output goes to tests/mame_runs/ (ignored); the summary printed at the end is what tests/detectors/ keeps. MAME_ROMPATH=... python -I scripts/mame_probe.py """ from __future__ import annotations import os import subprocess import sys import time from pathlib import Path ROOT = Path(__file__).resolve().parents[1] MAME = os.environ.get("MAME", "mame") # the MAME 0.285 binary; $MAME overrides PROBE = """local cpu = manager.machine.devices[":maincpu"] local space = cpu.spaces["program"] for _, e in ipairs(space.map.entries) do print(string.format("MAP %08X-%08X read=%s write=%s", e.address_start, e.address_end, tostring(e.read.handlertype), tostring(e.write.handlertype))) end print(string.format("RESET PC %08X", cpu.state["PC"].value)) frames = 0 sub = emu.add_machine_frame_notifier(function() frames = frames + 1 if frames >= 60 then print(string.format("AFTER %d frames PC %08X", frames, cpu.state["PC"].value)) manager.machine:exit() end end) """ def run(driver: str, out: Path) -> tuple[int, list[str]]: command = [ "nice", MAME, driver, "-rompath", os.environ["MAME_ROMPATH"], "-video", "none", "-sound", "none", "-nothrottle", "-noreadconfig", "-skip_gameinfo", "-autoboot_script", "probe.lua", "-seconds_to_run", "3", ] result = subprocess.run(command, cwd=out, capture_output=True, text=True, check=False, timeout=300) text = (result.stdout + result.stderr).splitlines() (out / f"{driver}.txt").write_text("\n".join(text) + "\n", encoding="utf-8") keep = [line for line in text if line.startswith(("MAP", "RESET", "AFTER", "Fatal"))] return result.returncode, keep def main() -> int: if not os.environ.get("MAME_ROMPATH"): print("set MAME_ROMPATH to the folder holding gcjp.zip and triforce.zip") return 2 out = ROOT / "tests" / "mame_runs" / time.strftime("probe-%Y%m%d-%H%M%S") out.mkdir(parents=True, exist_ok=False) (out / "probe.lua").write_text(PROBE, encoding="utf-8") for driver in ("gcjp", "triforce"): code, lines = run(driver, out) print(f"== {driver}: exit {code}") for line in lines: print(f" {line}") return 0 if __name__ == "__main__": sys.exit(main())