#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Milestone 4: the DMA-hard titles at the wiki's scenes, the board against MAME. Each recipe names the title, the symptom the wiki's "Common Emulator Development Issues" page gives (tier 3, console-verified), the frames to run from the NTSC BIOS, the snapshot frames and the scripted input (``frames_mame.py --script`` items, applied on both machines). Every recipe runs ``frames_mame.py`` with MAME's switches and the C17/C18 exclusions (named, counted there); the board's frames that differ are kept as PNGs in the run directory, MAME's snapshots beside them. A title reaches its scene only if the frames show it (looked at, recorded in docs/build-progress.md); MAME's agreement is a detector's. python scripts/m4_scenes.py [--jobs 3] [--only Choplifter,Xenophobe] """ from __future__ import annotations import argparse import os import re import subprocess import sys from concurrent.futures import ThreadPoolExecutor from pathlib import Path from a7800_python import romsets ROOT = Path(__file__).resolve().parents[1] ROMS = romsets.no_intro(romsets.LICENSED_7800) def presses(action: str, frames: list[int], hold: int = 6) -> list[str]: """Press ``action`` at each frame for ``hold`` frames, then release everything.""" items = [] for f in frames: items += [f"{f}:{action}", f"{f + hold}:{'switches-off' if action in ('reset', 'select', 'pause') else 'none'}"] return items # name: (dump, symptom, frames, every, extra snapshot frames, script) RECIPES: dict[str, tuple[str, str, int, int, str, list[str]]] = { "Choplifter": ("Choplifter! (USA).zip", "horizon line in place and still (DMA penalties); no glitch zone high in the sky (TIA floating bus)", 1400, 50, "", [*presses("reset", [700]), "900:right", "960:up", "1000:b1", "1010:right", "1100:left", "1200:none"]), "Xenophobe": ("Xenophobe (USA).zip", "title graphic's bottom row in the right colour; the action screen does not glitch (DMA timing)", 1600, 50, "", []), "One-on-One": ("One-on-One Basketball (USA).zip", "a button press advances past the option menu (RIOT two-button default)", 1300, 50, "", presses("b12", [500, 700, 900])), "Ninja Golf": ("Ninja Golf (USA).zip", "the player-number screen's graphics are 160A, not squished 160B (non-zero terminators)", # session 8: the "NORMAL" screen, the story, then the course (frame 1500 on MAME) 1700, 50, "", presses("select", [500]) + presses("b12", [700, 900]) + ["1100:right", "1400:b1", "1406:right"]), "Crossbow": ("Crossbow (USA).zip", "graphics not garbled or in the wrong mode (non-zero terminators)", 1000, 50, "", []), "Planet Smashers": ("Planet Smashers (USA).zip", "the background starfield, not glitched graphics ($BFFF hotspot)", 1200, 50, "", presses("reset", [600])), "Alien Brigade": ("Alien Brigade (USA).zip", "no corruption in the main screen with many objects (DMA penalties)", 1600, 50, "", []), "Summer Games": ("Summer Games (USA).zip", "Platform Diving: no flickering line between the stands and the pool deck (DMA timing)", # session 8: Reset, MAIN MENU item 4 "PRACTICE ONE EVENT", event A # "PLATFORM DIVING" (the menus as MAME shows them), then dive presses 1700, 50, "", presses("reset", [600]) + presses("down", [760, 800, 840]) + presses("b1", [900, 1000, 1200, 1300, 1400])), "Ace of Aces": ("Ace of Aces (USA).zip", "the top line of sky does not bounce (DMA timing)", 1600, 50, "", presses("reset", [600]) + presses("b1", [800, 1000]) + ["1100:left", "1200:up", "1300:b1", "1310:none"]), "Karateka": ("Karateka (USA).zip", "second enemy stage: no flicker bottom right or in the power meter (DMA timing)", 2400, 100, "", presses("reset", [600])), "Pole Position II": ("Pole Position II (USA).zip", "track selection by joystick reaches every track (first frame in VBLANK; SWCHA read twice)", # session 8: the stick works on the track-selection screen (frames 240-600), # not in the race; Reset then starts on the chosen track 1000, 40, "", presses("down", [260, 340]) + presses("right", [420]) + presses("reset", [600])), "M.I.A.": ("Missing in Action (USA) (Proto).zip", "right sprites for player and enemies (DMA penalties); no hang at level 2 (TIA undriven bits)", 1600, 50, "", [*presses("reset", [600]), "700:right", "1000:b1", "1010:right", "1300:b1", "1310:right"]), "Klax": ("Klax (USA) (Proto).zip", "starts up, not a black screen (start race; hit-or-miss on consoles too)", 1000, 50, "", []), "Tower Toppler": ("Tower Toppler (USA).zip", "320-mode pixels (composite artefacts are a frontend option, milestone 8)", 1200, 50, "", []), "RealSports Baseball": ("RealSports Baseball (USA).zip", "Holey DMA title (the brief's logic-analyser case)", 1400, 50, "", presses("reset", [600]) + presses("b1", [800, 1000, 1200])), "Kung-Fu Master": ("Kung-Fu Master (USA).zip", "line RAM buffering (the brief's list)", 1400, 50, "", [*presses("reset", [600]), "800:right", "900:b1", "910:left", "1000:b2", "1010:right", "1200:none"]), } SUMMARY = re.compile(r": (\d+) frames compared .*?, (\d+) differ") def run(name: str, tag: str, faults: list[str]) -> tuple[str, str]: dump, _symptom, frames, every, at, script = RECIPES[name] cmd = [sys.executable, str(ROOT / "scripts/frames_mame.py"), str(ROMS / dump), "--frames", str(frames), "--every", str(every), "--mame-switches", "--mask-tia-undriven", "--mask-open-bus", "--ram", f"--tag={tag}"] # fmt: skip for fault in faults: cmd += ["--fault", fault] if at: cmd += ["--at", at] if script: cmd += ["--script", *script] env = dict(os.environ, PYPY_GC_NURSERY="1M") done = subprocess.run(["nice", "-n", "19", *cmd], capture_output=True, text=True, env=env) return name, done.stdout + done.stderr def main() -> int: parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) parser.add_argument("--jobs", type=int, default=3) parser.add_argument("--only", default="") parser.add_argument("--tag", default="-m4") parser.add_argument("--log", type=Path, default=ROOT / "tests/detector_runs/m4-scenes.txt") parser.add_argument("--fault", action="append", default=[], help="seeded board fault (the judge must then fail, e.g. end-test-zero on Crossbow)") args = parser.parse_args() names = [n for n in RECIPES if not args.only or n in args.only.split(",")] lines = [] with ThreadPoolExecutor(args.jobs) as pool: for name, output in pool.map(lambda n: run(n, args.tag, args.fault), names): m = SUMMARY.search(output) verdict = f"{m.group(2)} of {m.group(1)} frames differ" if m else "no comparison" lines.append(f"## {name}: {verdict}\nsymptom: {RECIPES[name][1]}\n{output}") print(f"{name}: {verdict}", flush=True) args.log.write_text("\n".join(lines), encoding="utf-8") return 0 if __name__ == "__main__": sys.exit(main())