From 7d191ccc11a3f0a1f18c4bf582655f2ba7c36e02 Mon Sep 17 00:00:00 2001 From: Kelly Youngblood Date: Sat, 3 Sep 2016 00:15:25 -0500 Subject: [PATCH 1/3] Adds --PS3 flag for PS3 controllr support on SDL. --- Core/Config.h | 1 + SDL/SDLJoystick.cpp | 6 +++++- SDL/SDLJoystick.h | 26 ++++++++++++++++++++++++++ UI/NativeApp.cpp | 2 ++ ext/native/base/NativeApp.h | 1 + 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Core/Config.h b/Core/Config.h index 119acebea97a..7b7d58014e59 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -121,6 +121,7 @@ struct Config { #if !defined(MOBILE_DEVICE) bool bPauseExitsEmulator; #endif + bool bPS3Controller; // Core bool bIgnoreBadMemAccess; diff --git a/SDL/SDLJoystick.cpp b/SDL/SDLJoystick.cpp index 7d654b8a25a7..be2c2212b8da 100644 --- a/SDL/SDLJoystick.cpp +++ b/SDL/SDLJoystick.cpp @@ -1,4 +1,5 @@ #include "SDL/SDLJoystick.h" +#include "Core/Config.h" #include @@ -16,7 +17,10 @@ SDLJoystick::SDLJoystick(bool init_SDL ): thread(NULL), running(true) { SDL_setenv("SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS", "1", 0); SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO); } - fillMapping(); + if (g_Config.bPS3Controller) + fillMappingPS3(); + else + fillMapping(); int numjoys = SDL_NumJoysticks(); SDL_JoystickEventState(SDL_ENABLE); diff --git a/SDL/SDLJoystick.h b/SDL/SDLJoystick.h index aac7f24f4925..807dff33a986 100644 --- a/SDL/SDLJoystick.h +++ b/SDL/SDLJoystick.h @@ -15,6 +15,8 @@ #include "net/resolve.h" #include "base/NativeApp.h" +#define _PS3_ true + extern "C" { int SDLJoystickThreadWrapper(void *SDLJoy); } @@ -31,6 +33,30 @@ class SDLJoystick{ private: void runLoop(); + void fillMappingPS3() + { + SDLJoyButtonMap[14] = NKCODE_BUTTON_1; // Cross + SDLJoyButtonMap[13] = NKCODE_BUTTON_2; // Circle + SDLJoyButtonMap[15] = NKCODE_BUTTON_3; // Sqlare + SDLJoyButtonMap[12] = NKCODE_BUTTON_4; // Triangle + SDLJoyButtonMap[10] = NKCODE_BUTTON_5; // L1 + SDLJoyButtonMap[11] = NKCODE_BUTTON_6; // R1 + SDLJoyButtonMap[8] = NKCODE_BUTTON_7; // L2 + SDLJoyButtonMap[9] = NKCODE_BUTTON_8; // R2 + SDLJoyButtonMap[0] = NKCODE_BUTTON_9; // Select + SDLJoyButtonMap[3] = NKCODE_BUTTON_10; // Start + SDLJoyButtonMap[1] = NKCODE_BUTTON_11; // L3 + SDLJoyButtonMap[2] = NKCODE_BUTTON_12; // R3 + SDLJoyButtonMap[16] = NKCODE_BUTTON_13; // PS + SDLJoyButtonMap[4] = NKCODE_DPAD_UP; + SDLJoyButtonMap[6] = NKCODE_DPAD_DOWN; + SDLJoyButtonMap[7] = NKCODE_DPAD_LEFT; + SDLJoyButtonMap[5] = NKCODE_DPAD_RIGHT; + SDLJoyAxisMap[0] = JOYSTICK_AXIS_X; + SDLJoyAxisMap[1] = JOYSTICK_AXIS_Y; + SDLJoyAxisMap[2] = JOYSTICK_AXIS_Z; + SDLJoyAxisMap[3] = JOYSTICK_AXIS_RZ; + } void fillMapping() { //TODO: C++11 aggregate initialization diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 048a235c8a66..da7b29667ecd 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -415,6 +415,8 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch fileToLog = argv[i] + strlen("--log="); if (!strncmp(argv[i], "--state=", strlen("--state=")) && strlen(argv[i]) > strlen("--state=")) stateToLoad = argv[i] + strlen("--state="); + if (!strncmp(argv[1], "--PS3", strlen("--PS3"))) + g_Config.bPS3Controller = true; #if !defined(MOBILE_DEVICE) if (!strncmp(argv[i], "--escape-exit", strlen("--escape-exit"))) g_Config.bPauseExitsEmulator = true; diff --git a/ext/native/base/NativeApp.h b/ext/native/base/NativeApp.h index b9de74d0952c..37fbff1c586d 100644 --- a/ext/native/base/NativeApp.h +++ b/ext/native/base/NativeApp.h @@ -175,3 +175,4 @@ enum SystemProperty { std::string System_GetProperty(SystemProperty prop); int System_GetPropertyInt(SystemProperty prop); + From 06d594b3ffdc11f1973f051de23f6132427eee95 Mon Sep 17 00:00:00 2001 From: Kelly Youngblood Date: Sat, 3 Sep 2016 00:20:18 -0500 Subject: [PATCH 2/3] Code cleanup --- SDL/SDLJoystick.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/SDL/SDLJoystick.h b/SDL/SDLJoystick.h index 807dff33a986..9cbec8dc7f77 100644 --- a/SDL/SDLJoystick.h +++ b/SDL/SDLJoystick.h @@ -15,8 +15,6 @@ #include "net/resolve.h" #include "base/NativeApp.h" -#define _PS3_ true - extern "C" { int SDLJoystickThreadWrapper(void *SDLJoy); } From 5adaa122606c98d9388e518576a7e139b12a4699 Mon Sep 17 00:00:00 2001 From: Kelly Youngblood Date: Sat, 3 Sep 2016 21:14:44 -0500 Subject: [PATCH 3/3] Adds auto-detection for PS3 cocntroller. --- SDL/SDLJoystick.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/SDL/SDLJoystick.cpp b/SDL/SDLJoystick.cpp index be2c2212b8da..9fca4a7b61b8 100644 --- a/SDL/SDLJoystick.cpp +++ b/SDL/SDLJoystick.cpp @@ -17,16 +17,22 @@ SDLJoystick::SDLJoystick(bool init_SDL ): thread(NULL), running(true) { SDL_setenv("SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS", "1", 0); SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO); } - if (g_Config.bPS3Controller) - fillMappingPS3(); - else - fillMapping(); int numjoys = SDL_NumJoysticks(); SDL_JoystickEventState(SDL_ENABLE); for (int i = 0; i < numjoys; i++) { joys.push_back(SDL_JoystickOpen(i)); +// printf("Initialized joystick %d: %s",i,SDL_JoystickNameForIndex(i)); + if(strstr(SDL_JoystickNameForIndex(i),"PLAYSTATION(R)3 Controller")) + g_Config.bPS3Controller = true; } + + if (g_Config.bPS3Controller) + fillMappingPS3(); + else + fillMapping(); + + } SDLJoystick::~SDLJoystick(){