diff options
author | Twinaphex | 2019-10-24 20:11:31 +0200 |
---|---|---|
committer | GitHub | 2019-10-24 20:11:31 +0200 |
commit | 4b353f8adc434d4168df88bca58e793becaa891b (patch) | |
tree | 4cab4856b036a0c90605cb45f67a4dd313e38d69 | |
parent | 1990449de5befed3c0ee614ff4b6273cfe303a8e (diff) | |
parent | 03fc8e9043246716a36a152750c9c69cce301d73 (diff) | |
download | pcsx_rearmed-4b353f8adc434d4168df88bca58e793becaa891b.tar.gz pcsx_rearmed-4b353f8adc434d4168df88bca58e793becaa891b.tar.bz2 pcsx_rearmed-4b353f8adc434d4168df88bca58e793becaa891b.zip |
Merge pull request #351 from SindenLightgun/master
Basic Guncon support
-rw-r--r-- | frontend/libretro.c | 91 | ||||
-rw-r--r-- | frontend/libretro_core_options.h | 252 | ||||
-rw-r--r-- | frontend/plugin.c | 10 | ||||
-rw-r--r-- | include/psemu_plugin_defs.h | 3 | ||||
-rw-r--r-- | libpcsxcore/plugins.c | 42 | ||||
-rw-r--r-- | plugins/dfinput/main.c | 11 |
6 files changed, 401 insertions, 8 deletions
diff --git a/frontend/libretro.c b/frontend/libretro.c index 785213b..987f90d 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -572,6 +572,8 @@ static void update_controller_port_variable(unsigned port) in_type[port] = PSE_PAD_TYPE_ANALOGPAD; else if (strcmp(var.value, "negcon") == 0) 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, "none") == 0) in_type[port] = PSE_PAD_TYPE_NONE; // else 'default' case, do nothing @@ -2000,6 +2002,93 @@ void retro_run(void) } } + if (in_type[i] == PSE_PAD_TYPE_GUNCON) + { + //ToDo move across to: + //RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X + //RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y + //RETRO_DEVICE_ID_LIGHTGUN_TRIGGER + //RETRO_DEVICE_ID_LIGHTGUN_RELOAD + //RETRO_DEVICE_ID_LIGHTGUN_AUX_A + //RETRO_DEVICE_ID_LIGHTGUN_AUX_B + //Though not sure these are hooked up properly on the Pi + + //ToDo + //Put the controller index back to i instead of hardcoding to 1 when the libretro overlay crash bug is fixed + //This is required for 2 player + + //GUNCON has 3 controls, Trigger,A,B which equal Circle,Start,Cross + + // Trigger + //The 1 is hardcoded instead of i to prevent the overlay mouse button libretro crash bug + if (input_state_cb(1, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT)){ + in_keystate[i] |= (1 << DKEY_CIRCLE); + } + + // A + if (input_state_cb(1, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT)){ + in_keystate[i] |= (1 << DKEY_START); + } + + // B + if (input_state_cb(1, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_MIDDLE)){ + in_keystate[i] |= (1 << DKEY_CROSS); + } + + //The 1 is hardcoded instead of i to prevent the overlay mouse button libretro crash bug + int gunx = input_state_cb(1, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X); + int guny = input_state_cb(1, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y); + + //This adjustment process gives the user the ability to manually align the mouse up better + //with where the shots are in the emulator. + + //Percentage distance of screen to adjust + int GunconAdjustX = 0; + int GunconAdjustY = 0; + + //Used when out by a percentage + float GunconAdjustRatioX = 1; + float GunconAdjustRatioY = 1; + + struct retro_variable var; + var.value = NULL; + var.key = "pcsx_rearmed_gunconadjustx"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + { + GunconAdjustX = atoi(var.value); + } + + var.value = NULL; + var.key = "pcsx_rearmed_gunconadjusty"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + { + GunconAdjustY = atoi(var.value); + } + + + var.value = NULL; + var.key = "pcsx_rearmed_gunconadjustratiox"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + { + GunconAdjustRatioX = atof(var.value); + } + + + var.value = NULL; + var.key = "pcsx_rearmed_gunconadjustratioy"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + { + GunconAdjustRatioY = atof(var.value); + } + + //Mouse range is -32767 -> 32767 + //1% is about 655 + //Use the left analog stick field to store the absolute coordinates + in_analog_left[0][0] = (gunx*GunconAdjustRatioX) + (GunconAdjustX * 655); + in_analog_left[0][1] = (guny*GunconAdjustRatioY) + (GunconAdjustY * 655); + + + } if (in_type[i] == PSE_PAD_TYPE_NEGCON) { // Query digital inputs @@ -2104,7 +2193,7 @@ void retro_run(void) // > NeGcon L in_analog_left[i][1] = get_analog_button(ret, input_state_cb, i, RETRO_DEVICE_ID_JOYPAD_L); } - else + if (in_type[i] != PSE_PAD_TYPE_NEGCON && in_type[i] != PSE_PAD_TYPE_GUNCON) { // 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 1ecc9a9..0c0634f 100644 --- a/frontend/libretro_core_options.h +++ b/frontend/libretro_core_options.h @@ -106,6 +106,7 @@ struct retro_core_option_definition option_defs_us[] = { { "analog", NULL }, { "dualshock", NULL }, { "negcon", NULL }, + { "guncon", NULL }, { "none", NULL }, { NULL, NULL }, }, @@ -120,6 +121,7 @@ struct retro_core_option_definition option_defs_us[] = { { "analog", NULL }, { "dualshock", NULL }, { "negcon", NULL }, + { "guncon", NULL }, { "none", NULL }, { NULL, NULL }, }, @@ -134,6 +136,7 @@ struct retro_core_option_definition option_defs_us[] = { { "analog", NULL }, { "dualshock", NULL }, { "negcon", NULL }, + { "guncon", NULL }, { "none", NULL }, { NULL, NULL }, }, @@ -148,6 +151,7 @@ struct retro_core_option_definition option_defs_us[] = { { "analog", NULL }, { "dualshock", NULL }, { "negcon", NULL }, + { "guncon", NULL }, { "none", NULL }, { NULL, NULL }, }, @@ -162,6 +166,7 @@ struct retro_core_option_definition option_defs_us[] = { { "analog", NULL }, { "dualshock", NULL }, { "negcon", NULL }, + { "guncon", NULL }, { "none", NULL }, { NULL, NULL }, }, @@ -175,6 +180,7 @@ struct retro_core_option_definition option_defs_us[] = { { "analog", NULL }, { "dualshock", NULL }, { "negcon", NULL }, + { "guncon", NULL }, { "none", NULL }, { NULL, NULL }, }, @@ -188,6 +194,7 @@ struct retro_core_option_definition option_defs_us[] = { { "analog", NULL }, { "dualshock", NULL }, { "negcon", NULL }, + { "guncon", NULL }, { "none", NULL }, { NULL, NULL }, }, @@ -201,6 +208,7 @@ struct retro_core_option_definition option_defs_us[] = { { "analog", NULL }, { "dualshock", NULL }, { "negcon", NULL }, + { "guncon", NULL }, { "none", NULL }, { NULL, NULL }, }, @@ -270,6 +278,250 @@ struct retro_core_option_definition option_defs_us[] = { "enabled", }, { + "pcsx_rearmed_gunconadjustx", + "Guncon Adjust X", + "When using Guncon mode, you can override aim in emulator if shots misaligned, this applies an increment on the x axis.", + { + { "0", NULL }, + { "-25", NULL }, + { "-24", NULL }, + { "-23", NULL }, + { "-22", NULL }, + { "-21", NULL }, + { "-20", NULL }, + { "-19", NULL }, + { "-18", NULL }, + { "-17", NULL }, + { "-16", NULL }, + { "-15", NULL }, + { "-14", NULL }, + { "-13", NULL }, + { "-12", NULL }, + { "-11", NULL }, + { "-10", NULL }, + { "-09", NULL }, + { "-08", NULL }, + { "-07", NULL }, + { "-06", NULL }, + { "-05", NULL }, + { "-04", NULL }, + { "-03", NULL }, + { "-02", NULL }, + { "-01", NULL }, + { "00", NULL }, + { "01", NULL }, + { "02", NULL }, + { "03", NULL }, + { "04", NULL }, + { "05", NULL }, + { "06", NULL }, + { "07", NULL }, + { "08", NULL }, + { "09", NULL }, + { "10", NULL }, + { "11", NULL }, + { "12", NULL }, + { "13", NULL }, + { "14", NULL }, + { "15", NULL }, + { "16", NULL }, + { "17", NULL }, + { "18", NULL }, + { "19", NULL }, + { "20", NULL }, + { "21", NULL }, + { "22", NULL }, + { "23", NULL }, + { "24", NULL }, + { "25", NULL }, + { NULL, NULL }, + }, + "0", + }, + { + "pcsx_rearmed_gunconadjusty", + "Guncon Adjust Y", + "When using Guncon mode, you can override aim in emulator if shots misaligned, this applies an increment on the y axis.", + { + { "0", NULL }, + { "-25", NULL }, + { "-24", NULL }, + { "-23", NULL }, + { "-22", NULL }, + { "-21", NULL }, + { "-20", NULL }, + { "-19", NULL }, + { "-18", NULL }, + { "-17", NULL }, + { "-16", NULL }, + { "-15", NULL }, + { "-14", NULL }, + { "-13", NULL }, + { "-12", NULL }, + { "-11", NULL }, + { "-10", NULL }, + { "-09", NULL }, + { "-08", NULL }, + { "-07", NULL }, + { "-06", NULL }, + { "-05", NULL }, + { "-04", NULL }, + { "-03", NULL }, + { "-02", NULL }, + { "-01", NULL }, + { "00", NULL }, + { "01", NULL }, + { "02", NULL }, + { "03", NULL }, + { "04", NULL }, + { "05", NULL }, + { "06", NULL }, + { "07", NULL }, + { "08", NULL }, + { "09", NULL }, + { "10", NULL }, + { "11", NULL }, + { "12", NULL }, + { "13", NULL }, + { "14", NULL }, + { "15", NULL }, + { "16", NULL }, + { "17", NULL }, + { "18", NULL }, + { "19", NULL }, + { "20", NULL }, + { "21", NULL }, + { "22", NULL }, + { "23", NULL }, + { "24", NULL }, + { "25", NULL }, + { NULL, NULL }, + }, + "0", + }, + { + "pcsx_rearmed_gunconadjustratiox", + "Guncon Adjust Ratio X", + "When using Guncon mode, you can override aim in emulator if shots misaligned, this applies a ratio on the x axis.", + { + { "1", NULL }, + { "0.75", NULL }, + { "0.76", NULL }, + { "0.77", NULL }, + { "0.78", NULL }, + { "0.79", NULL }, + { "0.80", NULL }, + { "0.81", NULL }, + { "0.82", NULL }, + { "0.83", NULL }, + { "0.84", NULL }, + { "0.85", NULL }, + { "0.86", NULL }, + { "0.87", NULL }, + { "0.88", NULL }, + { "0.89", NULL }, + { "0.90", NULL }, + { "0.91", NULL }, + { "0.92", NULL }, + { "0.93", NULL }, + { "0.94", NULL }, + { "0.95", NULL }, + { "0.96", NULL }, + { "0.97", NULL }, + { "0.98", NULL }, + { "0.99", NULL }, + { "1.00", NULL }, + { "1.01", NULL }, + { "1.02", NULL }, + { "1.03", NULL }, + { "1.04", NULL }, + { "1.05", NULL }, + { "1.06", NULL }, + { "1.07", NULL }, + { "1.08", NULL }, + { "1.09", NULL }, + { "1.10", NULL }, + { "1.11", NULL }, + { "1.12", NULL }, + { "1.13", NULL }, + { "1.14", NULL }, + { "1.15", NULL }, + { "1.16", NULL }, + { "1.17", NULL }, + { "1.18", NULL }, + { "1.19", NULL }, + { "1.20", NULL }, + { "1.21", NULL }, + { "1.22", NULL }, + { "1.23", NULL }, + { "1.24", NULL }, + { "1.25", NULL }, + { NULL, NULL }, + }, + "1", + }, + { + "pcsx_rearmed_gunconadjustratioy", + "Guncon Adjust Ratio Y", + "When using Guncon mode, you can override aim in emulator if shots misaligned, this applies a ratio on the y axis.", + { + { "1", NULL }, + { "0.75", NULL }, + { "0.76", NULL }, + { "0.77", NULL }, + { "0.78", NULL }, + { "0.79", NULL }, + { "0.80", NULL }, + { "0.81", NULL }, + { "0.82", NULL }, + { "0.83", NULL }, + { "0.84", NULL }, + { "0.85", NULL }, + { "0.86", NULL }, + { "0.87", NULL }, + { "0.88", NULL }, + { "0.89", NULL }, + { "0.90", NULL }, + { "0.91", NULL }, + { "0.92", NULL }, + { "0.93", NULL }, + { "0.94", NULL }, + { "0.95", NULL }, + { "0.96", NULL }, + { "0.97", NULL }, + { "0.98", NULL }, + { "0.99", NULL }, + { "1.00", NULL }, + { "1.01", NULL }, + { "1.02", NULL }, + { "1.03", NULL }, + { "1.04", NULL }, + { "1.05", NULL }, + { "1.06", NULL }, + { "1.07", NULL }, + { "1.08", NULL }, + { "1.09", NULL }, + { "1.10", NULL }, + { "1.11", NULL }, + { "1.12", NULL }, + { "1.13", NULL }, + { "1.14", NULL }, + { "1.15", NULL }, + { "1.16", NULL }, + { "1.17", NULL }, + { "1.18", NULL }, + { "1.19", NULL }, + { "1.20", NULL }, + { "1.21", NULL }, + { "1.22", NULL }, + { "1.23", NULL }, + { "1.24", NULL }, + { "1.25", NULL }, + { NULL, NULL }, + }, + "1", + }, + { "pcsx_rearmed_dithering", "Enable Dithering", "If Off, disables the dithering pattern the PSX applies to combat color banding.", diff --git a/frontend/plugin.c b/frontend/plugin.c index 1fcd7be..30b0e08 100644 --- a/frontend/plugin.c +++ b/frontend/plugin.c @@ -58,12 +58,15 @@ static long PADreadPort1(PadDataS *pad) { 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) + 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; } @@ -78,12 +81,15 @@ static long PADreadPort2(PadDataS *pad) { 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) + 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; } diff --git a/include/psemu_plugin_defs.h b/include/psemu_plugin_defs.h index 6fc59b7..545cfca 100644 --- a/include/psemu_plugin_defs.h +++ b/include/psemu_plugin_defs.h @@ -219,6 +219,9 @@ typedef struct //configuration mode Request 0x43 int configMode; unsigned char reserved[87]; + + //Lightgun values + int absoluteX,absoluteY; } PadDataS; diff --git a/libpcsxcore/plugins.c b/libpcsxcore/plugins.c index af7ebed..67fe835 100644 --- a/libpcsxcore/plugins.c +++ b/libpcsxcore/plugins.c @@ -643,6 +643,48 @@ void _PADstartPoll(PadDataS *pad) { memcpy(buf, stdpar, 8); respSize = 8; break; + case PSE_PAD_TYPE_GUNCON: // GUNCON - gun controller SLPH-00034 from Namco + stdpar[0] = 0x63; + stdpar[1] = 0x5a; + stdpar[2] = pad->buttonStatus & 0xff; + stdpar[3] = pad->buttonStatus >> 8; + + //This code assumes an X resolution of 256 and a Y resolution of 240 + int xres = 256; + int yres = 240; + + //The code wants an input range for x and y of 0-1023 we passed in -32767 -> 32767 + int absX = (pad->absoluteX / 64) + 512; + int absY = (pad->absoluteY / 64) + 512; + + //Keep within limits + if (absX > 1023) absX = 1023; + if (absX < 0) absX = 0; + if (absY > 1023) absY = 1023; + if (absY < 0) absY = 0; + + stdpar[4] = 0x5a - (xres - 256) / 3 + (((xres - 256) / 3 + 356) * absX >> 10); + stdpar[5] = (0x5a - (xres - 256) / 3 + (((xres - 256) / 3 + 356) * absX >> 10)) >> 8; + stdpar[6] = 0x20 + (yres * absY >> 10); + stdpar[7] = (0x20 + (yres * absY >> 10)) >> 8; + + //Offscreen - Point at the side of the screen so PSX thinks you are pointing offscreen + //Required as a mouse can't be offscreen + //Coordinates X=0001h, Y=000Ah indicates "no light" + //This will mean you cannot shoot the very each of the screen + //ToDo read offscreen range from settings if useful to change + int OffscreenRange = 2; + if (absX < (OffscreenRange) || absX > (1023 - OffscreenRange) || absY < (OffscreenRange) || absY > (1023 - OffscreenRange)) + { + stdpar[4] = 0x01; + stdpar[5] = 0x00; + stdpar[6] = 0x0A; + stdpar[7] = 0x00; + } + + memcpy(buf, stdpar, 8); + respSize = 8; + break; case PSE_PAD_TYPE_ANALOGPAD: // scph1150 stdpar[0] = 0x73; stdpar[2] = pad->buttonStatus & 0xff; diff --git a/plugins/dfinput/main.c b/plugins/dfinput/main.c index 4204b86..af6b80b 100644 --- a/plugins/dfinput/main.c +++ b/plugins/dfinput/main.c @@ -1,5 +1,5 @@ /* - * (C) Gražvydas "notaz" Ignotas, 2011 + * (C) Gražvydas "notaz" Ignotas, 2011 * * This work is licensed under the terms of any of these licenses * (at your option): @@ -40,10 +40,11 @@ static int old_controller_type1 = -1, old_controller_type2 = -1; pad_init(); \ break; \ case PSE_PAD_TYPE_GUNCON: \ - PAD##n##_startPoll = PADstartPoll_guncon; \ - PAD##n##_poll = PADpoll_guncon; \ - guncon_init(); \ - break; \ + //Removed for new Guncon functionality, may have been required for very old touchscreen support + //PAD##n##_startPoll = PADstartPoll_guncon; \ + //PAD##n##_poll = PADpoll_guncon; \ + //guncon_init(); \ + //break; \ case PSE_PAD_TYPE_NEGCON: \ case PSE_PAD_TYPE_GUN: \ default: \ |