Add Auto joystick mode: use gamepad when connected, else keypad - #51
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.