#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """MAME lockstep (rung 5): replay MAME 0.285's traces of four machines through the core. python -I scripts/mame_trace.py bbcm --bus --seconds 3 # record a trace first python -I scripts/run_mame_replay.py # every recorded driver python -I scripts/run_mame_replay.py lynx --limit 1000000 The method is tests/mame_replay.py's. MAME is an emulator: every difference printed here is a question, to be settled by a higher tier (docs/mame-oracle.md lists the answers). Exit status 0 always: a detector does not pass or fail. """ from __future__ import annotations import argparse import multiprocessing import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "tests")) import mame_replay def run(task: tuple[str, int | None]) -> str: driver, limit = task return mame_replay.format_report(mame_replay.replay(driver, limit), categories=60) def main() -> int: parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) parser.add_argument("driver", nargs="*", help=f"default: {' '.join(mame_replay.DRIVERS)}") parser.add_argument("--limit", type=int, help="instructions per driver") parser.add_argument("--jobs", type=int, default=4) args = parser.parse_args() drivers = args.driver or list(mame_replay.DRIVERS) missing = [driver for driver in drivers if not mame_replay.has_bus_trace(driver)] if missing: raise SystemExit(f"{mame_replay.TRACE_HINT} (missing: {' '.join(missing)})") with multiprocessing.Pool(min(args.jobs, len(drivers))) as pool: for text in pool.imap(run, [(driver, args.limit) for driver in drivers]): print(text, flush=True) return 0 if __name__ == "__main__": sys.exit(main())