Skip to content

Add Auto joystick mode: use gamepad when connected, else keypad - #51

Merged
digarok merged 2 commits into
mainfrom
joystick-auto-mode
Jul 6, 2026
Merged

Add Auto joystick mode: use gamepad when connected, else keypad#51
digarok merged 2 commits into
mainfrom
joystick-auto-mode

Conversation

@digarok

@digarok digarok commented Jul 6, 2026

Copy link
Copy Markdown
Owner

The default joystick type was Keypad, but gamepad buttons still leaked through to $C061/$C062 while the analog stick did nothing -- a connected gamepad appeared half-broken until the user manually selected Native Joystick 1 in the config menu.

Add joystick type 4 "Auto (Gamepad or Keypad)" and make it the default. Auto resolves at sample time via paddle_effective_joystick_type(): native joystick 1 when a device is connected, keypad otherwise. Nothing is stored, so hotplug switches modes live and config.kegs is untouched; explicitly saved types (0-3) keep their exact old meaning.

Also gate the gamepad button merge on the resolved type being native, so an explicit Keypad/Mouse selection now fully ignores the gamepad instead of accepting its buttons but not its axes. Keyboard Open/Closed-Apple is unaffected (ORed separately from ADB state). The keypad-key swallowing in adb.c uses the resolved type too, so the numeric keypad types numbers again while a gamepad is driving the joystick.

Additionally add's "circle-to-square" mapping for gamepads so they can hit 0,0 to 255,255.

digarok and others added 2 commits July 5, 2026 23:38
The default joystick type was Keypad, but gamepad buttons still leaked
through to $C061/$C062 while the analog stick did nothing -- a connected
gamepad appeared half-broken until the user manually selected Native
Joystick 1 in the config menu.

Add joystick type 4 "Auto (Gamepad or Keypad)" and make it the default.
Auto resolves at sample time via paddle_effective_joystick_type(): native
joystick 1 when a device is connected, keypad otherwise. Nothing is
stored, so hotplug switches modes live and config.kegs is untouched;
explicitly saved types (0-3) keep their exact old meaning.

Also gate the gamepad button merge on the resolved type being native, so
an explicit Keypad/Mouse selection now fully ignores the gamepad instead
of accepting its buttons but not its axes. Keyboard Open/Closed-Apple is
unaffected (ORed separately from ADB state). The keypad-key swallowing in
adb.c uses the resolved type too, so the numeric keypad types numbers
again while a gamepad is driving the joystick.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A modern analog stick's gate is circular: full diagonal deflection only
reports ~71% on each axis, so games expecting the square travel of real
Apple joysticks (paddle 0/255 at the corners) could never reach them.

Add paddle_map_circle_to_square(): a radial circle-to-square remap that
stretches each sample along its own direction -- identity on the pure
axes, growing to sqrt(2) at the diagonals -- so the circular rim lands
exactly on the square perimeter. Includes an 8% radial deadzone
(rescaled so travel is continuous and full deflection is unaffected)
and a final clamp for pads that overshoot the unit circle.

Applied centrally in paddle_update_trigger_dcycs() when the effective
joystick type is native, on a copy of the X/Y pair: some backends keep
g_paddle_val[] between samples, so remapping in place would compound
the stretch. Composes with the existing Scale/Trim/swap/invert options,
which apply downstream as before.

New config var g_joystick_square_range, exposed in the joystick menu as
"Gamepad Range: Square (Full Corners) / Circular (Raw)", default Square.
Link libm on Linux for sqrt().

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@digarok
digarok merged commit 420c7b1 into main Jul 6, 2026
5 checks passed
@digarok
digarok deleted the joystick-auto-mode branch July 6, 2026 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant