# SPDX-License-Identifier: MIT """Which mini-sweep cartridges does IPL_SYNC_WHILE_STOPPED change? Each cartridge runs --frames with the rule off (the regression); if its 68000 ever STOPped, it runs again with the rule on and the two final pictures are compared. NO_INTRO_DIR=... python stop_impact.py [--frames 600] [--jobs 10] """ import argparse import hashlib import os import sys from multiprocessing import Pool from pathlib import Path ROOT = Path("/data/emu/megadrive-python") sys.path.insert(0, str(ROOT / "src")) def run(path: Path, frames: int, fix: bool): import megadrive_python.system as sm from megadrive_python.cartridge import Cartridge from megadrive_python.machine import MACHINES sm.IPL_SYNC_WHILE_STOPPED = fix s = sm.System(MACHINES["genesis"], Cartridge.from_file(path)) s.board.fm.enabled = False cpu = s.m68k stopped_steps = 0 seen = set() for _ in range(frames): f = s.vdp.frame while s.vdp.frame == f: if cpu.stopped: stopped_steps += 1 s.step() seen.add(hashlib.sha1(repr(s.vdp.renderer.frame_rgb()).encode()).hexdigest()) last = hashlib.sha1(repr(s.vdp.renderer.frame_rgb()).encode()).hexdigest()[:10] return stopped_steps, last, len(seen) def one(args): name, frames = args path = Path(os.environ["NO_INTRO_DIR"]) / "Sega - Mega Drive - Genesis" / f"{name}.zip" if not path.exists(): path = path.parent.parent / "Sega - Mega Drive - Genesis (Aftermarket)" / path.name if not path.exists(): return name, "missing" try: steps, last, distinct = run(path, frames, False) if not steps: return name, f"never stopped ({distinct} distinct)" steps2, last2, distinct2 = run(path, frames, True) same = "same" if last == last2 else "DIFFERS" return name, (f"stopped {steps} steps off / {steps2} on; distinct {distinct} -> " f"{distinct2}; last frame {same}") except Exception as e: # noqa: BLE001 return name, f"error {type(e).__name__}: {e}" p = argparse.ArgumentParser() p.add_argument("--frames", type=int, default=600) p.add_argument("--jobs", type=int, default=10) a = p.parse_args() names = [line.strip() for line in (ROOT / "tests/mini_sweep.txt").read_text().splitlines() if line.strip() and not line.startswith("#")] if os.environ.get("ONLY_FILE"): names = Path(os.environ["ONLY_FILE"]).read_text().splitlines() with Pool(a.jobs) as pool: for name, verdict in pool.imap(one, [(n, a.frames) for n in names]): print(f"{name}\t{verdict}", flush=True)