From 1149fee96939ca3df8fe302c23c3fed9298271d7 Mon Sep 17 00:00:00 2001 From: pqsk <3964831+pabloarista@users.noreply.github.com> Date: Sun, 29 Dec 2024 18:41:09 -0500 Subject: [PATCH] Fixed Atari 5200 game controller missing left stick for control as an alternate to the d-pad, also added mapping for 1-8,* and # buttons Fixed Atari 5200 virtual game controller missing functionality of the joystick Nintendo 64 swapped the start and z buttons so it's more natural as the OG nintendo 64 controller (z left fingher, start right finger) --- .../PVAtari800Bridge/PVAtari800Bridge.m | 45 ++++++++++++++++--- .../PVMupenBridge/PVMupenBridge+Controls.m | 11 +++-- .../PVAtari5200ControllerViewController.swift | 27 +++++------ 3 files changed, 57 insertions(+), 26 deletions(-) diff --git a/Cores/Atari800/Sources/PVAtari800Bridge/PVAtari800Bridge.m b/Cores/Atari800/Sources/PVAtari800Bridge/PVAtari800Bridge.m index f90463da62..4cbc42270b 100644 --- a/Cores/Atari800/Sources/PVAtari800Bridge/PVAtari800Bridge.m +++ b/Cores/Atari800/Sources/PVAtari800Bridge/PVAtari800Bridge.m @@ -688,17 +688,17 @@ - (void)pollControllers { GCExtendedGamepad *gamepad = [controller extendedGamepad]; GCControllerDirectionPad *dpad = [gamepad dpad]; - // D-Pad - self.controllerStates[playerIndex].up = dpad.up.isPressed; - self.controllerStates[playerIndex].down = dpad.down.isPressed; - self.controllerStates[playerIndex].left = dpad.left.isPressed; - self.controllerStates[playerIndex].right = dpad.right.isPressed; + // D-Pad/Left thunb stick + self.controllerStates[playerIndex].up = dpad.up.isPressed || gamepad.leftThumbstick.up.isPressed; + self.controllerStates[playerIndex].down = dpad.down.isPressed || gamepad.leftThumbstick.down.isPressed; + self.controllerStates[playerIndex].left = dpad.left.isPressed || gamepad.leftThumbstick.left.isPressed; + self.controllerStates[playerIndex].right = dpad.right.isPressed || gamepad.leftThumbstick.right.isPressed; // Fire 1 - self.controllerStates[playerIndex].fire = gamepad.buttonA.isPressed || gamepad.buttonY.isPressed || gamepad.leftTrigger.isPressed; + self.controllerStates[playerIndex].fire = gamepad.buttonA.isPressed; // Fire 2 - INPUT_key_shift = gamepad.buttonB.isPressed || gamepad.buttonX.isPressed || gamepad.rightTrigger.isPressed; + INPUT_key_shift = gamepad.buttonB.isPressed; // The following buttons are on a shared bus. Only one at a time. // If none, state is reset. Since only one button can be registered @@ -715,9 +715,40 @@ - (void)pollControllers { // Reset else if (gamepad.leftShoulder.isPressed) { INPUT_key_code = AKEY_5200_RESET; + } else if (gamepad.leftTrigger.isPressed) { + //* button + INPUT_key_code = AKEY_5200_ASTERISK; + } else if (gamepad.rightTrigger.isPressed) { + //# button + INPUT_key_code = AKEY_5200_HASH; + } else if (gamepad.rightThumbstick.left.isPressed) { + //1 button + INPUT_key_code = AKEY_5200_1; + } else if (gamepad.rightThumbstick.up.isPressed) { + //2 button + INPUT_key_code = AKEY_5200_2; + } else if (gamepad.rightThumbstick.right.isPressed) { + //3 button + INPUT_key_code = AKEY_5200_3; + } else if (gamepad.rightThumbstick.down.isPressed) { + //4 button + INPUT_key_code = AKEY_5200_4; + } else if (gamepad.leftThumbstickButton.isPressed) { + //5 button + INPUT_key_code = AKEY_5200_5; + } else if (gamepad.rightThumbstickButton.isPressed) { + //6 button + INPUT_key_code = AKEY_5200_6; + } else if (gamepad.buttonX.isPressed) { + //7 button + INPUT_key_code = AKEY_5200_7; + } else if (gamepad.buttonY.isPressed) { + //8 button + INPUT_key_code = AKEY_5200_8; } else { INPUT_key_code = AKEY_NONE; } + //ran out of buttons for 9 and 0, but an idea would be to add an option for the user to use those while sacrificing either the left stick or the dpad to have those buttons. } #if TARGET_OS_TV else if ([controller microGamepad]) { diff --git a/Cores/Mupen64Plus/Sources/PVMupenBridge/PVMupenBridge+Controls.m b/Cores/Mupen64Plus/Sources/PVMupenBridge/PVMupenBridge+Controls.m index e7e41936c7..0af4b9cb6f 100644 --- a/Cores/Mupen64Plus/Sources/PVMupenBridge/PVMupenBridge+Controls.m +++ b/Cores/Mupen64Plus/Sources/PVMupenBridge/PVMupenBridge+Controls.m @@ -235,6 +235,9 @@ - (void)pollController:(GCController* _Nullable)controller forIndex:(NSInteger)p if (dualSense) { padData[playerIndex][PVN64ButtonStart] = dualSense.touchpadButton.touched; + } else if (gamepad.rightThumbstickButton != nil) { + //fallback for non-dual sense only if the R3 button exists on the controller + padData[playerIndex][PVN64ButtonStart] = gamepad.rightThumbstickButton.isPressed; } } else { if (dualSense) { @@ -243,11 +246,11 @@ - (void)pollController:(GCController* _Nullable)controller forIndex:(NSInteger)p // DualShock-Either Trigger → Z padData[playerIndex][PVN64ButtonZ] = gamepad.leftTrigger.isPressed || gamepad.rightTrigger.isPressed; } else { - // MFi-L2 → Start - padData[playerIndex][PVN64ButtonStart] = gamepad.leftTrigger.isPressed; + // MFi-R2 → Start + padData[playerIndex][PVN64ButtonStart] = gamepad.rightTrigger.isPressed; - // MFi-R2 → Z - padData[playerIndex][PVN64ButtonZ] = gamepad.rightTrigger.isPressed; + // MFi-L2 → Z + padData[playerIndex][PVN64ButtonZ] = gamepad.leftTrigger.isPressed; } } diff --git a/PVUI/Sources/PVUIBase/Controller/Systems/PVAtari5200ControllerViewController.swift b/PVUI/Sources/PVUIBase/Controller/Systems/PVAtari5200ControllerViewController.swift index 3e10eba2d1..287c894cbf 100644 --- a/PVUI/Sources/PVUIBase/Controller/Systems/PVAtari5200ControllerViewController.swift +++ b/PVUI/Sources/PVUIBase/Controller/Systems/PVAtari5200ControllerViewController.swift @@ -43,24 +43,21 @@ final class PVAtari5200ControllerViewController: PVControllerViewController 0.5 ? CGFloat((value.x - 0.5) * 2) : 0.0 - up = min(up, 1.0) - down = min(down, 1.0) - left = min(left, 1.0) - right = min(right, 1.0) - - up = max(up, 0.0) - down = max(down, 0.0) - left = max(left, 0.0) - right = max(right, 0.0) - - // print("x: \(value.x) , y: \(value.y), up:\(up), down:\(down), left:\(left), right:\(right), ") - emulatorCore.didMoveJoystick(.up, withValue: up, forPlayer: 0) + emulatorCore.didRelease(.up, forPlayer: 0) + emulatorCore.didRelease(.down, forPlayer: 0) + emulatorCore.didRelease(.left, forPlayer: 0) + emulatorCore.didRelease(.right, forPlayer: 0) + if up != 0 { + emulatorCore.didPush(.up, forPlayer: 0) + } + if left != 0 { + emulatorCore.didPush(.left, forPlayer: 0) + } if down != 0 { - emulatorCore.didMoveJoystick(.down, withValue: down, forPlayer: 0) + emulatorCore.didPush(.down, forPlayer: 0) } - emulatorCore.didMoveJoystick(.left, withValue: left, forPlayer: 0) if right != 0 { - emulatorCore.didMoveJoystick(.right, withValue: right, forPlayer: 0) + emulatorCore.didPush(.right, forPlayer: 0) } }