"""Turbo (driving module) and Slither (Roller Controller) under scripted spinner input. python scripts/spinner_games.py [--frames 1500] Runs each game three times, turning left, not at all, and right from frame 1100 on, and prints how many maskable-interrupt responses the CPU took (the spinner's /INT pulses) and how many pixels of the last frame differ between the runs. A game that reads the spinner must take the interrupts and draw different pictures for the three runs. """ from __future__ import annotations import argparse import sys from colecovision_python import ColecoVision, HandController from colecovision_python.controllers import DrivingModule, RollerController from colecovision_python.images import NO_INTRO, load_image from colecovision_python.pictures import differences from colecovision_python.video import write_png def run(title: str, kind: str, rate: float, frames: int, png: str | None): image = load_image(NO_INTRO / f"{title}.zip") pad = HandController() if kind == "turbo": wheel = DrivingModule() console = ColecoVision(image, port1=wheel, port2=pad) pads, spin = (wheel, pad), (lambda r: setattr(wheel.spinner, "rate", r)) else: roller = RollerController() console = ColecoVision(image, port1=roller.ports[0], port2=roller.ports[1]) pads, spin = roller.ports, (lambda r: setattr(roller, "x", r)) board = console.board interrupts = 0 frame = None for n in range(frames): for p in pads: p.keys, p.left_fire, p.right_fire = set(), False, False if 800 <= n < 806: for p in pads: p.keys = {"1"} if kind == "turbo" and n >= 1000: wheel.pedal = True if kind != "turbo" and 1000 <= n < 1006: pads[0].left_fire = True spin(rate if n >= 1100 else 0.0) while True: pc = board.cpu.pc board.step() if board.cpu.pc == 0x0038 and pc != 0x0038: interrupts += 1 f = board.vdp.take_frame() if f is not None: frame = f break if png: write_png(png, frame.pixels) return interrupts, frame.pixels def main() -> int: parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) parser.add_argument("--frames", type=int, default=1500) parser.add_argument("--png-prefix") args = parser.parse_args() for title, kind in (("Turbo (USA, Europe)", "turbo"), ("Slither (USA, Europe)", "roller")): results = {} for rate in (-60.0, 0.0, 60.0): png = f"{args.png_prefix}-{kind}-{int(rate)}.png" if args.png_prefix else None results[rate] = run(title, kind, rate, args.frames, png) left, still, right = (results[r] for r in (-60.0, 0.0, 60.0)) print( f"{title}: interrupt responses left {left[0]}, still {still[0]}, right {right[0]}; " f"pixels differing left/still {differences(left[1], still[1])}, " f"right/still {differences(right[1], still[1])}, left/right {differences(left[1], right[1])}" ) return 0 if __name__ == "__main__": sys.exit(main())