# SPDX-License-Identifier: MIT """Shared fixtures: BYOR cartridges read in place from the No-Intro set. The set is found through ``NO_INTRO_DIR`` (its "Nintendo - Super Nintendo Entertainment System" directory) or ``SNES_NO_INTRO`` (that directory itself); tests that need a cartridge skip when it is absent. Nothing is copied or committed. """ from __future__ import annotations import os import zipfile from pathlib import Path import pytest NO_INTRO = Path( os.environ.get("SNES_NO_INTRO") or Path(os.environ.get("NO_INTRO_DIR", "")) / "Nintendo - Super Nintendo Entertainment System" ) # the player's own No-Intro set: SNES_NO_INTRO, or NO_INTRO_DIR's SNES directory CARTRIDGES = { "retail": "Mega Man X2 (USA)", "x3": "Mega Man X3 (USA)", "beta": "Rockman X2 (Japan) (Beta 1)", } def cartridge_path(name: str) -> Path: path = NO_INTRO / f"{CARTRIDGES[name]}.zip" if not path.exists(): pytest.skip(f"BYOR: {path} is absent") return path def cartridge_bytes(name: str) -> bytes: with zipfile.ZipFile(cartridge_path(name)) as archive: member = next(n for n in archive.namelist() if n.lower().endswith((".sfc", ".smc"))) return archive.read(member) @pytest.fixture def cartridge(): return cartridge_bytes @pytest.fixture def cartridge_file(): return cartridge_path @pytest.fixture def program_words(): def words(name: str) -> list[int]: rom = cartridge_bytes(name) region = rom[0x10000:0x12000] # SNES 02:8000-9FFF in LoROM order return [region[i] | region[i + 1] << 8 for i in range(0, len(region), 2)] return words