#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Where each mid-run capture's lockstep starts, from the reference's own harness. capture_starts.py OUT.json The six long captures start in the middle of a run; the reference's rung 4 (``tests/capture_replay.py``, ``decoder_start``) takes the registers from the capture decoder ``decode6502`` (a GPL program, run as an external tool; its source is not opened here) at the first instruction where it knows every register. This calls that same function for each capture and writes ``{"machine/capture": {"start": sample, "registers": {...}}}`` so that ``target/release/capture`` starts exactly where the reference does. Run it with the reference's interpreter; ``$W65C02_PYTHON`` is the reference checkout. """ from __future__ import annotations import json import os import sys from pathlib import Path def main() -> int: reference = Path(os.environ["W65C02_PYTHON"]).resolve() sys.path.insert(0, str(reference / "tests")) import capture_replay starts = {} for machine, captures in capture_replay.CAPTURES.items(): for capture in captures: path = capture_replay.raw_path(machine, capture) with path.open("rb") as handle: first = int.from_bytes(handle.read(2), "little") if not first & capture_replay.RST: continue # a reset capture starts at the reset sequence: nothing to ask start, registers = capture_replay.decoder_start(machine, path) starts[f"{machine}/{capture}"] = {"start": start, "registers": registers} print(f"{machine}/{capture}: sample {start}, {registers}", flush=True) Path(sys.argv[1]).write_text(json.dumps(starts, indent=1, sort_keys=True) + "\n") return 0 if __name__ == "__main__": sys.exit(main())