"""Shared fixtures: the BIOS (bring your own, found by SHA-1) and a tiny program host.""" from __future__ import annotations from pathlib import Path import pytest from colecovision_python import Board, PlainCartridge, mame_options from colecovision_python.images import NO_INTRO, load_bios, load_image from colecovision_python.machine import BIOS_PAL_SHA1 ROOT = Path(__file__).resolve().parent.parent TRACES = ROOT / "tests" / "mame_traces" @pytest.fixture(scope="session") def bios() -> bytes: try: return load_bios() except FileNotFoundError as error: pytest.skip(str(error)) @pytest.fixture(scope="session") def pal_bios() -> bytes: try: return load_bios(BIOS_PAL_SHA1) except FileNotFoundError as error: pytest.skip(str(error)) def cart(title: str) -> bytes: """A No-Intro image by its file stem, read in place; skips if absent.""" path = NO_INTRO / f"{title}.zip" if not path.exists(): pytest.skip(f"not in the library: {path}") return load_image(path) def program_board(code: bytes, *, at: int = 0x8000, options=None, **keywords) -> Board: """A board whose 'BIOS' jumps straight to ``code`` placed in a plain cartridge at ``at`` (no real BIOS needed): $0000 holds JP at.""" bios = bytearray(b"\xff" * 8192) bios[0:3] = bytes((0xC3, at & 0xFF, at >> 8)) image = bytearray(b"\xff" * 0x8000) image[at - 0x8000 : at - 0x8000 + len(code)] = code return Board(bytes(bios), PlainCartridge(bytes(image)), options=options or mame_options(), **keywords)