# SPDX-License-Identifier: MIT """The controller models on a synthetic board (no ROM needed).""" from __future__ import annotations from helpers import fake_board from a5200_python.controllers import Controllers, TrakBall def test_trakball_speed_maps_to_deflection_through_the_lag(): ball = TrakBall() for _ in range(30): x, y = ball.step(TrakBall.full_speed * 2, -TrakBall.full_speed / 2, calibrating=False) assert abs(x - (TrakBall.centre + TrakBall.span)) < 0.01 # clamped full right assert abs(y - (TrakBall.centre - TrakBall.span / 2)) < 0.01 # half up x, _ = ball.step(0.0, 0.0, calibrating=False) assert TrakBall.centre < x < TrakBall.centre + TrakBall.span # decays, not jumps def test_trakball_calibrates_to_centre_with_consol_bit2_low(): ball = TrakBall() for _ in range(30): x, _ = ball.step(TrakBall.full_speed, 0.0, calibrating=True) assert abs(x - TrakBall.centre) < 0.01 def test_consol_bit2_low_cuts_a_stick_but_not_a_trakball(): board = fake_board() controllers = Controllers(board) controllers.pads[1].trakball = True board.gtia.consol_out = 0 # pot power off controllers.apply() assert controllers._trak_pins[2:4] == [True, True] assert controllers._trak_pins[0:2] == [False, False] assert controllers.pot_level(0) is False # the stick on port 1 never crosses