#!/usr/bin/env python3 """Rung 7: frames per second for a Graphics II frame with sprites, windows on and off. The picture is the synthetic "g2" case's VRAM (validation/synthetic.py): full Graphics II tables, 13 sprites on screen (five on one line), plus a stream of one VRAM write every 200 master clocks during the frame so the access path is exercised. Reference cores are correct, not fast: real time (59.92 frames a second) is not a goal; the number is recorded. python -I validation/speed.py [frames] """ from __future__ import annotations import platform import sys import time from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "validation")) import synthetic # noqa: E402 (puts src on the path) from tms9918_python import TMS9918, TMS9928A # noqa: E402 FRAME = 684 * 262 def measure(windows: bool, frames: int) -> float: vram, regs, _ = synthetic.cases()["g2"] vdp = TMS9918(TMS9928A, windows=windows) vdp.write(1, 0x80) vdp.write(1, 0x81) vdp.vram[:] = vram for reg, value in enumerate(regs): vdp.write(1, value) vdp.write(1, 0x80 | reg) vdp.run(FRAME) # warm up start = time.perf_counter() for _ in range(frames): vdp.write(1, 0x00) vdp.write(1, 0x7C) # write address $3C00 (unused by this picture) for _ in range(FRAME // 200): vdp.run(200) vdp.write(0, 0x55) vdp.run(FRAME - (FRAME // 200) * 200) return frames / (time.perf_counter() - start) def main() -> int: frames = int(sys.argv[1]) if len(sys.argv) > 1 else 20 impl = f"{platform.python_implementation()} {platform.python_version()}" for windows in (True, False): fps = measure(windows, frames) print(f"{impl}: windows {'on ' if windows else 'off'}: {fps:6.2f} frames/s " f"({fps / 59.92:.3f} x real time), {frames} frames") # fmt: skip return 0 if __name__ == "__main__": sys.exit(main())