"""Unit tests for pure Galaxian two-plane graphics decoding.""" import pytest from galemu.video import ( GFX_PLANE_SIZE, GFX_ROM_SIZE, SPRITE_COUNT, TILE_COUNT, decode_sprites, decode_tiles, ) def test_tiles_decode_msb_first_and_keep_all_256_codes() -> None: graphics = bytearray(GFX_ROM_SIZE) offset = 0xFF * 8 + 3 graphics[offset] = 0b10000001 graphics[GFX_PLANE_SIZE + offset] = 0b01000001 tiles = decode_tiles(bytes(graphics)) assert len(tiles) == TILE_COUNT == 256 assert tiles[0xFF][3] == (1, 2, 0, 0, 0, 0, 0, 3) def test_sprites_decode_their_four_8x8_quadrants() -> None: graphics = bytearray(GFX_ROM_SIZE) offset = 0x3F * 32 graphics[offset] = 0x80 graphics[GFX_PLANE_SIZE + offset + 24 + 7] = 0x01 sprites = decode_sprites(bytes(graphics)) assert len(sprites) == SPRITE_COUNT == 64 assert sprites[0x3F][0][0] == 1 assert sprites[0x3F][15][15] == 2 assert sprites[0x3F][0][8] == 0 assert sprites[0x3F][8][0] == 0 @pytest.mark.parametrize("size", [0, GFX_ROM_SIZE - 1, GFX_ROM_SIZE + 1]) def test_graphics_decoders_require_the_complete_two_plane_region(size: int) -> None: graphics = bytes(size) with pytest.raises(ValueError, match="expected a 4096-byte graphics ROM"): decode_tiles(graphics) with pytest.raises(ValueError, match="expected a 4096-byte graphics ROM"): decode_sprites(graphics)