"""M4: sound-chip register streams (value and clock, in order) against MAME's, per title. python scripts/sound_streams.py TITLE... [--frames 1200] For each No-Intro title: a MAME port-access log with the smoke list's generic inputs (scripts/mame_io.py, made once under tests/mame_traces/io-), then the board's replay of it with MAME's switches (scripts/replay_io.py). Prints the sound writes matched before the first difference of any kind and the time they span. """ from __future__ import annotations import argparse import subprocess import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) from replay_io import replay from colecovision_python import mame_options from colecovision_python.images import NO_INTRO ROOT = Path(__file__).resolve().parents[1] INPUTS = ["800:806:p1.1", "1000:1100:p1.right", "1150:1156:p1.fire_left"] def main() -> int: parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) parser.add_argument("titles", nargs="+") parser.add_argument("--frames", type=int, default=1200) args = parser.parse_args() for title in args.titles: run = ROOT / "tests/mame_traces" / (f"io{args.frames}-" + title.replace(" ", "_")) cart = NO_INTRO / f"{title}.zip" if not (run / "error.log").exists(): subprocess.run( [sys.executable, "-I", str(ROOT / "scripts/mame_io.py"), "coleco", str(cart), "--frames", str(args.frames), "--out", str(run), *[a for t in INPUTS for a in ("--input", t)]], check=True, stdout=subprocess.DEVNULL, ) # fmt: skip compared, _diffs, report, board = replay(run, str(cart), mame_options(), 1) sound = board.sound_matched game = sound[4:] # after the BIOS's four silencing writes span = (game[-1] - game[0]) / 3_579_545 if len(game) > 1 else 0.0 first = report[0] if report else "none" print( f"{title[:44]:44s} accesses {compared:8,d} game sound writes matched {len(game):6,d} " f"over {span:5.1f} s CPU steps {board.steps:,} first difference: {first}", flush=True, ) return 0 if __name__ == "__main__": sys.exit(main())