"""Execute the official Geargrafx libretro core with a tiny headless frontend. The frontend supplies callbacks; CPU/memory execution belongs to Geargrafx. No emulator source is incorporated into the MIT ROM or this frontend. """ import argparse import ctypes as C import hashlib import json import re from pathlib import Path import subprocess import sys import struct import tempfile sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "tools")) from build import verify_fixture # noqa: E402 from environment import DEPENDENCIES, core_path # noqa: E402 EXPECTED = b"PCE!\xf8\x5a" def missing_marker_rom(data, labels): """Locate the exported instruction and assert its opcode/operands before mutation.""" symbols = {} for line in labels.splitlines(): match = re.fullmatch(r"al ([0-9A-Fa-f]{6}) \.(\w+)", line) if match: address, name = int(match[1], 16), match[2] if name in symbols and symbols[name] != address: raise ValueError(f"conflicting fixture symbol: {name}") symbols[name] = address if not {"reset", "marker", "marker_transfer"} <= symbols.keys(): raise ValueError("fixture transfer/marker/reset symbols missing") if symbols["reset"] != 0xe000 or len(data) != 8192: raise ValueError("fixture bank mapping mismatch") offset = symbols["marker_transfer"] - symbols["reset"] if not 0 <= offset <= len(data) - 7 or not 0xe000 <= symbols["marker"] <= 0xffff: raise ValueError("fixture transfer symbol outside mapped ROM") instruction = b"\x73" + struct.pack("