From 98bf089db28f8dc44695b657ea70752046999c3f Mon Sep 17 00:00:00 2001 From: David Walters Date: Sun, 19 Nov 2017 23:57:20 +0000 Subject: [PATCH 1/3] Gun trigger mouse button swap option; Better Guncon off-screen shot detection. --- input.cpp | 76 +++++++++++++++++++++++++++++++--------------- input.h | 2 ++ libretro.cpp | 9 ++++++ libretro_options.h | 2 ++ 4 files changed, 64 insertions(+), 25 deletions(-) diff --git a/input.cpp b/input.cpp index b0d30b8f..23d47214 100644 --- a/input.cpp +++ b/input.cpp @@ -19,6 +19,7 @@ static FrontIO* FIO; // cached in input_set_fio static unsigned players = 2; static bool enable_analog_calibration = false; +static bool gun_trigger_rmb = false; typedef union { @@ -428,6 +429,11 @@ void input_set_player_count( unsigned _players ) players = _players; } +void input_set_gun_trigger( bool use_rmb ) +{ + gun_trigger_rmb = use_rmb; +} + unsigned input_get_player_count() { return players; @@ -468,24 +474,7 @@ void input_update( retro_input_state_t input_state_cb ) { p_input->u8[4] = 0; - uint8_t trigger = 0; - - // trigger - if ( input_state_cb( iplayer, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_TRIGGER ) ) { - trigger = ( 1 << 0 ); // Trigger - } - - // a - if ( input_state_cb( iplayer, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT ) || - input_state_cb( iplayer, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_BUTTON_4 ) ) { - p_input->u8[4] |= ( 1 << 1 ); // a - } - - // b - if ( input_state_cb( iplayer, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_MIDDLE ) || - input_state_cb( iplayer, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_BUTTON_5 ) ) { - p_input->u8[4] |= ( 1 << 2 ); // b - } + uint8_t shot_type = 0; // -- Position @@ -494,17 +483,24 @@ void input_update( retro_input_state_t input_state_cb ) gun_x_raw = input_state_cb( iplayer, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X ); gun_y_raw = input_state_cb( iplayer, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y ); + int gun_edge_detect = 32700; + // off-screen? - if ( ( gun_x_raw == 0 ) && ( gun_y_raw == 0 ) ) + if ( ( ( gun_x_raw == 0 ) && ( gun_y_raw == 0 ) ) || + ( gun_x_raw < -gun_edge_detect ) || + ( gun_x_raw > gun_edge_detect ) || + ( gun_y_raw < -gun_edge_detect ) || + ( gun_y_raw > gun_edge_detect ) ) { - if ( trigger ) { - trigger |= ( 1 << 3 ); // off-screen flag - } - gun_x = 0; - gun_y = 0; + shot_type = ( 1 << 3 ); // Off-screen shot + + gun_x = -16384; // magic position to disable cross-hair drawing. + gun_y = -16384; } else { + shot_type = ( 1 << 0 ); // On-screen shot! + // // .. scale into screen space: // NOTE: this is complete hacky guesswork for this first pass, need to re-write. @@ -531,7 +527,37 @@ void input_update( retro_input_state_t input_state_cb ) p_input->gun_pos[ 0 ] = gun_x; p_input->gun_pos[ 1 ] = gun_y; - p_input->u8[4] |= trigger; + + unsigned mbutton_trigger; + unsigned mbutton_a; + unsigned mbutton_b; + + if ( gun_trigger_rmb ) { + mbutton_trigger = RETRO_DEVICE_ID_MOUSE_RIGHT; + mbutton_a = RETRO_DEVICE_ID_MOUSE_LEFT; + mbutton_b = RETRO_DEVICE_ID_MOUSE_MIDDLE; + } else { + mbutton_trigger = RETRO_DEVICE_ID_MOUSE_LEFT; + mbutton_a = RETRO_DEVICE_ID_MOUSE_RIGHT; + mbutton_b = RETRO_DEVICE_ID_MOUSE_MIDDLE; + } + + // trigger + if ( input_state_cb( iplayer, RETRO_DEVICE_MOUSE, 0, mbutton_trigger ) ) { + p_input->u8[4] = shot_type; + } + + // a + if ( input_state_cb( iplayer, RETRO_DEVICE_MOUSE, 0, mbutton_a ) || + input_state_cb( iplayer, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_BUTTON_4 ) ) { + p_input->u8[4] |= ( 1 << 1 ); // a + } + + // b + if ( input_state_cb( iplayer, RETRO_DEVICE_MOUSE, 0, mbutton_b ) || + input_state_cb( iplayer, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_BUTTON_5 ) ) { + p_input->u8[4] |= ( 1 << 2 ); // b + } } break; diff --git a/input.h b/input.h index 3f88f558..27313aad 100644 --- a/input.h +++ b/input.h @@ -18,6 +18,8 @@ extern void input_enable_calibration( bool enable ); extern void input_set_env( retro_environment_t environ_cb ); +extern void input_set_gun_trigger( bool use_rmb ); + extern void input_set_player_count( unsigned players ); extern unsigned input_get_player_count(); diff --git a/libretro.cpp b/libretro.cpp index 4e88269e..b2e53160 100644 --- a/libretro.cpp +++ b/libretro.cpp @@ -2829,6 +2829,14 @@ static void check_variables(bool startup) setting_psx_multitap_port_2 = false; } + var.key = input_set_gun_trigger; + + if ( environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value ) + { + bool newval = (!strcmp(var.value, "Right Mouse Button")); + input_set_gun_trigger( newval ); + } + var.key = option_initial_scanline; if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) @@ -3731,6 +3739,7 @@ void retro_set_environment(retro_environment_t cb) { option_analog_toggle, "DualShock Analog button toggle; disabled|enabled" }, { option_multitap1, "Port 1: Multitap enable; disabled|enabled" }, { option_multitap2, "Port 2: Multitap enable; disabled|enabled" }, + { option_gun_trigger, "Gun Trigger; Left Mouse Button|Right Mouse Button" }, #ifndef EMSCRIPTEN { option_cd_access_method, "CD Access Method (restart); sync|async|precache" }, #endif diff --git a/libretro_options.h b/libretro_options.h index 0d605c2a..117b4b4b 100644 --- a/libretro_options.h +++ b/libretro_options.h @@ -40,6 +40,7 @@ #define option_analog_toggle "beetle_psx_hw_analog_toggle" #define option_multitap1 "beetle_psx_hw_enable_multitap_port1" #define option_multitap2 "beetle_psx_hw_enable_multitap_port2" +#define option_gun_trigger "beetle_psx_hw_gun_trigger" #define option_cpu_overclock "beetle_psx_hw_cpu_overclock" #define option_cd_access_method "beetle_psx_hw_cd_access_method" #define option_skip_bios "beetle_psx_hw_skipbios" @@ -75,6 +76,7 @@ #define option_analog_toggle "beetle_psx_analog_toggle" #define option_multitap1 "beetle_psx_enable_multitap_port1" #define option_multitap2 "beetle_psx_enable_multitap_port2" +#define option_gun_trigger "beetle_psx_gun_trigger" #define option_cpu_overclock "beetle_psx_cpu_overclock" #define option_cd_access_method "beetle_psx_cd_access_method" #define option_skip_bios "beetle_psx_skipbios" From c08eaeef77b6f1721c497b41a3c639dbce26f338 Mon Sep 17 00:00:00 2001 From: David Walters Date: Sun, 19 Nov 2017 23:58:48 +0000 Subject: [PATCH 2/3] gun - mouse button swap option --- libretro.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libretro.cpp b/libretro.cpp index b2e53160..8f763a34 100644 --- a/libretro.cpp +++ b/libretro.cpp @@ -2829,7 +2829,7 @@ static void check_variables(bool startup) setting_psx_multitap_port_2 = false; } - var.key = input_set_gun_trigger; + var.key = option_gun_trigger; if ( environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value ) { From fd00f13f56a3fbcfd57f5245514386d0b1a29109 Mon Sep 17 00:00:00 2001 From: David Walters Date: Mon, 20 Nov 2017 00:31:37 +0000 Subject: [PATCH 3/3] Justifier support --- input.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/input.cpp b/input.cpp index 23d47214..b5162d55 100644 --- a/input.cpp +++ b/input.cpp @@ -55,10 +55,11 @@ static uint32_t input_type[ MAX_CONTROLLERS ] = {0}; #define RETRO_DEVICE_PS_ANALOG RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_ANALOG, 0) #define RETRO_DEVICE_PS_ANALOG_JOYSTICK RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_ANALOG, 2) #define RETRO_DEVICE_PS_GUNCON RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_LIGHTGUN, 0) +#define RETRO_DEVICE_PS_JUSTIFIER RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_LIGHTGUN, 1) #define RETRO_DEVICE_PS_MOUSE RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_MOUSE, 0) #define RETRO_DEVICE_PS_NEGCON RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_ANALOG, 3) -enum { INPUT_DEVICE_TYPES_COUNT = 1 /*none*/ + 7 }; // <-- update me! +enum { INPUT_DEVICE_TYPES_COUNT = 1 /*none*/ + 8 }; // <-- update me! static const struct retro_controller_description input_device_types[ INPUT_DEVICE_TYPES_COUNT ] = { @@ -67,6 +68,7 @@ static const struct retro_controller_description input_device_types[ INPUT_DEVIC { "Analog Controller", RETRO_DEVICE_PS_ANALOG }, { "Analog Joystick", RETRO_DEVICE_PS_ANALOG_JOYSTICK }, { "Guncon / G-Con 45", RETRO_DEVICE_PS_GUNCON }, + { "Justifier", RETRO_DEVICE_PS_JUSTIFIER }, { "Mouse", RETRO_DEVICE_PS_MOUSE }, { "neGcon", RETRO_DEVICE_PS_NEGCON }, { NULL, 0 }, @@ -471,6 +473,7 @@ void input_update( retro_input_state_t input_state_cb ) break; case RETRO_DEVICE_PS_GUNCON: + case RETRO_DEVICE_PS_JUSTIFIER: { p_input->u8[4] = 0; @@ -544,19 +547,27 @@ void input_update( retro_input_state_t input_state_cb ) // trigger if ( input_state_cb( iplayer, RETRO_DEVICE_MOUSE, 0, mbutton_trigger ) ) { - p_input->u8[4] = shot_type; + p_input->u8[4] |= shot_type; } - // a + // Guncon 'A' or Justifier 'Aux' if ( input_state_cb( iplayer, RETRO_DEVICE_MOUSE, 0, mbutton_a ) || input_state_cb( iplayer, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_BUTTON_4 ) ) { - p_input->u8[4] |= ( 1 << 1 ); // a + p_input->u8[4] |= ( 1 << 1 ); } - // b + // Guncon 'B' or Justifier 'Start' if ( input_state_cb( iplayer, RETRO_DEVICE_MOUSE, 0, mbutton_b ) || input_state_cb( iplayer, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_BUTTON_5 ) ) { - p_input->u8[4] |= ( 1 << 2 ); // b + p_input->u8[4] |= ( 1 << 2 ); + } + + // Justifier 'Start' + if ( input_type[ iplayer ] == RETRO_DEVICE_PS_JUSTIFIER ) + { + if ( input_state_cb( iplayer, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START ) ) { + p_input->u8[4] |= ( 1 << 2 ); + } } } @@ -877,6 +888,11 @@ void retro_set_controller_port_device( unsigned in_port, unsigned device ) SetInput( in_port, "guncon", (uint8*)&input_data[ in_port ] ); break; + case RETRO_DEVICE_PS_JUSTIFIER: + log_cb( RETRO_LOG_INFO, "Controller %u: Justifier\n", (in_port+1) ); + SetInput( in_port, "justifier", (uint8*)&input_data[ in_port ] ); + break; + case RETRO_DEVICE_PS_MOUSE: log_cb( RETRO_LOG_INFO, "Controller %u: Mouse\n", (in_port+1) ); SetInput( in_port, "mouse", (uint8*)&input_data[ in_port ] );