#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """The plane fetch-schedule cartridges, for the pin-level fit. The cartridge: plane A tile 1 (red) everywhere, tile 2 green; on each line the 68000 rewrites one cell's name (column c of the cell row the line shows) to tile 1 or 2 by V's parity, at a delay that sweeps across the line, so the picture shows whether each line's fetch of that cell came before or after the write. The measurement is ``scripts/run_vscroll_pins.py --fetch``: the referee (Nuked-MD @ 594ca2a, a closed box, its RGB pins only) against the board, plane A's fetch times fitted on the picture alone (``FETCH_AT``, OBSERVED for plane A, bounded; plane B provisional). The chip-address map below, VRAM address lines to linear address, is the one a known cartridge layout read off the VDP's VRAM pins gives (``NMD_VRAMSIG``, which logs pins only); it is kept for that use. This script once also placed each access by the model's internal H and V counters; those were removed from the harness in provenance wave 2 (2026-11-19), and that part with them. python scripts/run_fetch_schedule.py (runs run_vscroll_pins.py --fetch) """ from __future__ import annotations import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "src")) sys.path.insert(0, str(ROOT / "scripts")) from run_vscroll_latch import _w, nuked_md_cartridge # noqa: E402 COLUMNS = {True: (16, 20, 22, 23), False: (12, 14, 16, 19)} def linear(address: int) -> int: return (address & 3) | ((address >> 6) & 0x3FC) | ((address & 0xFC) << 8) def cartridge(c: int, h40: bool) -> bytes: code = bytearray() code += _w(0x46FC, 0x2700) code += bytes.fromhex("23fc5345474100a14000") code += _w(0x41F9, 0x00C0, 0x0000, 0x43F9, 0x00C0, 0x0004, 0x45F9, 0x00C0, 0x0008) for reg, value in ((0x00, 0x04), (0x01, 0x04), (0x02, 0x30), (0x04, 0x07), (0x05, 0x78), (0x07, 0x00), (0x0A, 0xFF), (0x0B, 0x00), (0x0C, 0x81 if h40 else 0x00), (0x0D, 0x3F), (0x0F, 0x02), (0x10, 0x01), (0x11, 0x00), (0x12, 0x00)): # fmt: skip code += _w(0x32BC, 0x8000 | reg << 8 | value) code += _w(0x22BC, 0xC000, 0x0000) code += _w(0x30BC, 0x0000, 0x30BC, 0x000E, 0x30BC, 0x00E0) code += _w(0x22BC, 0x4000, 0x0000, 0x303C, 0x7FFF) # clear VRAM code += _w(0x30BC, 0x0000, 0x51C8, 0xFFFA) code += _w(0x22BC, 0x4020, 0x0000) # tiles 1 (red) and 2 (green) code += _w(0x303C, 0x000F, 0x30BC, 0x1111, 0x51C8, 0xFFFA) code += _w(0x303C, 0x000F, 0x30BC, 0x2222, 0x51C8, 0xFFFA) code += _w(0x22BC, 0x4000, 0x0003) # plane A: every cell tile 1 code += _w(0x303C, 0x07FF, 0x30BC, 0x0001, 0x51C8, 0xFFFA) code += _w(0x32BC, 0x8144) code += _w(0x7800, 0x7200) loop = bytearray() loop += _w(0x1012, 0xB001, 0x67FA, 0x1200, 0x3400, 0x0242, 0x003F) loop += _w(0x1A01, 0x0285, 0x0000, 0x00F8, 0xE98D) # d5 = (V & $F8) << 4 loop += _w(0x0685, 0x0000, 2 * c, 0x4845) # + 2c, swap loop += _w(0x0085, 0x4000, 0x0003) # VRAM write at $C000 + that loop += _w(0x1801, 0x0244, 0x0001, 0x5244) # d4 = (V & 1) + 1 loop += _w(0x51CA, 0xFFFE) # D: dbra d2,D loop += _w(0x2285, 0x3084) # move.l d5,(a1); move.w d4,(a0) n = len(loop) loop += _w(0x6000, (-(n + 2)) & 0xFFFF) return nuked_md_cartridge(bytes(code + loop)) def main() -> int: import run_vscroll_pins sys.argv[1:] = ["--fetch", *sys.argv[1:]] return run_vscroll_pins.main() if __name__ == "__main__": sys.exit(main())