#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Frame hashes: pixels, audio and CPU registers of a run, to prove a change left the 2600 alone. For each dump, the board runs ``--frames`` frames with no input and hashes, frame by frame, every line the TIA finished (all 228 colour clocks, blank included), every audio sample, and the 6507's registers and the board's cycle count at the frame's end. One line per dump: the SHA-256 of the whole run and of each part. Two runs of the same tree must print identical lines; a refactor that changes nothing observable must too. Dumps are named relative to the No-Intro root in ``NO_INTRO_DIR`` (no machine path in the repository); the default list is the eight-plus games of ``DEFAULT_GAMES``, one or more per scheme family. python scripts/frame_hashes.py [--frames 600] [--out hashes.tsv] [NAME ...] ``--machine`` runs another row and ``--start FRAME`` starts a game before hashing; ``tests/frame_hashes_rows.tsv`` keeps Pitfall II with its DPC music on, per row (``--start 100``; docs/validation.md, "The DPC oscillator on every row"). The default record stays the NTSC row with no input. """ from __future__ import annotations import argparse import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "src")) from a2600_python import System # noqa: E402 from a2600_python.gates import dump_path, hash_row, run_hashes # noqa: E402 from a2600_python.machine import HOSTED_MACHINES, MACHINES, VCS_NTSC # noqa: E402 DEFAULT_GAMES = ( "Combat ~ Tank-Plus (USA)", # 2K "Pitfall! - Pitfall Harry's Jungle Adventure (USA)", # 4K "Adventure (USA)", # 4K "River Raid (USA)", # 4K "Space Invaders (USA)", # 4K "Crystal Castles (USA)", # F6SC "Montezuma's Revenge - Featuring Panama Joe (USA)", # E0 "BurgerTime (USA)", # E7 "Activision Decathlon, The (USA)", # FE "David Crane's Pitfall II - Lost Caverns (USA)", # DPC ) def main() -> int: parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) parser.add_argument("names", nargs="*", default=list(DEFAULT_GAMES)) parser.add_argument("--frames", type=int, default=600) parser.add_argument("--out", type=Path, help="append the lines here too") parser.add_argument( "--machine", default=VCS_NTSC.name, choices=sorted({**MACHINES, **HOSTED_MACHINES}), help="the row to run (default: the NTSC VCS, the record's row)", ) parser.add_argument( "--start", type=int, metavar="FRAME", help="before hashing, press Reset for frames 30-39 and fire for FRAME to" " FRAME+9 (starts Pitfall II's music at 100); the hashed frames follow", ) parser.add_argument( "--check", type=Path, help="compare with a recorded file (tests/frame_hashes.tsv); 1 on any change", ) args = parser.parse_args() # A run other than the record's (another row, or a game started) is # labelled with its settings, so one file can keep several rows. settings = "" if args.machine != VCS_NTSC.name or args.start is not None: start = "" if args.start is None else f", start {args.start}" settings = f" [{args.machine}{start}]" expected = {} if args.check: for row in args.check.read_text().splitlines(): if row and not row.startswith("#"): expected[row.split("\t")[0]] = row if not args.names or args.names == list(DEFAULT_GAMES): args.names = [ k.removesuffix(settings) for k in expected if (k.endswith(settings) if settings else not k.endswith("]")) ] changed = 0 for name in args.names: system = System.from_rom(dump_path(name), {**MACHINES, **HOSTED_MACHINES}[args.machine]) if args.start is not None: riot, tia = system.board.riot, system.board.tia system.run_frames(30) riot.input_b &= ~0x01 # Reset (SWCHB D0) pressed system.run_frames(10) riot.input_b |= 0x01 system.run_frames(max(0, args.start - 40)) tia.fire[0] = True system.run_frames(10) tia.fire[0] = False label = name + settings row = hash_row(label, args.frames, run_hashes(system, args.frames)) verdict = "" if args.check: same = expected.get(label) == row changed += not same verdict = "\tsame" if same else "\tCHANGED" print(row + verdict, flush=True) if args.out: with args.out.open("a") as out: out.write(row + "\n") if args.check: print(f"{len(args.names) - changed} of {len(args.names)} runs identical") return 1 if changed else 0 if __name__ == "__main__": sys.exit(main())