"""Pure input and sound-device routing tests for the Galaxian parent board.""" import pytest from galemu.devices import SoundEvent, decode_sound_write, route_input def test_input_routing_sets_and_clears_active_high_controls_without_touching_dips() -> None: idle_ports = (0x00, 0x00, 0x04) pressed = route_input(idle_ports, "player_1_fire", True) assert pressed == (0x10, 0x00, 0x04) assert route_input(pressed, "player_1_fire", False) == idle_ports def test_input_routing_preserves_other_controls_and_routes_cocktail_inputs() -> None: ports = route_input((0x00, 0x00, 0x04), "coin_1", True) assert route_input(ports, "player_2_right", True) == (0x01, 0x08, 0x04) @pytest.mark.parametrize( ("ports", "control", "message"), [ ((0x00, 0x00), "coin_1", "ports must contain exactly three byte values"), ((0x00, 0x100, 0x04), "coin_1", "ports must contain exactly three byte values"), ((0x00, 0x00, 0x04), "jump", "unknown Galaxian control: jump"), ], ) def test_input_routing_rejects_invalid_state_or_control( ports: tuple[int, ...], control: str, message: str ) -> None: with pytest.raises(ValueError, match=message): route_input(ports, control, True) # type: ignore[arg-type] @pytest.mark.parametrize( ("address", "value", "expected"), [ (0x6006, 0x03, SoundEvent("sound_background_resistor", 1, 2)), (0x6FF9, 0x00, SoundEvent("sound_tone_enable", 0, 1)), (0x6803, 0x01, SoundEvent("sound_hit", 1)), (0x6805, 0x01, SoundEvent("sound_fire", 1)), (0x6807, 0x02, SoundEvent("sound_volume", 0, 1)), (0x7FFF, 0x42, SoundEvent("sound_pitch", 0x42)), ], ) def test_sound_writes_decode_to_semantic_events( address: int, value: int, expected: SoundEvent ) -> None: assert decode_sound_write(address, value) == expected def test_unconnected_sound_address_remains_visible_as_an_unused_event() -> None: assert decode_sound_write(0x6804, 0x01) == SoundEvent("sound_unused", 1) @pytest.mark.parametrize( ("address", "value", "message"), [ (-1, 0, "address must be a 16-bit value"), (0x10000, 0, "address must be a 16-bit value"), (0, 0x100, "value must be a byte"), ], ) def test_sound_decoder_rejects_out_of_range_values(address: int, value: int, message: str) -> None: with pytest.raises(ValueError, match=message): decode_sound_write(address, value)