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..9fca4a7b61b8 100644 --- a/SDL/SDLJoystick.cpp +++ b/SDL/SDLJoystick.cpp @@ -1,4 +1,5 @@ #include "SDL/SDLJoystick.h" +#include "Core/Config.h" #include @@ -16,13 +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); } - 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(){ diff --git a/SDL/SDLJoystick.h b/SDL/SDLJoystick.h index aac7f24f4925..9cbec8dc7f77 100644 --- a/SDL/SDLJoystick.h +++ b/SDL/SDLJoystick.h @@ -31,6 +31,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); +