# SPDX-License-Identifier: MIT """Where the vertical scroll is latched, fitted at the referee's RGB pins only. ``vdp.VSCROLL_LATCH_H`` (full-screen scroll, planes A and B) and ``vdp.VSCROLL_COLUMN_H`` (2-cell columns) were first placed with signals inside Nuked-MD, which the family's rules no longer allow (docs/provenance.md). This fits them again from the picture alone: the cartridges of ``run_vscroll_latch.py`` and ``run_vscroll_columns.py`` (a VSRAM word rewritten at a point that walks across each line, plane red over its top 128 rows and green below) run on the referee, Nuked-MD @ 594ca2a as a closed box, whose picture is read from its RGB output pins (``run_plane_sizes.referee_picture``); the board runs them with the latch where it stands and moved by ``--shifts`` H steps either way, and each is scored by the lines whose colour (red, green, or split) matches the referee's, best of board frames 9-14 (the two clocks are not one). ``OBSERVED``. With ``--fetch`` the same for plane A's tile fetches (``render.FETCH_AT``, placed first on Nuked-MD's VRAM pins but in its internal H counter): ``run_fetch_schedule.py``'s cartridge, a name rewritten at a point that walks across each line. python scripts/run_vscroll_pins.py [--shifts 4] [--jobs 4] [--fetch] """ from __future__ import annotations import argparse import sys from concurrent.futures import ProcessPoolExecutor from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path[:0] = [str(ROOT / "src"), str(ROOT / "scripts")] import run_plane_sizes as pictures # noqa: E402 RED, GREEN = (14, 0, 0), (0, 14, 0) PLOT_FRAME = 11 BOARD_FRAMES = range(9, 15) def classify(row) -> str: seen = {p for p in row if p in (RED, GREEN)} return "split" if len(seen) == 2 else ("red" if RED in seen else "green") def board_lines(rom: bytes, width: int, patch) -> list[list[str]]: from megadrive_python import vdp from megadrive_python.cartridge import Cartridge from megadrive_python.machine import MACHINES from megadrive_python.system import System from megadrive_python import render saved = (dict(vdp.VSCROLL_LATCH_H), dict(vdp.VSCROLL_COLUMN_H), dict(render.FETCH_AT)) patch(vdp) try: system = System(MACHINES["genesis"], Cartridge(rom)) system.board.fm.enabled = False frames = [] for frame in range(1, BOARD_FRAMES.stop): system.run_frame() if frame in BOARD_FRAMES: rgb = system.vdp.renderer.frame_rgb()[:224] colours = {0xFF0000: RED, 0x00FF00: GREEN} frames.append([classify([colours.get(p) for p in row[:width]]) for row in rgb]) return frames finally: vdp.VSCROLL_LATCH_H.clear() vdp.VSCROLL_LATCH_H.update(saved[0]) vdp.VSCROLL_COLUMN_H.clear() vdp.VSCROLL_COLUMN_H.update(saved[1]) render.FETCH_AT.clear() render.FETCH_AT.update(saved[2]) def cases(): import run_vscroll_columns as columns import run_vscroll_latch as latch out = [] for h40 in (True, False): for plane in ("A", "B"): out.append((f"full-screen {plane} {'H40' if h40 else 'H32'}", latch.cartridge(plane, h40), h40, "latch", 0 if plane == "A" else 1)) # fmt: skip for plane, h40, k in columns.CASES: out.append((f"column {k:2d} {plane} {'H40' if h40 else 'H32'}", columns.cartridge(k, plane, h40), h40, "column", (0 if plane == "A" else 1))) # fmt: skip return out def fetch_cases(): import run_fetch_schedule as fetch return [(f"fetch column {c:2d} {'H40' if h40 else 'H32'}", fetch.cartridge(c, h40), h40, "fetch", 0) for h40 in (True, False) for c in fetch.COLUMNS[h40]] # fmt: skip def shifted(kind: str, mode: str, index: int, d: int): def patch(vdp): if kind == "fetch": # plane A's three fetches together from megadrive_python import render a, b = render.FETCH_AT[mode] render.FETCH_AT[mode] = (tuple(x + d for x in a), b) elif kind == "latch": value = list(vdp.VSCROLL_LATCH_H[mode]) value[index] += d vdp.VSCROLL_LATCH_H[mode] = tuple(value) else: value = list(vdp.VSCROLL_COLUMN_H[mode]) first, per = value[index] value[index] = (first + d, per) vdp.VSCROLL_COLUMN_H[mode] = tuple(value) return patch def run(job) -> list[str]: name, rom, h40, kind, index, shifts = job width = 320 if h40 else 256 mode = "H40" if h40 else "H32" theirs = [classify(row) for row in pictures.referee_picture(rom, width, PLOT_FRAME)] out = [] for d in range(-shifts, shifts + 1): frames = board_lines(rom, width, shifted(kind, mode, index, d)) best = max(sum(1 for a, b in zip(theirs, f, strict=False) if a == b) for f in frames) out.append((d, best)) return name, out, len(theirs) def main() -> int: parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) parser.add_argument("--shifts", type=int, default=4) parser.add_argument("--jobs", type=int, default=4) parser.add_argument("--fetch", action="store_true", help="plane A's tile fetch times instead") parser.add_argument("--full-screen", action="store_true", help="the full-screen latch only") args = parser.parse_args() chosen = fetch_cases() if args.fetch else cases() if args.full_screen: chosen = [c for c in chosen if c[3] == "latch"] jobs = [(*c, args.shifts) for c in chosen] with ProcessPoolExecutor(args.jobs) as pool: for name, scores, lines in pool.map(run, jobs): here = dict(scores)[0] top = max(s for _, s in scores) bests = [d for d, s in scores if s == top] print(f"{name:22} as it stands {here}/{lines} lines; best {top} at shift " f"{bests}; " + " ".join(f"{d:+d}:{s}" for d, s in scores), flush=True) # fmt: skip return 0 if __name__ == "__main__": raise SystemExit(main())