"""Every cartridge's sound-chip writes under MAME 0.285, for the period-0/1 question (C8). python -I scripts/psg_sweep.py [--frames 1800] [--out tests/mame_traces/psg] One MAME run at a time, untraced except for a watchpoint on writes to $E0-$FF, with a generic input script (keypad 1 at frames 800 and 1200, fire at 1000 and 1400, so most games leave their title and skill screens). Then ``scripts/psg_streams.py`` reads the logs. MAME is a detector: what a game *writes* does not depend on whose PSG plays it, and the board's own streams equal MAME's where they were compared (docs/results.md, M4). """ from __future__ import annotations import argparse import os import subprocess import sys import time from pathlib import Path ROOT = Path(__file__).resolve().parents[1] NO_INTRO = ( Path(os.environ.get("NO_INTRO_DIR") or sys.exit("set NO_INTRO_DIR to the No-Intro romset folder")) / "Coleco - ColecoVision" ) INPUTS = ["800:806:p1.1", "1000:1006:p1.fire_left", "1200:1206:p1.1", "1400:1406:p1.fire_left"] def main() -> int: parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) parser.add_argument("--frames", type=int, default=1800) parser.add_argument("--out", type=Path, default=ROOT / "tests/mame_traces/psg") args = parser.parse_args() began = time.monotonic() images = sorted(p for p in NO_INTRO.glob("*.zip") if not p.name.startswith("[BIOS]")) for n, image in enumerate(images): out = args.out / image.stem.replace(" ", "_") if (out / "error.log").exists(): continue command = [ sys.executable, "-I", str(ROOT / "scripts/mame_io.py"), "coleco", str(image), "--frames", str(args.frames), "--out", str(out), "--ports", "e0,20", "--writes-only", ] command += [a for t in INPUTS for a in ("--input", t)] result = subprocess.run(command, capture_output=True, text=True) status = result.stdout.strip() or result.stderr.strip().splitlines()[-1:] print(f"{n + 1:3d}/{len(images)} {image.stem[:50]:50s} {status}", flush=True) print(f"{len(images)} images in {time.monotonic() - began:.0f} s") return 0 if __name__ == "__main__": sys.exit(main())