From 7dea987c9689c441d8148b9523871f3fbbca2804 Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Sun, 7 Jun 2020 15:23:13 +0800 Subject: [PATCH] Add Sony Mouse Controller support - Tested with Final Doom. Worked great. --- frontend/libretro.c | 36 +++++++++++ frontend/libretro_core_options.h | 8 +++ frontend/libretro_core_options_intl.h | 16 +++++ frontend/plugin.c | 91 ++++++++++++++++----------- frontend/plugin_lib.h | 1 + 5 files changed, 115 insertions(+), 37 deletions(-) diff --git a/frontend/libretro.c b/frontend/libretro.c index d489ce55..a91c5c17 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -112,6 +112,7 @@ int in_type[8] = { int in_analog_left[8][2] = { { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 } }; int in_analog_right[8][2] = { { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 } }; unsigned short in_keystate[PORTS_NUMBER]; +int in_mouse[8][2]; int multitap1 = 0; int multitap2 = 0; int in_enable_vibration = 1; @@ -595,6 +596,8 @@ static void update_controller_port_variable(unsigned port) in_type[port] = PSE_PAD_TYPE_NEGCON; else if (strcmp(var.value, "guncon") == 0) in_type[port] = PSE_PAD_TYPE_GUNCON; + else if (strcmp(var.value, "mouse") == 0) + in_type[port] = PSE_PAD_TYPE_MOUSE; else if (strcmp(var.value, "none") == 0) in_type[port] = PSE_PAD_TYPE_NONE; // else 'default' case, do nothing @@ -2428,6 +2431,39 @@ static void update_input(void) case PSE_PAD_TYPE_NEGCON: update_input_negcon(i, ret); break; + case PSE_PAD_TYPE_MOUSE: + { + /* mouse x/y movement, range -128 to +127 */ + float accum_x = 0, accum_y = 0; + + float x = input_state_cb(i, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X); + float y = input_state_cb(i, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y); + + accum_x += x; + accum_y += y; + + if (accum_x > 127) + accum_x = 127; + else if (accum_x < -128) + accum_x = -128; + + if (accum_y > 127) + accum_y = 127; + else if (accum_y < -128) + accum_y = -128; + + in_mouse[i][0] = (int)accum_x; + in_mouse[i][1] = (int)accum_y; + + /* mouse button state */ + if (input_state_cb(i, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT)) + in_keystate[i] |= 1 << 11; + + if (input_state_cb(i, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT)) + in_keystate[i] |= 1 << 10; + + break; + } default: // Query digital inputs for (j = 0; j < RETRO_PSX_MAP_LEN; j++) diff --git a/frontend/libretro_core_options.h b/frontend/libretro_core_options.h index cab6a9a0..46670baa 100644 --- a/frontend/libretro_core_options.h +++ b/frontend/libretro_core_options.h @@ -118,6 +118,7 @@ struct retro_core_option_definition option_defs_us[] = { { "dualshock", NULL }, { "negcon", NULL }, { "guncon", NULL }, + { "mouse", NULL }, { "none", NULL }, { NULL, NULL }, }, @@ -133,6 +134,7 @@ struct retro_core_option_definition option_defs_us[] = { { "dualshock", NULL }, { "negcon", NULL }, { "guncon", NULL }, + { "mouse", NULL }, { "none", NULL }, { NULL, NULL }, }, @@ -148,6 +150,7 @@ struct retro_core_option_definition option_defs_us[] = { { "dualshock", NULL }, { "negcon", NULL }, { "guncon", NULL }, + { "mouse", NULL }, { "none", NULL }, { NULL, NULL }, }, @@ -163,6 +166,7 @@ struct retro_core_option_definition option_defs_us[] = { { "dualshock", NULL }, { "negcon", NULL }, { "guncon", NULL }, + { "mouse", NULL }, { "none", NULL }, { NULL, NULL }, }, @@ -178,6 +182,7 @@ struct retro_core_option_definition option_defs_us[] = { { "dualshock", NULL }, { "negcon", NULL }, { "guncon", NULL }, + { "mouse", NULL }, { "none", NULL }, { NULL, NULL }, }, @@ -192,6 +197,7 @@ struct retro_core_option_definition option_defs_us[] = { { "dualshock", NULL }, { "negcon", NULL }, { "guncon", NULL }, + { "mouse", NULL }, { "none", NULL }, { NULL, NULL }, }, @@ -206,6 +212,7 @@ struct retro_core_option_definition option_defs_us[] = { { "dualshock", NULL }, { "negcon", NULL }, { "guncon", NULL }, + { "mouse", NULL }, { "none", NULL }, { NULL, NULL }, }, @@ -220,6 +227,7 @@ struct retro_core_option_definition option_defs_us[] = { { "dualshock", NULL }, { "negcon", NULL }, { "guncon", NULL }, + { "mouse", NULL }, { "none", NULL }, { NULL, NULL }, }, diff --git a/frontend/libretro_core_options_intl.h b/frontend/libretro_core_options_intl.h index 107cd571..1e7fd793 100644 --- a/frontend/libretro_core_options_intl.h +++ b/frontend/libretro_core_options_intl.h @@ -124,6 +124,8 @@ struct retro_core_option_definition option_defs_tr[] = { { "analog", NULL }, { "dualshock", NULL }, { "negcon", NULL }, + { "guncon", NULL }, + { "mouse", NULL }, { "none", "hiçbiri" }, { NULL, NULL }, }, @@ -138,6 +140,8 @@ struct retro_core_option_definition option_defs_tr[] = { { "analog", NULL }, { "dualshock", NULL }, { "negcon", NULL }, + { "guncon", NULL }, + { "mouse", NULL }, { "none", "hiçbiri" }, { NULL, NULL }, }, @@ -152,6 +156,8 @@ struct retro_core_option_definition option_defs_tr[] = { { "analog", NULL }, { "dualshock", NULL }, { "negcon", NULL }, + { "guncon", NULL }, + { "mouse", NULL }, { "none", "hiçbiri" }, { NULL, NULL }, }, @@ -166,6 +172,8 @@ struct retro_core_option_definition option_defs_tr[] = { { "analog", NULL }, { "dualshock", NULL }, { "negcon", NULL }, + { "guncon", NULL }, + { "mouse", NULL }, { "none", "hiçbiri" }, { NULL, NULL }, }, @@ -180,6 +188,8 @@ struct retro_core_option_definition option_defs_tr[] = { { "analog", NULL }, { "dualshock", NULL }, { "negcon", NULL }, + { "guncon", NULL }, + { "mouse", NULL }, { "none", "hiçbiri" }, { NULL, NULL }, }, @@ -193,6 +203,8 @@ struct retro_core_option_definition option_defs_tr[] = { { "analog", NULL }, { "dualshock", NULL }, { "negcon", NULL }, + { "guncon", NULL }, + { "mouse", NULL }, { "none", "hiçbiri" }, { NULL, NULL }, }, @@ -206,6 +218,8 @@ struct retro_core_option_definition option_defs_tr[] = { { "analog", NULL }, { "dualshock", NULL }, { "negcon", NULL }, + { "guncon", NULL }, + { "mouse", NULL }, { "none", "hiçbiri" }, { NULL, NULL }, }, @@ -219,6 +233,8 @@ struct retro_core_option_definition option_defs_tr[] = { { "analog", NULL }, { "dualshock", NULL }, { "negcon", NULL }, + { "guncon", NULL }, + { "mouse", NULL }, { "none", "hiçbiri" }, { NULL, NULL }, }, diff --git a/frontend/plugin.c b/frontend/plugin.c index 30b0e082..a617c24e 100644 --- a/frontend/plugin.c +++ b/frontend/plugin.c @@ -51,47 +51,64 @@ extern int CALLBACK SPUplayCDDAchannel(short *, int); /* PAD */ static long PADreadPort1(PadDataS *pad) { int pad_index = pad->requestPadIndex; - pad->controllerType = in_type[pad_index]; - pad->buttonStatus = ~in_keystate[pad_index]; - if (multitap1 == 1) - pad->portMultitap = 1; - else - pad->portMultitap = 0; - - if (in_type[pad_index] == PSE_PAD_TYPE_ANALOGJOY || in_type[pad_index] == PSE_PAD_TYPE_ANALOGPAD || in_type[pad_index] == PSE_PAD_TYPE_NEGCON || in_type[pad_index] == PSE_PAD_TYPE_GUNCON) - { - pad->leftJoyX = in_analog_left[pad_index][0]; - pad->leftJoyY = in_analog_left[pad_index][1]; - pad->rightJoyX = in_analog_right[pad_index][0]; - pad->rightJoyY = in_analog_right[pad_index][1]; - - pad->absoluteX = in_analog_left[pad_index][0]; - pad->absoluteY = in_analog_left[pad_index][1]; - } - return 0; + + pad->controllerType = in_type[pad_index]; + pad->buttonStatus = ~in_keystate[pad_index]; + + if (multitap1 == 1) + pad->portMultitap = 1; + else + pad->portMultitap = 0; + + if (in_type[pad_index] == PSE_PAD_TYPE_ANALOGJOY || in_type[pad_index] == PSE_PAD_TYPE_ANALOGPAD || in_type[pad_index] == PSE_PAD_TYPE_NEGCON || in_type[pad_index] == PSE_PAD_TYPE_GUNCON) + { + pad->leftJoyX = in_analog_left[pad_index][0]; + pad->leftJoyY = in_analog_left[pad_index][1]; + pad->rightJoyX = in_analog_right[pad_index][0]; + pad->rightJoyY = in_analog_right[pad_index][1]; + + pad->absoluteX = in_analog_left[pad_index][0]; + pad->absoluteY = in_analog_left[pad_index][1]; + } + + if (in_type[pad_index] == PSE_PAD_TYPE_MOUSE) + { + pad->moveX = in_mouse[pad_index][0]; + pad->moveY = in_mouse[pad_index][1]; + } + + return 0; } static long PADreadPort2(PadDataS *pad) { int pad_index = pad->requestPadIndex; - - pad->controllerType = in_type[pad_index]; - pad->buttonStatus = ~in_keystate[pad_index]; - if (multitap2 == 1) - pad->portMultitap = 2; - else - pad->portMultitap = 0; - - if (in_type[pad_index] == PSE_PAD_TYPE_ANALOGJOY || in_type[pad_index] == PSE_PAD_TYPE_ANALOGPAD || in_type[pad_index] == PSE_PAD_TYPE_NEGCON || in_type[pad_index] == PSE_PAD_TYPE_GUNCON) - { - pad->leftJoyX = in_analog_left[pad_index][0]; - pad->leftJoyY = in_analog_left[pad_index][1]; - pad->rightJoyX = in_analog_right[pad_index][0]; - pad->rightJoyY = in_analog_right[pad_index][1]; - - pad->absoluteX = in_analog_left[pad_index][0]; - pad->absoluteY = in_analog_left[pad_index][1]; - } - return 0; + + pad->controllerType = in_type[pad_index]; + pad->buttonStatus = ~in_keystate[pad_index]; + + if (multitap2 == 1) + pad->portMultitap = 2; + else + pad->portMultitap = 0; + + if (in_type[pad_index] == PSE_PAD_TYPE_ANALOGJOY || in_type[pad_index] == PSE_PAD_TYPE_ANALOGPAD || in_type[pad_index] == PSE_PAD_TYPE_NEGCON || in_type[pad_index] == PSE_PAD_TYPE_GUNCON) + { + pad->leftJoyX = in_analog_left[pad_index][0]; + pad->leftJoyY = in_analog_left[pad_index][1]; + pad->rightJoyX = in_analog_right[pad_index][0]; + pad->rightJoyY = in_analog_right[pad_index][1]; + + pad->absoluteX = in_analog_left[pad_index][0]; + pad->absoluteY = in_analog_left[pad_index][1]; + } + + if (in_type[pad_index] == PSE_PAD_TYPE_MOUSE) + { + pad->moveX = in_mouse[pad_index][0]; + pad->moveY = in_mouse[pad_index][1]; + } + + return 0; } /* GPU */ diff --git a/frontend/plugin_lib.h b/frontend/plugin_lib.h index d51c5e7d..09cc4c56 100644 --- a/frontend/plugin_lib.h +++ b/frontend/plugin_lib.h @@ -24,6 +24,7 @@ extern int multitap2; extern int in_analog_left[8][2]; extern int in_analog_right[8][2]; extern unsigned short in_keystate[8]; +extern int in_mouse[8][2]; extern int in_adev[2], in_adev_axis[2][2]; extern int in_adev_is_nublike[2]; -- 2.39.5