# SPDX-License-Identifier: MIT """The ProLine stick: one- and two-button modes chosen by the 6532's port B.""" from __future__ import annotations from a7800_python.board import EXT, LOCK, MEN, Board from a7800_python.cartridge.connector import Linear from a7800_python.controllers import LightGun, ProLine from a7800_python.machine import NTSC def setup(): board = Board(NTSC, Linear(bytes(0x4000)), None) board.inptctrl, board.locked = MEN | EXT | LOCK, True return board, ProLine(board.tia, board.riot) def inpt(board, n): return board.read_byte(0x08 + n) & 0x80 def test_one_button_mode_at_power(): board, sticks = setup() sticks.set(0, right_button=True) assert inpt(board, 4) == 0 and inpt(board, 0) == 0 # fire low on INPT4, pots quiet def test_two_button_mode_when_port_b_drives_the_line_low(): board, sticks = setup() board.write_byte(0x0283, 0x14) # SWBCNT: bits 2 and 4 outputs board.write_byte(0x0282, 0x00) # SWCHB: driven low sticks.set(0, left_button=True) assert inpt(board, 1) == 0x80 and inpt(board, 0) == 0 and inpt(board, 4) == 0x80 sticks.set(1, right_button=True) assert inpt(board, 2) == 0x80 def test_directions_on_port_a(): board, sticks = setup() sticks.set(0, up=True, left=True) sticks.set(1, right=True) assert board.read_byte(0x0280) == 0xFF & ~0x10 & ~0x40 & ~0x08 def test_light_gun_trigger_on_swcha_d4_and_sensor_on_inpt4(): board, _ = setup() gun = LightGun(board, 0) gun.set(aim=(100, 200), trigger=True) assert board.read_byte(0x0280) & 0x10 == 0 # the Barnyard Blaster / Crossbow read maria = board.maria maria.enabled, maria.vblank, maria.line = True, False, 101 maria.registers[0x00] = 0x0F # BACKGRND: luminance 15 everywhere maria.clock_in_line, maria._rendered = 210, 0 assert inpt(board, 4) == 0 # light seen: INPT4 low assert gun.hits == 1 maria.line, maria._rendered = 120, 0 assert inpt(board, 4) == 0x80 # beam far from the aim point maria.line, maria._rendered = 101, 0 maria.registers[0x00] = 0x02 # dark there: no light assert inpt(board, 4) == 0x80 def test_sound_tap_records_the_tia_twice_a_line(): from a7800_python.sound import SoundTap, tia_rate, wav_bytes board, _ = setup() tap = SoundTap(board).attach() board.inptctrl = MEN | EXT | LOCK board.write_byte(0x15, 0x04) # AUDC0: pure tone board.write_byte(0x17, 0x01) board.write_byte(0x19, 0x0F) # AUDV0 15 for _ in range(454 * 50 // 4): # 50 lines board.read_byte(0x8000) samples = tap.take() assert len(samples) in (99, 100) and max(samples) > 0.3 and min(samples) == 0.0 assert tap.tia == samples and tap.pokey == [0.0] * len(samples) # no POKEY on this cart assert abs(tia_rate(NTSC) - 31399.5) < 1 assert wav_bytes(samples, tia_rate(NTSC))[:4] == b"RIFF"