"""M2's exit test: pictures equal to both detectors by colour index, and the Final Test Cartridge's own verdict. Detector pictures (git-ignored, made by the Phase 0 runs of docs/mame-oracle.md and docs/validation.md): MAME 0.285 snapshots after 2 s (no cartridge) and 5 s (Zaxxon, Final Test); Gearcoleco frames after 300 frames. Gearcoleco refuses an image without a header, so the no-cartridge screen is compared with MAME only. """ from __future__ import annotations import pytest from conftest import ROOT, TRACES, cart from colecovision_python import BoardOptions, ColecoVision, mame_options from colecovision_python.pictures import detector_indices, differences RUNS = ROOT / "tests" / "runs" CASES = { "nocart": (None, 119, [TRACES / "coleco-nocart/snap/coleco/0000.png"]), "zaxxon": ( "Zaxxon (USA, Europe)", 299, [TRACES / "coleco-Zaxxon/snap/coleco/0000.png", RUNS / "gearcoleco-zaxxon-300.png"], ), "finaltest": ( "Final Test Cartridge (USA)", 299, [ TRACES / "coleco-Final_Test_Cartridge/snap/coleco/0000.png", RUNS / "gearcoleco-finaltest-300.png", ], ), } @pytest.mark.slow @pytest.mark.parametrize("options", [BoardOptions(), mame_options()], ids=["default", "mame"]) @pytest.mark.parametrize("case", sorted(CASES)) def test_picture_equals_detectors(bios, case, options): title, frames, pictures = CASES[case] pictures = [p for p in pictures if p.exists()] if not pictures: pytest.skip("no detector pictures") console = ColecoVision(cart(title) if title else None, bios=bios, options=options) frame = console.run_frames(frames) for picture in pictures: assert differences(frame.pixels, detector_indices(picture)) == 0, picture def test_comparison_can_fail(bios): """Seeded fault: the no-cartridge frame against Zaxxon's picture.""" picture = TRACES / "coleco-Zaxxon/snap/coleco/0000.png" if not picture.exists(): pytest.skip("no detector picture") frame = ColecoVision(bios=bios).run_frames(119) assert differences(frame.pixels, detector_indices(picture)) > 1000 def final_test_text(console, rows): """The Final Test Cartridge's screen as text: its name bytes are space 0, digits 1-10, letters from $0B (read off its name table: 'ROM' is 1C 19 17).""" vdp = console.board.vdp base = (vdp.regs[2] & 0x0F) << 10 out = [] for row in rows: chars = [] for byte in vdp.vram[base + row * 32 : base + row * 32 + 32]: if byte == 0: chars.append(" ") elif byte <= 10: chars.append(str(byte - 1)) elif byte <= 0x0B + 25: chars.append(chr(ord("A") + byte - 0x0B)) else: chars.append("?") out.append(" ".join("".join(chars).split())) return out @pytest.mark.slow def test_final_test_cartridge_verdict(bios): console = ColecoVision(cart("Final Test Cartridge (USA)"), bios=bios) console.run_frames(299) assert final_test_text(console, (5, 6, 8)) == ["ROM CHECKSUM D483", "ROM GOOD", "RAM TEST RAM GOOD"]