Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atari 5200 and Nintendo 64 Game Controller Improvements #2367

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions Cores/Atari800/Sources/PVAtari800Bridge/PVAtari800Bridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,21 @@ final class PVAtari5200ControllerViewController: PVControllerViewController<PV52
var left:CGFloat = value.x < 0.5 ? CGFloat(1 - (value.x * 2)) : 0.0
var right:CGFloat = value.x > 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)
}
}

Expand Down
Loading