summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2014-04-08 02:33:19 +0000
committerSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2014-04-08 02:33:19 +0000
commitc875a3566e340e366553beb2dcd6b2bcf4d5ab18 (patch)
tree97dcfbe538af5f282135a27cf889ed32b1d9d54d /plugins
parent0d4ea9238b154a30e8713c7d00d7b6d1b0050d5c (diff)
DFInput: Implement SDL2 GameController support.
This change allows the user to use SDL2’s GameController API instead of the Joystick API. The Game Controller API maps the buttons similar to an Xbox 360 controller, so some tricky mapping needed to be done. Note that it currently only supports OS X. git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@89828 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'plugins')
-rwxr-xr-xplugins/dfinput/analog.c26
-rwxr-xr-xplugins/dfinput/pad.c31
-rwxr-xr-xplugins/dfinput/pad.h11
-rwxr-xr-xplugins/dfinput/sdljoy.c180
4 files changed, 193 insertions, 55 deletions
diff --git a/plugins/dfinput/analog.c b/plugins/dfinput/analog.c
index 7e236ead..ea89ab13 100755
--- a/plugins/dfinput/analog.c
+++ b/plugins/dfinput/analog.c
@@ -18,6 +18,15 @@
#include "pad.h"
+#if SDL_VERSION_ATLEAST(2,0,0)
+static SDL_GameControllerAxis PsxAxisMap[] = {
+ SDL_CONTROLLER_AXIS_LEFTX,
+ SDL_CONTROLLER_AXIS_LEFTY,
+ SDL_CONTROLLER_AXIS_RIGHTX,
+ SDL_CONTROLLER_AXIS_RIGHTY
+};
+#endif
+
void InitAnalog() {
g.PadState[0].AnalogStatus[ANALOG_LEFT][0] = 127;
g.PadState[0].AnalogStatus[ANALOG_LEFT][1] = 127;
@@ -42,6 +51,23 @@ void CheckAnalog() {
}
for (j = 0; j < ANALOG_TOTAL; j++) {
+#if SDL_VERSION_ATLEAST(2,0,0)
+ if (g.PadState[i].GCDev != NULL) {
+ for(k = 0; k < 2; k++) {
+ unsigned int absVal;
+ val = SDL_GameControllerGetAxis(g.PadState[i].GCDev, PsxAxisMap[j << 1 | k]);
+ absVal = abs(val);
+ if (absVal > 0) {
+ absVal += 32640;
+ absVal /= 256;
+ g.PadState[i].AnalogStatus[j][k] = val > 0 ? absVal : -absVal;
+ } else {
+ g.PadState[i].AnalogStatus[j][k] = 0;
+ }
+ }
+ continue;
+ }
+#endif
for (k = 0; k < 4; k++) {
if (g.PadState[i].AnalogKeyStatus[j][k]) {
switch (k) {
diff --git a/plugins/dfinput/pad.c b/plugins/dfinput/pad.c
index c0f72657..ba4ec0ab 100755
--- a/plugins/dfinput/pad.c
+++ b/plugins/dfinput/pad.c
@@ -25,6 +25,27 @@
#if SDL_VERSION_ATLEAST(2,0,0)
int has_haptic;
+
+SDL_GameControllerButton controllerMap[] = {
+ SDL_CONTROLLER_BUTTON_BACK,
+ SDL_CONTROLLER_BUTTON_LEFTSTICK,
+ SDL_CONTROLLER_BUTTON_RIGHTSTICK,
+ SDL_CONTROLLER_BUTTON_START,
+ SDL_CONTROLLER_BUTTON_DPAD_UP,
+ SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
+ SDL_CONTROLLER_BUTTON_DPAD_DOWN,
+ SDL_CONTROLLER_BUTTON_DPAD_LEFT,
+ SDL_CONTROLLER_BUTTON_INVALID, //SDL2 doesn't map the bumpers to buttons, but axies
+ SDL_CONTROLLER_BUTTON_INVALID, //The bumpers are analogous to L2 and R2
+ SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
+ SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
+ SDL_CONTROLLER_BUTTON_Y,
+ SDL_CONTROLLER_BUTTON_B,
+ SDL_CONTROLLER_BUTTON_A,
+ SDL_CONTROLLER_BUTTON_X,
+
+ SDL_CONTROLLER_BUTTON_GUIDE
+};
#endif
static void (*gpuVisualVibration)(uint32_t, uint32_t) = NULL;
@@ -100,6 +121,8 @@ long PADopen(unsigned long *Disp) {
}
#if SDL_VERSION_ATLEAST(2,0,0)
+ SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
+
has_haptic = 0;
if (SDL_InitSubSystem(SDL_INIT_HAPTIC) == 0)
has_haptic = 1;
@@ -135,14 +158,16 @@ long PADclose(void) {
DestroySDLJoy();
DestroyKeyboard();
#if SDL_VERSION_ATLEAST(2,0,0)
- if (SDL_WasInit(SDL_INIT_EVERYTHING & ~(SDL_INIT_HAPTIC | SDL_INIT_JOYSTICK))) {
+ if (SDL_WasInit(SDL_INIT_EVERYTHING & ~(SDL_INIT_HAPTIC | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER))) {
SDL_QuitSubSystem(SDL_INIT_HAPTIC);
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
- } else
-#endif
+ SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
+ } else {
+#else
if (SDL_WasInit(SDL_INIT_EVERYTHING & ~SDL_INIT_JOYSTICK)) {
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
} else {
+#endif
SDL_Quit();
}
}
diff --git a/plugins/dfinput/pad.h b/plugins/dfinput/pad.h
index 205bae41..eb9217fa 100755
--- a/plugins/dfinput/pad.h
+++ b/plugins/dfinput/pad.h
@@ -38,6 +38,7 @@ extern "C" {
#include <SDL_joystick.h>
#if SDL_VERSION_ATLEAST(2,0,0)
#include <SDL_haptic.h>
+#include <SDL_gamecontroller.h>
#endif
#ifdef _MACOSX
@@ -147,12 +148,19 @@ typedef struct tagKeyDef {
enum { ANALOG_XP = 0, ANALOG_XM, ANALOG_YP, ANALOG_YM };
+#if SDL_VERSION_ATLEAST(2,0,0)
+SDL_GameControllerButton controllerMap[DKEY_TOTAL];
+#endif
+
typedef struct tagPadDef {
int8_t DevNum;
uint16_t Type;
uint8_t VisualVibration;
KEYDEF KeyDef[DKEY_TOTAL];
KEYDEF AnalogDef[ANALOG_TOTAL][4];
+#if SDL_VERSION_ATLEAST(2,0,0)
+ int8_t UseSDL2;
+#endif
} PADDEF;
typedef struct tagEmuDef {
@@ -188,7 +196,8 @@ typedef struct tagPadState {
uint8_t Vib0, Vib1;
volatile uint8_t VibF[2];
#if SDL_VERSION_ATLEAST(2,0,0)
- SDL_Haptic *haptic;
+ SDL_Haptic *haptic;
+ SDL_GameController *GCDev;
#else
#ifdef __linux__
int VibrateDev;
diff --git a/plugins/dfinput/sdljoy.c b/plugins/dfinput/sdljoy.c
index 2a763935..ee139517 100755
--- a/plugins/dfinput/sdljoy.c
+++ b/plugins/dfinput/sdljoy.c
@@ -18,44 +18,44 @@
#include "pad.h"
-#if SDL_VERSION_ATLEAST(2,0,0)
-static SDL_HapticEffect haptic_rumbleEffect;
-#endif
-
void JoyInitHaptic()
{
#if SDL_VERSION_ATLEAST(2,0,0)
- uint8_t i;
+ uint8_t i;
//unsigned int haptic_query = 0;
- for (i = 0; i < 2; i++)
- {
- if (g.PadState[i].JoyDev && SDL_JoystickIsHaptic(g.PadState[i].JoyDev))
- {
- if (g.PadState[i].haptic != NULL)
- {
- SDL_HapticClose(g.PadState[i].haptic);
- g.PadState[i].haptic = NULL;
- }
-
- g.PadState[i].haptic = SDL_HapticOpenFromJoystick(g.PadState[i].JoyDev);
- if (g.PadState[i].haptic == NULL)
- continue;
-
- if (SDL_HapticRumbleSupported(g.PadState[i].haptic) == SDL_FALSE)
- {
- printf("\nRumble not supported\n");
- g.PadState[i].haptic = NULL;
- continue;
- }
-
- if (SDL_HapticRumbleInit(g.PadState[i].haptic) != 0)
- {
- printf("\nFailed to initialize rumble: %s\n", SDL_GetError());
- g.PadState[i].haptic = NULL;
- continue;
- }
- }
- }
+ for (i = 0; i < 2; i++)
+ {
+ SDL_Joystick *curJoy = g.PadState[i].JoyDev;
+ if (!curJoy && g.PadState[i].GCDev) {
+ curJoy = SDL_GameControllerGetJoystick(g.PadState[i].GCDev);
+ }
+ if (SDL_JoystickIsHaptic(curJoy))
+ {
+ if (g.PadState[i].haptic != NULL)
+ {
+ SDL_HapticClose(g.PadState[i].haptic);
+ g.PadState[i].haptic = NULL;
+ }
+
+ g.PadState[i].haptic = SDL_HapticOpenFromJoystick(curJoy);
+ if (g.PadState[i].haptic == NULL)
+ continue;
+
+ if (SDL_HapticRumbleSupported(g.PadState[i].haptic) == SDL_FALSE)
+ {
+ printf("\nRumble not supported\n");
+ g.PadState[i].haptic = NULL;
+ continue;
+ }
+
+ if (SDL_HapticRumbleInit(g.PadState[i].haptic) != 0)
+ {
+ printf("\nFailed to initialize rumble: %s\n", SDL_GetError());
+ g.PadState[i].haptic = NULL;
+ continue;
+ }
+ }
+ }
#endif
}
@@ -84,14 +84,22 @@ int JoyHapticRumble(int pad, uint32_t low, uint32_t high)
void InitSDLJoy() {
uint8_t i;
- uint8_t emukeydev;
g.PadState[0].JoyKeyStatus = 0xFFFF;
g.PadState[1].JoyKeyStatus = 0xFFFF;
for (i = 0; i < 2; i++) {
if (g.cfg.PadDef[i].DevNum >= 0) {
+#if SDL_VERSION_ATLEAST(2,0,0)
+ if (g.cfg.PadDef[i].UseSDL2) {
+ g.PadState[i].GCDev = SDL_GameControllerOpen(g.cfg.PadDef[i].DevNum);
+ }
+
+ if (!g.PadState[i].GCDev) {
+ g.PadState[i].JoyDev = SDL_JoystickOpen(g.cfg.PadDef[i].DevNum);
+ }
+#else
g.PadState[i].JoyDev = SDL_JoystickOpen(g.cfg.PadDef[i].DevNum);
-
+#endif
// Saves an extra call to SDL joystick open
if (g.cfg.E.DevNum == g.cfg.PadDef[i].DevNum) {
g.cfg.E.EmuKeyDev = g.PadState[i].JoyDev;
@@ -106,10 +114,10 @@ void InitSDLJoy() {
}
#if SDL_VERSION_ATLEAST(2,0,0)
- if (has_haptic)
- {
- JoyInitHaptic();
- }
+ if (has_haptic)
+ {
+ JoyInitHaptic();
+ }
#endif
if (g.cfg.E.EmuKeyDev == 0 && g.cfg.E.DevNum >= 0) {
@@ -117,6 +125,9 @@ void InitSDLJoy() {
}
SDL_JoystickEventState(SDL_IGNORE);
+#if SDL_VERSION_ATLEAST(2,0,0)
+ SDL_GameControllerEventState(SDL_IGNORE);
+#endif
InitAnalog();
}
@@ -126,21 +137,31 @@ void DestroySDLJoy() {
if (SDL_WasInit(SDL_INIT_JOYSTICK)) {
for (i = 0; i < 2; i++) {
- if (g.PadState[i].JoyDev != NULL) {
#if SDL_VERSION_ATLEAST(2,0,0)
- if (g.PadState[i].haptic != NULL)
- {
- SDL_HapticClose(g.PadState[i].haptic);
- g.PadState[i].haptic = NULL;
- }
-#endif
+ if (g.PadState[i].JoyDev != NULL || g.PadState[i].GCDev != NULL) {
+ if (g.PadState[i].haptic != NULL) {
+ SDL_HapticClose(g.PadState[i].haptic);
+ g.PadState[i].haptic = NULL;
+ }
+ if (g.PadState[i].GCDev != NULL) {
+ SDL_GameControllerClose(g.PadState[i].GCDev);
+ } else {
+ SDL_JoystickClose(g.PadState[i].JoyDev);
+ }
+ }
+#else
+ if (g.PadState[i].JoyDev != NULL) {
SDL_JoystickClose(g.PadState[i].JoyDev);
}
+#endif
}
}
for (i = 0; i < 2; i++) {
g.PadState[i].JoyDev = NULL;
+#if SDL_VERSION_ATLEAST(2,0,0)
+ g.PadState[i].GCDev = NULL;
+#endif
}
g.cfg.E.EmuKeyDev = NULL;
}
@@ -167,14 +188,14 @@ static void bup(int pad, int bit)
void CheckJoy() {
uint8_t i, j, n;
+#if SDL_VERSION_ATLEAST(2,0,0)
+ SDL_GameControllerUpdate();
+#endif
SDL_JoystickUpdate();
for (i = 0; i < 2; i++) {
- if (g.PadState[i].JoyDev == NULL) {
- continue;
- }
-
+ if (g.PadState[i].JoyDev != NULL) {
g.PadState[i].JoyKeyStatus = ~0;
for (j = 0; j < DKEY_TOTAL; j++) {
switch (g.cfg.PadDef[i].KeyDef[j].JoyEvType) {
@@ -219,6 +240,63 @@ void CheckJoy() {
}
}
}
+
+#if SDL_VERSION_ATLEAST(2,0,0)
+ if (g.PadState[i].GCDev != NULL) {
+ g.PadState[i].JoyKeyStatus = ~0;
+ for (j = 0; j < DKEY_TOTAL; j++) {
+ Sint16 axis2;
+ switch (j) {
+ case DKEY_SELECT:
+ case DKEY_L3:
+ case DKEY_R3:
+ case DKEY_START:
+ case DKEY_UP:
+ case DKEY_RIGHT:
+ case DKEY_DOWN:
+ case DKEY_LEFT:
+ case DKEY_L1:
+ case DKEY_R1:
+ case DKEY_TRIANGLE:
+ case DKEY_CIRCLE:
+ case DKEY_CROSS:
+ case DKEY_SQUARE:
+ case DKEY_ANALOG:
+
+ if (SDL_GameControllerGetButton(g.PadState[i].GCDev, controllerMap[j])) {
+ bdown(i, j);
+ } else {
+ bup(i, j);
+ }
+ break;
+
+ case DKEY_L2:
+ axis2 = SDL_GameControllerGetAxis(g.PadState[i].GCDev, SDL_CONTROLLER_AXIS_TRIGGERLEFT);
+ if (axis2 > 0) {
+ bdown(i, j);
+ } else {
+ bup(i, j);
+ }
+
+ break;
+
+ case DKEY_R2:
+ axis2 = SDL_GameControllerGetAxis(g.PadState[i].GCDev, SDL_CONTROLLER_AXIS_TRIGGERRIGHT);
+ if (axis2 > 0) {
+ bdown(i, j);
+ } else {
+ bup(i, j);
+ }
+
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+#endif
+ }
// Check for emulator button states
for (i=(g.cfg.E.EmuKeyDev == NULL ? EMU_TOTAL : 0) ; i < EMU_TOTAL ; i++) {