# SPDX-License-Identifier: MIT """Rung 3: the games' built-in Cx4 test, item by item, in the board-free harness. Judge: the test itself (hardware-designed self-test: written to pass on production chips). Its expected values are read out of each cartridge's own 65816 test code (X2 USA ``13:F8B7``-``13:FBDA``, X3 USA ``05:F8C2``-``05:FBE5``) by ``harness.find_expectations``; nothing is typed in from an emulator. LDMAC (768 or 1,024 DMAs of 2 KiB, each summed by 0E:40: 19-25 million instructions) is marked slow. BYOR: the cartridges are read in place and the tests skip without them. """ from __future__ import annotations import pytest from hg51b_python.harness import ITEMS, find_expectations, mirror, selftest QUICK = tuple(item for item in ITEMS if item != "LDMAC") def test_mirror_like_ares() -> None: size = 0x180000 # 1.5 MiB assert mirror(0x17FFFF, size) == 0x17FFFF assert mirror(0x180000, size) == 0x100000 assert mirror(0x1FFFFF, size) == 0x17FFFF assert mirror(0x200000, 0x200000) == 0 @pytest.mark.parametrize("name", ["retail", "x3"]) def test_expectations_from_the_test_code(name: str, cartridge) -> None: expect = find_expectations(cartridge(name)) registers = dict(expect.interface) assert registers[0x7F50] == 0x44 and registers[0x7F51] == 0x01 and registers[0x7F52] == 0 assert (registers[0x7F49], registers[0x7F4A], registers[0x7F4B]) == (0x00, 0x80, 0x02) assert expect.immediate_rom == 0x054336 # the data ROM's byte sum (U21) assert expect.malu[0x5A:0x60] == bytes([1, 0, 0, 0, 0, 0]) # (-1)^2 = 1: R1 = ML, R2 = MH assert expect.constants[:6] == bytes([0, 0, 0, 0xFF, 0xFF, 0xFF]) # 50h, 51h assert expect.banks == (0x30 if name == "retail" else 0x40) @pytest.mark.parametrize("name", ["retail", "x3"]) def test_selftest_quick_items(name: str, cartridge) -> None: result = selftest(cartridge(name), items=QUICK) assert all(result.passed[item] for item in QUICK), result.lines() @pytest.mark.slow @pytest.mark.parametrize("name", ["retail", "x3"]) def test_selftest_ldmac(name: str, cartridge) -> None: result = selftest(cartridge(name), items=("LDMAC",)) assert result.passed["LDMAC"], result.lines()