# SPDX-License-Identifier: MIT """Milestone 1, exit (b): the BIOS picks the mode, on both BIOS rows. The BIOS's own test (cartridge/bios_test.py) is fast and runs always; the whole-board runs (the real BIOS on this board until INPTCTRL selects a mode) are marked slow. The NTSC BIOS needs MARIA's DLIs to finish its signature check (it waits on $F0, which its NMI routine sets), so a 7800 image on the NTSC row reaches 7800 mode only from milestone 2 on. """ from __future__ import annotations import pytest from conftest import A2600, LICENSED, read_zip from a7800_python.board import EXT, LOCK, MEN from a7800_python.cartridge.bios_test import bios_verdict from a7800_python.cartridge.connector import Cartridge, Linear from a7800_python.machine import NTSC, PAL from a7800_python.system import System class Plain2600(Cartridge): """A 2K/4K 2600 cartridge on the middle 24 contacts: it answers where A12 is high.""" def __init__(self, rom: bytes) -> None: self.rom = rom def access(self, address, data, read, halt, t): if read and address & 0x1000: return self.rom[address % len(self.rom)] return None @pytest.mark.parametrize("row", ["ntsc", "pal"]) def test_bios_test_verdicts(row, ntsc_bios, pal_bios): bios = ntsc_bios if row == "ntsc" else pal_bios assert bios_verdict(bios, read_zip(LICENSED / "Asteroids (USA).zip")) == "7800" assert bios_verdict(bios, read_zip(A2600 / "Combat (Europe).zip")) == "2600" # the NTSC BIOS refuses a PAL cartridge by its region byte; the PAL BIOS takes it (C8) expected = "2600" if row == "ntsc" else "7800" assert bios_verdict(bios, read_zip(LICENSED / "Centipede (Europe).zip")) == expected def run_to_mode(system: System, frames: int) -> None: board = system.board system.run_until( lambda: board.locked or (system.mode == "7800" and 0x4000 <= system.cpu.pc < 0xF000), max_clocks=system.machine.frame_clocks * frames, ) @pytest.mark.slow @pytest.mark.parametrize("machine", [NTSC, PAL], ids=["ntsc", "pal"]) def test_bios_locks_a_2600_image_into_2600_mode(machine): system = System(Plain2600(read_zip(A2600 / "Combat (Europe).zip")), machine) run_to_mode(system, 60) board = system.board assert board.locked and board.inptctrl & (LOCK | MEN | EXT) == LOCK | EXT assert system.mode == "2600" # The lock holds: the 2600 program's own TIA writes must not reach the latch. latch = board.inptctrl system.run_frames(2) assert board.inptctrl == latch @pytest.mark.slow def test_pal_bios_starts_a_7800_image_in_7800_mode(): system = System(Linear(read_zip(LICENSED / "Centipede (Europe).zip")), PAL) run_to_mode(system, 60) assert system.mode == "7800" and system.board.inptctrl & (MEN | EXT) == MEN | EXT