# SPDX-License-Identifier: MIT """Milestone 6: the palettes (each with its origin) and the a2600-play window, headless.""" from __future__ import annotations import pytest from conftest import image_4k from a2600_python.machine import MACHINES from a2600_python.palettes import PALETTES # VSYNC for three lines, COLUBK $5A, 255 more lines, again. FRAME_LOOP = bytes.fromhex("a9028500850285028502a9008500a95a8509a2ff8502cad0fb4c00f0") def test_every_palette_has_128_colours_and_says_where_it_comes_from(): for palette in PALETTES.values(): assert len(palette.colours) == 128 assert palette.origin for machine in MACHINES.values(): assert machine.palette in PALETTES def test_palette_structure_follows_nocash(): ntsc, pal, secam = PALETTES["ntsc"], PALETTES["pal"], PALETTES["secam"] r, g, b = ntsc.rgb(0x0E) assert r == g == b # hue 0 is grey # PAL colours 1, 14 and 15 are "same as color 0". for hue in (1, 14, 15): assert pal.rgb(hue << 4 | 0x06) == pal.rgb(0x06) # SECAM ignores the hue: luminance 1 is blue, 2 red, 7 white. assert secam.rgb(0x32) == (0, 0, 255) and secam.rgb(0xF4) == (255, 0, 0) assert secam.rgb(0x0E) == (255, 255, 255) def test_the_window_runs_headless_and_saves_its_last_frame(tmp_path, monkeypatch): pytest.importorskip("pygame") monkeypatch.setenv("SDL_VIDEODRIVER", "dummy") monkeypatch.setenv("SDL_AUDIODRIVER", "dummy") from a2600_python import play rom = tmp_path / "loop.bin" rom.write_bytes(image_4k(FRAME_LOOP)) shot = tmp_path / "shot.png" assert play.main([str(rom), "--frames", "3", "--scale", "1", "--screenshot", str(shot)]) == 0 assert shot.stat().st_size > 0