#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Repro, on the reference alone, of a5200-python 844355d's trak-ball save-state finding. A save state taken while a CX53 trak-ball is rolling does not continue identically: ``state.snapshot`` does not hold the trak-ball's lag output (``Controllers._balls[n].out``), and ``state.restore`` calls ``Controllers.apply()``, which steps that lag once more. Run with the reference's interpreter, from ``/``: PYTHONPATH=external/a5200-python/src PYPY_GC_NURSERY=1M \\ ../a5200-python/.venv-pypy/bin/python scripts/trak_state_repro.py \\ "$NO_INTRO_DIR/Atari - Atari 5200/Missile Command (USA).zip" Measured 2026-11-14: lag output 164.0 at the save, 139.0 after restore; POT0's target 10 frames on 18696 uninterrupted, 18693 restored. The Rust board inherited it (the trak-ball case then in scripts/cases-upstream.tsv failed with --save-at-half at the first slice after the load). Fixed upstream in a5200-python cf82d44 (save-state version 4; its test_missile_command_trakball_save_continues is this repro). Run against cf82d44 it prints the same lag, x and target on both sides; the case is now trak/missile-command-rolling-at-half in scripts/cases.tsv. Kept as the record of the finding. """ import sys from a5200_python import state from a5200_python.system import Console rom = sys.argv[1] def drive(console, frames, start): pad = console.controllers.pads[0] for f in range(start, start + frames): pad.trakball = True pad.vx = 4.0 if f >= 480 else 0.0 console.run_frames(1) a = Console(rom) drive(a, 500, 1) saved = state.snapshot(a) ball_a = list(a.controllers._balls[0].out) drive(a, 10, 501) b = Console(rom) state.restore(b, saved) ball_b = list(b.controllers._balls[0].out) drive(b, 10, 501) print("trak-ball lag output at the save:", ball_a, "after restore:", ball_b) print("pad 1 x after 10 more frames: uninterrupted", a.controllers.pads[0].x, "restored", b.controllers.pads[0].x) print("POT0 target:", a.controllers.rc.target[0], b.controllers.rc.target[0])