#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Write scripts/cases-midframe.tsv: the mid-frame save-state cases (methodology.md "Save states in the gate"), from the inputs and save points of a5200-python's tests/test_state.py (cf82d44), expressed as tracer options. - ``busy/``: the synthetic case (``scripts/busy_case.py`` writes its BIOS, cartridge and RAM images to ``$BUSY``) under the test's ``_drive`` (a trak-ball changing speed every frame on port 1 with its buttons and the keypad, a stick moving on port 2), 60 frames, one row per save point of the test's ``SAVE_POINTS`` (the frame-boundary one is ``--save-at``), at slice 20. - ``title/``: Missile Command and Centipede (trak-ball), Star Raiders (keypad), Pac-Man (stick) under the test's ``_title_drive``, 900 frames, every save point in turn, one per 50 slices from slice 450 (``cycle-12345`` at slice 600, the test's own point). The tracers apply frame f's inputs (the test's ``drive(console, f)``, f from 0) before slice f, which they number frame f + 1. Stdlib only: python3 scripts/midframe_cases.py """ from __future__ import annotations from pathlib import Path HERE = Path(__file__).resolve().parent POINTS = ["cycle-1", "cycle-7001", "cycle-15013", "cycle-29801", "wsync-pending", "irq-edge-unsynced", "irq-held", "nmi-pending"] def busy_inputs(frames: int) -> list[str]: """tests/test_state.py ``_drive`` for f in range(frames).""" args = [] for f in range(frames): fr = f + 1 vx = (3.0, 8.0, -2.0, 0.0, 5.5)[f % 5] vy = (-4.0, 1.0, 6.0)[f % 3] args.append(f"--trak {fr}:{vx}:{vy}:1") if f % 4 == 1: args.append(f"--press {fr}:trigger:1:1") if f % 3 == 2: args.append(f"--press {fr}:top:1:1") if f % 3: args.append(f"--press {fr}:{('1', '5', 'start', '#', '0')[f % 5]}:1:1") args.append(f"--stick {fr}:{20.0 + (f * 37) % 200}:{228.0 - (f * 11) % 200}:2") return args def title_inputs(kind: str, frames: int) -> list[str]: """tests/test_state.py ``_title_drive(kind)`` for f in range(frames), as changes.""" args = ["--press 301:start:10"] for f in range(400, frames): if f % 20 == 0: args.append(f"--press {f + 1}:trigger:5") last = None for f in range(frames): fr = f + 1 if kind == "trak": now = ((6.0, -3.0, 0.0, 2.5)[(f // 7) % 4], (-5.0, 4.0, 1.0)[(f // 5) % 3]) if now != last: args.append(f"--trak {fr}:{now[0]}:{now[1]}") elif kind == "keypad": if f >= 400 and f % 9 == 0: args.append(f"--press {fr}:{('1', '4', '7', '0', '#', '*')[(f // 9) % 6]}:3") now = (114.0 + ((f % 60) - 30) * 3, 114.0) if now != last: args.append(f"--stick {fr}:{now[0]}:{now[1]}") else: now = ((20.0, 114.0, 220.0)[(f // 15) % 3], (114.0, 220.0, 20.0)[(f // 25) % 3]) if now != last: args.append(f"--stick {fr}:{now[0]}:{now[1]}") last = now return args TITLES = { "missile-command-trak": ("Missile Command (USA)", "trak"), "centipede-trak": ("Centipede (USA)", "trak"), "star-raiders-keypad": ("Star Raiders (USA)", "keypad"), "pac-man-stick": ("Pac-Man (USA)", "stick"), } def main() -> int: rows = [ "# SPDX-License-Identifier: MIT", "# Mid-frame save states: written by scripts/midframe_cases.py (do not edit by hand).", "# The save points and inputs of a5200-python's tests/test_state.py (cf82d44); the", "# reference runs uninterrupted, this board saves inside the frame, loads into a fresh", "# console and must go on identically. busy/* need scripts/busy_case.py first ($BUSY).", "# name\tslices\trom\targuments", ] busy = " ".join(["--bios $BUSY/bios.bin --ram 1000:$BUSY/dlist.bin " "--ram 2000:$BUSY/screen.bin", *busy_inputs(60)]) rows.append(f"busy/frame-boundary\t60\t$BUSY/cart.bin\t{busy} --save-at 20") for point in POINTS: rows.append(f"busy/{point}\t60\t$BUSY/cart.bin\t{busy} --save-mid 20:{point}") for name, (rom, kind) in TITLES.items(): saves = [] for n, point in enumerate(["cycle-1", "cycle-7001", "cycle-15013", "cycle-12345", "cycle-29801", "wsync-pending", "irq-edge-unsynced", "irq-held", "nmi-pending"]): saves.append(f"--save-mid {450 + 50 * n}:{point}") args = " ".join([*title_inputs(kind, 900), *saves]) rows.append(f"title/{name}\t900\t$NOINTRO/{rom}.zip\t{args}") (HERE / "cases-midframe.tsv").write_text("\n".join(rows) + "\n") print(f"wrote {len(rows) - 6} cases") return 0 if __name__ == "__main__": raise SystemExit(main())