#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """The full-screen vertical-scroll cartridges, for the pin-level fit. A cartridge built here: plane A (or B) is red over its top 128 pixel rows and green over the bottom 128 of a 64x32 plane, with full-screen scroll. The 68000 polls the V counter; on each new line it waits (V & 63) ``dbra`` loops, which sweeps its write across the whole line over 64 lines, then writes VSRAM word 0 (or 1) as ``(V & 1) << 7``. A value of 128 swaps red and green, so each line shows, pixel by pixel, which value was in force. The measurement is ``scripts/run_vscroll_pins.py --full-screen``: these cartridges run on the referee (Nuked-MD @ 594ca2a, a closed box, its RGB pins only) and on the board, and the latch point is fitted on the picture alone (``VSCROLL_LATCH_H``, OBSERVED). This script once also read the model's internal scroll latches and V counter; those taps were removed from the harness in provenance wave 2 (2026-11-19), and that part with them. python scripts/run_vscroll_latch.py (runs run_vscroll_pins.py --full-screen) """ 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")) def _w(*words: int) -> bytes: return b"".join(x.to_bytes(2, "big") for x in words) def cartridge(plane: str = "A", h40: bool = True) -> bytes: """The test cartridge, hand-assembled; each encoding is in its comment.""" code = bytearray() code += _w(0x46FC, 0x2700) # move.w #$2700,sr code += bytes.fromhex("23fc5345474100a14000") # move.l #'SEGA',$A14000 code += _w(0x41F9, 0x00C0, 0x0000) # lea $C00000,a0 (data) code += _w(0x43F9, 0x00C0, 0x0004) # lea $C00004,a1 (control) code += _w(0x45F9, 0x00C0, 0x0008) # lea $C00008,a2 (HV counter) for reg, value in ( (0x00, 0x04), (0x01, 0x04), # mode 5, display off while loading (0x02, 0x30 if plane == "A" else 0x38), # the plane under test at $C000, (0x04, 0x07 if plane == "A" else 0x06), # the other at an empty table (0x05, 0x78), (0x07, 0x00), (0x0A, 0xFF), (0x0B, 0x00), # full-screen H and V scroll (0x0C, 0x81 if h40 else 0x00), (0x0D, 0x3F), (0x0F, 0x02), (0x10, 0x01), # 64x32 (0x11, 0x00), (0x12, 0x00), ): # fmt: skip code += _w(0x32BC, 0x8000 | reg << 8 | value) # move.w #$8rvv,(a1) code += _w(0x22BC, 0xC000, 0x0000) # move.l #$C0000000,(a1): CRAM write 0 code += _w(0x30BC, 0x0000, 0x30BC, 0x000E, 0x30BC, 0x00E0) # black, red, green code += _w(0x22BC, 0x4000, 0x0000) # VRAM write 0 code += _w(0x303C, 0x7FFF) # move.w #$7FFF,d0 code += _w(0x30BC, 0x0000, 0x51C8, 0xFFFA) # clear: move.w #0,(a0); dbra d0,clear code += _w(0x22BC, 0x4020, 0x0000) # VRAM write $0020: tiles 1 and 2 code += _w(0x303C, 0x000F, 0x30BC, 0x1111, 0x51C8, 0xFFFA) # tile 1: colour 1 code += _w(0x303C, 0x000F, 0x30BC, 0x2222, 0x51C8, 0xFFFA) # tile 2: colour 2 code += _w(0x22BC, 0x4000, 0x0003) # VRAM write $C000: the plane code += _w(0x303C, 0x03FF, 0x30BC, 0x0001, 0x51C8, 0xFFFA) # rows 0-15: tile 1 code += _w(0x303C, 0x03FF, 0x30BC, 0x0002, 0x51C8, 0xFFFA) # rows 16-31: tile 2 code += _w(0x22BC, 0x4000, 0x0010) # VSRAM write 0 code += _w(0x30BC, 0x0000, 0x30BC, 0x0000) code += _w(0x32BC, 0x8144) # display on code += _w(0x7800, 0x7200) # moveq #0,d4; moveq #0,d1 loop = bytearray() loop += _w(0x1012) # L0: move.b (a2),d0 the V counter loop += _w(0xB001) # cmp.b d1,d0 loop += _w(0x67FA) # beq.s L0 loop += _w(0x1200) # move.b d0,d1 loop += _w(0x3400) # move.w d0,d2 loop += _w(0x0242, 0x003F) # andi.w #63,d2 loop += _w(0x51CA, 0xFFFE) # D: dbra d2,D loop += _w(0x22BC, 0x4000 if plane == "A" else 0x4002, 0x0010) # VSRAM word 0 or 1 loop += _w(0x1801) # move.b d1,d4 loop += _w(0x0244, 0x0001) # andi.w #1,d4 loop += _w(0xEF4C) # lsl.w #7,d4 (V & 1) << 7 loop += _w(0x3084) # move.w d4,(a0) assert len(loop) == 34 loop += _w(0x60DC) # bra.s L0 code += loop return nuked_md_cartridge(bytes(code)) def nuked_md_cartridge(code: bytes) -> bytes: rom = bytearray(0x10000) rom[0:4] = (0x00FFFE00).to_bytes(4, "big") rom[4:8] = (0x00000200).to_bytes(4, "big") for vector in range(2, 64): # every exception halts, so a fault is loud rom[vector * 4 : vector * 4 + 4] = (0x000001F0).to_bytes(4, "big") rom[0x1F0:0x1F4] = bytes.fromhex("4e722700") # stop #$2700 rom[0x100:0x110] = b"SEGA GENESIS " rom[0x200 : 0x200 + len(code)] = code return bytes(rom) def main() -> int: import run_vscroll_pins sys.argv[1:] = ["--full-screen", *sys.argv[1:]] return run_vscroll_pins.main() if __name__ == "__main__": sys.exit(main())