mirror of
https://github.com/libretro/beetle-psx-libretro.git
synced 2024-12-11 19:03:36 +00:00
commit
92ba9ef75d
94
input.cpp
94
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
|
||||
{
|
||||
@ -54,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 ] =
|
||||
{
|
||||
@ -66,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 },
|
||||
@ -428,6 +431,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;
|
||||
@ -465,27 +473,11 @@ 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;
|
||||
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 +486,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 +530,45 @@ 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;
|
||||
}
|
||||
|
||||
// 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 );
|
||||
}
|
||||
|
||||
// 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 );
|
||||
}
|
||||
|
||||
// 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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
@ -851,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 ] );
|
||||
|
2
input.h
2
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();
|
||||
|
@ -2829,6 +2829,14 @@ static void check_variables(bool startup)
|
||||
setting_psx_multitap_port_2 = false;
|
||||
}
|
||||
|
||||
var.key = option_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
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user