From 6ff3e5ebff50dd62c9644ca20628a11faee173fb Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Thu, 2 Jan 2014 23:13:32 +0100 Subject: [PATCH] INPUT: Added alternate C Button and mouse_keys --- .../data/InputAutoCfg.ini | 96 ++++++++++++++++++- source/mupen64plus-input-sdl/src/config.c | 42 +++++++- source/mupen64plus-input-sdl/src/plugin.c | 45 +++++++-- source/mupen64plus-input-sdl/src/plugin.h | 14 ++- 4 files changed, 181 insertions(+), 16 deletions(-) mode change 100644 => 100755 source/mupen64plus-input-sdl/src/config.c mode change 100644 => 100755 source/mupen64plus-input-sdl/src/plugin.c mode change 100644 => 100755 source/mupen64plus-input-sdl/src/plugin.h diff --git a/source/mupen64plus-input-sdl/data/InputAutoCfg.ini b/source/mupen64plus-input-sdl/data/InputAutoCfg.ini index 6d67e45..f448df4 100644 --- a/source/mupen64plus-input-sdl/data/InputAutoCfg.ini +++ b/source/mupen64plus-input-sdl/data/InputAutoCfg.ini @@ -915,7 +915,7 @@ Rumblepak switch= button(20) Y Axis= axis(4-,4+) X Axis= axis(3-,3+) -#Pandora dual nub support, the hat is in fact "nub1" +#Pandora nub support [nub0] plugged = True plugin = 2 @@ -951,3 +951,97 @@ C Button U = key(48) # default value here Mempak switch = key(44) Rumblepak switch = key(46) +C Button2 U = mouse_up +C Button2 D = mouse_down +C Button2 L = mouse_left +C Button2 R = mouse_right + +#Pandora nub support, if using right nub +[nub1] +plugged = True +plugin = 2 +mouse = False +DPad R = key(275) +DPad L = key(276) +DPad D = key(274) +DPad U = key(273) +#Start is Start +Start= key(308) +Z Trig= key(303) +#B button = (X) = 281 = SDLK_PAGEDWN +B Button= key(278) +#A button = (A) = 278 = SDLK_HOME (279 = (B)) +A Button= key(281) +R Trig= key(305) +#L trigger is (B) (P = 111) +L Trig= key(279) +Y Axis= axis(1-,1+) +X Axis= axis(0-,0+) +# K=107 , Backspace=8 +C Button R = key(8) +# J = 106, 9 = 57 +C Button L = key(57) +# M = 109 , (Y) = 280 +C Button D = key(280) +# I = 105 , 0 = 48 +C Button U = key(48) +#C Button R = hat(0 Right) +#C Button L = hat(0 Left) +#C Button D = hat(0 Down) +#C Button U = hat(0 Up) +# default value here +Mempak switch = key(44) +Rumblepak switch = key(46) +C Button2 U = mouse_up +C Button2 D = mouse_down +C Button2 L = mouse_left +C Button2 R = mouse_right + +[Retrode] +plugged = True +plugin = 2 +mouse = False +AnalogDeadzone = 4096,4096 +AnalogPeak = 32768,32768 +DPad R = button(8) +DPad L = button(9) +DPad D = button(10) +DPad U = button(11) +Start = button(12) +Z Trig = button(13) +B Button = button(14) +A Button = button(15) +C Button R = button(0) +C Button L = button(1) +C Button D = button(2) +C Button U = button(3) +R Trig = button(4) +L Trig = button(5) +#Mempak switch = +#Rumblepak switch = +X Axis = axis(0-,0+) +Y Axis = axis(1-,1+) +__NextController: +plugged = True +plugin = 2 +mouse = False +AnalogDeadzone = 4096,4096 +AnalogPeak = 32768,32768 +DPad R = button(24) +DPad L = button(25) +DPad D = button(26) +DPad U = button(27) +Start = button(28) +Z Trig = button(29) +B Button = button(30) +A Button = button(31) +C Button R = button(19) +C Button L = button(18) +C Button D = button(17) +C Button U = button(16) +R Trig = button(20) +L Trig = button(21) +#Mempak switch = +#Rumblepak switch = +X Axis = axis(2-,2+) +Y Axis = axis(3-,3+) \ No newline at end of file diff --git a/source/mupen64plus-input-sdl/src/config.c b/source/mupen64plus-input-sdl/src/config.c old mode 100644 new mode 100755 index 1a6fa55..d616b27 --- a/source/mupen64plus-input-sdl/src/config.c +++ b/source/mupen64plus-input-sdl/src/config.c @@ -62,6 +62,10 @@ static const char *button_names[] = { "L Trig", // L_TRIG "Mempak switch", "Rumblepak switch", + "C Button2 R", // R_CBUTTON alternate + "C Button2 L", // L_CBUTTON alternate + "C Button2 D", // D_CBUTTON alternate + "C Button2 U", // U_CBUTTON alternate "X Axis", // X_AXIS "Y Axis" // Y_AXIS }; @@ -89,7 +93,7 @@ static void clear_controller(int iCtrlIdx) controller[iCtrlIdx].control->Present = 0; controller[iCtrlIdx].control->RawData = 0; controller[iCtrlIdx].control->Plugin = PLUGIN_NONE; - for( b = 0; b < 16; b++ ) + for( b = 0; b < NUM_BUTTONS; b++ ) { controller[iCtrlIdx].button[b].button = -1; controller[iCtrlIdx].button[b].key = SDL_SCANCODE_UNKNOWN; @@ -98,6 +102,10 @@ static void clear_controller(int iCtrlIdx) controller[iCtrlIdx].button[b].hat = -1; controller[iCtrlIdx].button[b].hat_pos = -1; controller[iCtrlIdx].button[b].mouse = -1; + controller[iCtrlIdx].button[b].mouse_up = 0; + controller[iCtrlIdx].button[b].mouse_down = 0; + controller[iCtrlIdx].button[b].mouse_left = 0; + controller[iCtrlIdx].button[b].mouse_right = 0; } for( b = 0; b < 2; b++ ) { @@ -182,7 +190,7 @@ static int get_sdl_num_joysticks(void) static int load_controller_config(const char *SectionName, int i, int sdlDeviceIdx) { m64p_handle pConfig; - char input_str[256], value1_str[16], value2_str[16]; + char input_str[256], value1_str[NUM_BUTTONS], value2_str[NUM_BUTTONS]; const char *config_ptr; int j; @@ -257,9 +265,15 @@ static int load_controller_config(const char *SectionName, int i, int sdlDeviceI if (lastchar > value1_str && *lastchar == ')') *lastchar = 0; controller[i].button[j].hat_pos = get_hat_pos_by_name(value1_str); } - if ((config_ptr = strstr(input_str, "mouse")) != NULL) - if (sscanf(config_ptr, "mouse(%i)", &controller[i].button[j].mouse) != 1) + if ((config_ptr = strstr(input_str, "mouse")) != NULL) { + // check for mouse_pseudo button first + if ((config_ptr = strstr(input_str, "mouse_up")) != NULL) {controller[i].button[j].mouse_up=1; controller[i].mouse_up=1;} + else if ((config_ptr = strstr(input_str, "mouse_down")) != NULL) {controller[i].button[j].mouse_down=1; controller[i].mouse_down=1;} + else if ((config_ptr = strstr(input_str, "mouse_left")) != NULL) {controller[i].button[j].mouse_left=1; controller[i].mouse_left=1;} + else if ((config_ptr = strstr(input_str, "mouse_right")) != NULL) {controller[i].button[j].mouse_right=1; controller[i].mouse_right=1;} + else if (sscanf(config_ptr, "mouse(%i)", &controller[i].button[j].mouse) != 1) DebugMessage(M64MSG_WARNING, "parsing error in mouse() parameter of button '%s' for controller %i", button_names[j], i + 1); + } } /* load configuration for the 2 analog joystick axes */ for (j = X_AXIS; j <= Y_AXIS; j++) @@ -369,6 +383,26 @@ static void init_controller_config(int iCtrlIdx, const char *pccDeviceName, eMod sprintf(Param, "mouse(%i) ", controller[iCtrlIdx].button[j].mouse); strcat(ParamString, Param); } + if (controller[iCtrlIdx].button[j].mouse_up > 0) + { + sprintf(Param, "mouse_up "); + strcat(ParamString, Param); + } + if (controller[iCtrlIdx].button[j].mouse_down > 0) + { + sprintf(Param, "mouse_down "); + strcat(ParamString, Param); + } + if (controller[iCtrlIdx].button[j].mouse_right > 0) + { + sprintf(Param, "mouse_right "); + strcat(ParamString, Param); + } + if (controller[iCtrlIdx].button[j].mouse_left > 0) + { + sprintf(Param, "mouse_left "); + strcat(ParamString, Param); + } if (j == 0) Help = "Digital button configuration mappings"; else diff --git a/source/mupen64plus-input-sdl/src/plugin.c b/source/mupen64plus-input-sdl/src/plugin.c old mode 100644 new mode 100755 index 26b1814..379c940 --- a/source/mupen64plus-input-sdl/src/plugin.c +++ b/source/mupen64plus-input-sdl/src/plugin.c @@ -104,7 +104,11 @@ static unsigned short button_bits[] = { 0x1000, // R_TRIG 0x2000, // L_TRIG 0x4000, // Mempak switch - 0x8000 // Rumblepak switch + 0x8000, // Rumblepak switch + 0x0100, // R_CBUTTON alternate + 0x0200, // L_CBUTTON alternate + 0x0400, // D_CBUTTON alternate + 0x0800 // U_CBUTTON alternate }; static int romopen = 0; // is a rom opened @@ -261,10 +265,10 @@ doSdlKeys(unsigned char* keystate) static int grabmouse = 1, grabtoggled = 0; axis_max_val = 80; - if (keystate[SDL_SCANCODE_RCTRL]) +/* if (keystate[SDL_SCANCODE_RCTRL]) axis_max_val -= 40; if (keystate[SDL_SCANCODE_RSHIFT]) - axis_max_val -= 20; + axis_max_val -= 20;*/ for( c = 0; c < 4; c++ ) { @@ -298,7 +302,7 @@ doSdlKeys(unsigned char* keystate) } if (controller[c].mouse) { - if (keystate[SDL_SCANCODE_LCTRL] && keystate[SDL_SCANCODE_LALT]) + /* if (keystate[SDL_SCANCODE_LCTRL] && keystate[SDL_SCANCODE_LALT]) { if (!grabtoggled) { @@ -314,6 +318,7 @@ doSdlKeys(unsigned char* keystate) } } else grabtoggled = 0; + */ } } } @@ -473,7 +478,7 @@ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys ) if( controller[Control].device >= 0 ) { - for( b = 0; b < 16; b++ ) + for( b = 0; b < NUM_BUTTONS; b++ ) { if( controller[Control].button[b].button >= 0 ) if( SDL_JoystickGetButton( controller[Control].joystick, controller[Control].button[b].button ) ) @@ -556,7 +561,7 @@ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys ) // process mouse events mstate = SDL_GetMouseState( NULL, NULL ); - for( b = 0; b < 16; b++ ) + for( b = 0; b < NUM_BUTTONS; b++ ) { if( controller[Control].button[b].mouse < 1 ) continue; @@ -564,7 +569,8 @@ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys ) controller[Control].buttons.Value |= button_bits[b]; } - if (controller[Control].mouse) + if ((controller[Control].mouse) + || ((controller[Control].mouse_up) || (controller[Control].mouse_down) || (controller[Control].mouse_left) || (controller[Control].mouse_right) )) { #if SDL_VERSION_ATLEAST(2,0,0) #warning SDL mouse grabbing not yet supported with SDL 2.0 @@ -599,13 +605,31 @@ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys ) axis_val = -80; else if (axis_val > 80) axis_val = 80; - controller[Control].buttons.X_AXIS = axis_val; + if (controller[Control].mouse) + controller[Control].buttons.X_AXIS = axis_val; + else { + for( b = 0; b < NUM_BUTTONS; b++ ) { + if( controller[Control].button[b].mouse_left > 0 ) + if (controller[Control].mouse_left) controller[Control].buttons.Value |= (axis_val<-40)?button_bits[b]:0; + if( controller[Control].button[b].mouse_right > 0 ) + if (controller[Control].mouse_right) controller[Control].buttons.Value |= (axis_val>40)?button_bits[b]:0; + } + } axis_val = mousey_residual; if (axis_val < -80) axis_val = -80; else if (axis_val > 80) axis_val = 80; - controller[Control].buttons.Y_AXIS = -axis_val; + if (controller[Control].mouse) + controller[Control].buttons.Y_AXIS = -axis_val; + else { + for( b = 0; b < NUM_BUTTONS; b++ ) { + if( controller[Control].button[b].mouse_up > 0 ) + if (controller[Control].mouse_up) controller[Control].buttons.Value |= (axis_val<-40)?button_bits[b]:0; + if( controller[Control].button[b].mouse_down > 0 ) + if (controller[Control].mouse_down) controller[Control].buttons.Value |= (axis_val>40)?button_bits[b]:0; + } + } /* the mouse x/y values decay exponentially */ mousex_residual = (mousex_residual * 224) / 256; mousey_residual = (mousey_residual * 224) / 256; @@ -885,7 +909,8 @@ EXPORT int CALL RomOpen(void) controller[i].joystick = NULL; // grab mouse - if (controller[0].mouse || controller[1].mouse || controller[2].mouse || controller[3].mouse) + if ((controller[0].mouse || controller[1].mouse || controller[2].mouse || controller[3].mouse) + ||(controller[0].mouse_up || controller[0].mouse_down || controller[0].mouse_left || controller[0].mouse_right)) { #if SDL_VERSION_ATLEAST(2,0,0) #warning SDL mouse grabbing not yet supported with SDL 2.0 diff --git a/source/mupen64plus-input-sdl/src/plugin.h b/source/mupen64plus-input-sdl/src/plugin.h old mode 100644 new mode 100755 index f5e7bfd..1096bfb --- a/source/mupen64plus-input-sdl/src/plugin.h +++ b/source/mupen64plus-input-sdl/src/plugin.h @@ -100,6 +100,10 @@ enum EButton L_TRIG, MEMPAK, RUMBLEPAK, + R_CBUTTON2, + L_CBUTTON2, + D_CBUTTON2, + U_CBUTTON2, X_AXIS, Y_AXIS, NUM_BUTTONS @@ -113,6 +117,10 @@ typedef struct int axis_deadzone; // -1 for default, or >= 0 for custom value int hat, hat_pos; // hat + hat position; -1 if not assigned int mouse; // mouse button + int mouse_up; // mouse direction pseudo buttons + int mouse_down; + int mouse_left; + int mouse_right; } SButtonMap; typedef struct @@ -130,7 +138,7 @@ typedef struct BUTTONS buttons; // mappings - SButtonMap button[16]; // 14 buttons; in the order of EButton + mempak/rumblepak switches + SButtonMap button[NUM_BUTTONS]; // 14 buttons; in the order of EButton + mempak/rumblepak switches SAxisMap axis[2]; // 2 axis int device; // joystick device; -1 = keyboard; -2 = none int mouse; // mouse enabled: 0 = no; 1 = yes @@ -139,6 +147,10 @@ typedef struct int axis_deadzone[2]; // minimum absolute value before analog movement is recognized int axis_peak[2]; // highest analog value returned by SDL, used for scaling float mouse_sens[2]; // mouse sensitivity + int mouse_up; + int mouse_down; + int mouse_left; + int mouse_right; } SController; /* global data definitions */ -- 2.39.2