# SPDX-License-Identifier: MIT """scripts/run_32x.py when the console locks up before its first picture. Star Wars Arcade (USA) (Beta 3) in the No-Intro set holds one byte lane of its EPROMs, each byte twice ($8888A0A0 for every exception vector): its first exception jumps to $88A0A0, the 32X's area with ADEN = 0, and megadrive-python stops with ``Lockup`` in frame 1. The script then wrote the picture as far as it got, which in the first frame is no rows at all, and ``write_png`` raised IndexError (beta sweep, 2026-11-25). The script must report the lockup and exit 2, as for any other lockup. """ from __future__ import annotations import importlib.util import sys from pathlib import Path import pytest from conftest import STACK from megadrive_python.cartridge import Cartridge from sega32x_python import BootROMs from sega32x_python.console import build from sega32x_python.runner import Session SCRIPT = Path(__file__).resolve().parent.parent / "scripts" / "run_32x.py" def byte_lane_rom() -> bytes: """The reset vectors, then ILLEGAL at $200 with every other vector at $88A0A0.""" rom = bytearray(0x10000) rom[0:8] = STACK.to_bytes(4, "big") + (0x200).to_bytes(4, "big") for vector in range(2, 64): rom[4 * vector : 4 * vector + 4] = (0x8888A0A0).to_bytes(4, "big") rom[0x100:0x110] = b"SEGA 32X " rom[0x200:0x202] = bytes.fromhex("4afc") return bytes(rom) def test_a_lockup_in_the_first_frame_exits_2_without_a_picture( tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], user_boot_roms: BootROMs, ) -> None: spec = importlib.util.spec_from_file_location("run_32x_under_test", SCRIPT) assert spec is not None and spec.loader is not None script = importlib.util.module_from_spec(spec) spec.loader.exec_module(script) # The console the script builds (Session.start), without a file for the cartridge. system, device = build("genesis", Cartridge.from_image(byte_lane_rom()), user_boot_roms) monkeypatch.setattr(script.Session, "start", lambda *a, **k: Session(system, device)) out = tmp_path / "out" monkeypatch.setattr(sys, "argv", ["run_32x.py", "cart.32x", "--bios-dir", str(tmp_path), "--frames", "3", "--out", str(out)]) # fmt: skip assert script.main() == 2 printed = capsys.readouterr().out assert "frame 1: Lockup: 68000 read of $88A0A0" in printed assert "frame 1: no picture yet" in printed assert list(out.iterdir()) == []