"""Rung 4: access windows against VATT's hardware results (tier 3). The hardware numbers are VATT's raw sheet (aoineko and the machines' owners, msxgl wiki; ``reference/docs/vatt-raw.csv`` as pinned on 2026-11-12; no licence, so the numbers are written here with this citation and the sheet is never committed): the percentage of 256 fast VRAM writes that land, per loop period in MSX Z80 clocks. The full comparison, all modes and periods, is ``python -I validation/vatt.py check`` (docs/results.md); these are the points with the most rows behind them. """ from __future__ import annotations import sys from pathlib import Path import pytest from tms9918_python import TMS9928A, TMS9929A sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "validation")) import vatt # noqa: E402 PHASES = 12 # 60 Hz rows with a TI part, display on, Graphics II, sprites hidden (VATT raw sheet): # period -> (lowest, highest) percent landed, and the number of rows. HARDWARE_G2_60HZ = {12: (64, 78, 18), 22: (92, 95, 16), 26: (98, 100, 17), 27: (100, 100, 14)} @pytest.mark.parametrize("period", sorted(HARDWARE_G2_60HZ)) def test_graphics2_within_the_hardware_spread(period): lo, hi, _ = HARDWARE_G2_60HZ[period] value = vatt.emulate(TMS9928A, "G2", True, period, "newer", TMS9928A.access_delay, PHASES) assert lo - 1.0 <= value <= hi + 1.0 # one point for the core's phase sampling def test_text_and_blank_keep_up_with_the_fastest_loop(): # VATT: Text and display off land 100 % at 12 T on every TI row. assert vatt.emulate(TMS9928A, "T1", True, 12, "newer", 16, PHASES) == 100.0 assert vatt.emulate(TMS9928A, "G2", False, 12, "newer", 16, PHASES) == 100.0 def test_multicolor_is_no_faster_than_graphics2(): # C9: VATT's Multicolor rows equal its Graphics II rows at every period. mc = vatt.emulate(TMS9928A, "MC", True, 17, "newer", 16, PHASES) g2 = vatt.emulate(TMS9928A, "G2", True, 17, "newer", 16, PHASES) assert mc == g2 def test_restart_rule_is_ruled_out(): # U3: restarting the VDP delay on each new access loses far more than hardware at # 12 T (VATT: at least 64 %); the "newer" and "older" rules land the same counts. restart = vatt.emulate(TMS9928A, "G2", True, 12, "restart", 16, PHASES) newer = vatt.emulate(TMS9928A, "G2", True, 12, "newer", 16, PHASES) older = vatt.emulate(TMS9928A, "G2", True, 12, "older", 16, PHASES) assert restart < 60 and newer == older def test_50hz_part_lands_more_at_12t(): # VATT 50 Hz rows (TMS9929/TMS9929A, 3 rows): 70-74 % at 12 T, more than the 60 Hz # rows' median, as a longer vertical blank gives more of every burst to the CPU. pal = vatt.emulate(TMS9929A, "G2", True, 12, "newer", 16, PHASES) ntsc = vatt.emulate(TMS9928A, "G2", True, 12, "newer", 16, PHASES) assert pal > ntsc and 69.0 <= pal <= 75.0