From ee07912456bd101d65cb166bfda76828519c83dd Mon Sep 17 00:00:00 2001 From: David Walters Date: Thu, 30 Nov 2017 18:15:27 +0000 Subject: [PATCH] Support 6Player Adaptor --- input.cpp | 136 +++++++++++++++++++++++++++++------------- input.h | 2 + libretro.cpp | 48 ++++++++++----- libretro_settings.cpp | 3 +- libretro_settings.h | 2 + mednafen/settings.cpp | 4 -- mednafen/ss/smpc.cpp | 1 + 7 files changed, 133 insertions(+), 63 deletions(-) diff --git a/input.cpp b/input.cpp index 0201ce2..0f34cf6 100644 --- a/input.cpp +++ b/input.cpp @@ -1,5 +1,6 @@ #include "libretro.h" +#include "libretro_settings.h" #include "mednafen/mednafen-types.h" #include "mednafen/ss/ss.h" #include "mednafen/ss/smpc.h" @@ -13,9 +14,9 @@ static retro_environment_t environ_cb; // cached during input_set_env -#define MAX_CONTROLLERS 2 +#define MAX_CONTROLLERS 12 // 2x 6 player adapters -static unsigned players = MAX_CONTROLLERS; +static unsigned players = 2; static int astick_deadzone = 0; static int trigger_deadzone = 0; @@ -221,51 +222,48 @@ void input_init_env( retro_environment_t _environ_cb ) // Cache this environ_cb = _environ_cb; +#define RETRO_DESCRIPTOR_BLOCK( _user ) \ + { _user, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, \ + { _user, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, \ + { _user, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, \ + { _user, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, \ + { _user, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "A Button" }, \ + { _user, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "B Button" }, \ + { _user, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "C Button" }, \ + { _user, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "X Button" }, \ + { _user, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Y Button" }, \ + { _user, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "Z Button" }, \ + { _user, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L Button" }, \ + { _user, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R Button" }, \ + { _user, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start Button" }, \ + { _user, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Mode Switch" }, \ + { _user, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Analog X" }, \ + { _user, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Analog Y" }, \ + { _user, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_TRIGGER, "Gun Trigger" }, \ + { _user, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_START, "Gun Start" }, \ + { _user, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_RELOAD, "Gun Reload" } + struct retro_input_descriptor desc[] = { - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "A Button" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "B Button" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "C Button" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "X Button" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Y Button" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "Z Button" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L Button" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R Button" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start Button" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Mode Switch" }, - { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Analog X" }, - { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Analog Y" }, - { 0, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_TRIGGER, "Gun Trigger" }, - { 0, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_START, "Gun Start" }, - { 0, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_RELOAD, "Gun Reload" }, - - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "A Button" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "B Button" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "C Button" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "X Button" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Y Button" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "Z Button" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L Button" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R Button" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start Button" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Mode Switch" }, - { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Analog X" }, - { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Analog Y" }, - { 1, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_TRIGGER, "Gun Trigger" }, - { 1, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_START, "Gun Start" }, - { 1, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_RELOAD, "Gun Reload" }, + RETRO_DESCRIPTOR_BLOCK( 0 ), + RETRO_DESCRIPTOR_BLOCK( 1 ), + RETRO_DESCRIPTOR_BLOCK( 2 ), + RETRO_DESCRIPTOR_BLOCK( 3 ), + RETRO_DESCRIPTOR_BLOCK( 4 ), + RETRO_DESCRIPTOR_BLOCK( 5 ), + RETRO_DESCRIPTOR_BLOCK( 6 ), + RETRO_DESCRIPTOR_BLOCK( 7 ), + RETRO_DESCRIPTOR_BLOCK( 8 ), + RETRO_DESCRIPTOR_BLOCK( 9 ), + RETRO_DESCRIPTOR_BLOCK( 10 ), + RETRO_DESCRIPTOR_BLOCK( 11 ), { 0 }, }; +#undef RETRO_DESCRIPTOR_BLOCK + + // Send to front-end environ_cb( RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc ); } @@ -275,15 +273,27 @@ void input_set_env( retro_environment_t environ_cb ) { { input_device_types, INPUT_DEVICE_TYPES_COUNT }, { input_device_types, INPUT_DEVICE_TYPES_COUNT }, + { input_device_types, INPUT_DEVICE_TYPES_COUNT }, + { input_device_types, INPUT_DEVICE_TYPES_COUNT }, + { input_device_types, INPUT_DEVICE_TYPES_COUNT }, + { input_device_types, INPUT_DEVICE_TYPES_COUNT }, + { input_device_types, INPUT_DEVICE_TYPES_COUNT }, + { input_device_types, INPUT_DEVICE_TYPES_COUNT }, + { input_device_types, INPUT_DEVICE_TYPES_COUNT }, + { input_device_types, INPUT_DEVICE_TYPES_COUNT }, + { input_device_types, INPUT_DEVICE_TYPES_COUNT }, + { input_device_types, INPUT_DEVICE_TYPES_COUNT }, + { 0 }, }; + // Send to front-end environ_cb( RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports ); } void input_init() { - // Initialise to default and bind input buffers to SMPC emulation. + // Initialise to default pad type and bind input buffers to SMPC emulation. for ( unsigned i = 0; i < MAX_CONTROLLERS; ++i ) { input_type[ i ] = RETRO_DEVICE_JOYPAD; @@ -637,7 +647,7 @@ int input_StateAction( StateMem* sm, const unsigned load, const bool data_only ) SFORMAT StateRegs[] = { - SFARRAY16N( input_mode, MAX_CONTROLLERS, "mode" ), + SFARRAY16N( input_mode, MAX_CONTROLLERS, "pad-mode" ), SFEND }; @@ -704,4 +714,44 @@ void retro_set_controller_port_device( unsigned in_port, unsigned device ) }; // valid port? } +void input_multitap( int port, bool enabled ) +{ + switch ( port ) + { + case 1: // PORT 1 + if ( enabled != setting_multitap_port1 ) { + setting_multitap_port1 = enabled; + if ( setting_multitap_port1 ) { + log_cb( RETRO_LOG_INFO, "Connected 6Player Adaptor to Port 1\n" ); + } else { + log_cb( RETRO_LOG_INFO, "Removed 6Player Adaptor from Port 1\n" ); + } + SMPC_SetMultitap( 0, setting_multitap_port1 ); + } + break; + + case 2: // PORT 2 + if ( enabled != setting_multitap_port2 ) { + setting_multitap_port2 = enabled; + if ( setting_multitap_port2 ) { + log_cb( RETRO_LOG_INFO, "Connected 6Player Adaptor to Port 2\n" ); + } else { + log_cb( RETRO_LOG_INFO, "Removed 6Player Adaptor from Port 2\n" ); + } + SMPC_SetMultitap( 1, setting_multitap_port2 ); + } + break; + + }; // switch ( port ) + + // Update players count + players = 2; + if ( setting_multitap_port1 ) { + players += 5; + } + if ( setting_multitap_port2 ) { + players += 5; + } +} + //============================================================================== diff --git a/input.h b/input.h index 4f446ad..aeec617 100644 --- a/input.h +++ b/input.h @@ -22,4 +22,6 @@ extern void input_update( retro_input_state_t input_state_cb ); // save state function for input extern int input_StateAction( StateMem* sm, const unsigned load, const bool data_only ); +extern void input_multitap( int port, bool enabled ); + #endif diff --git a/libretro.cpp b/libretro.cpp index b41d138..99fd3f8 100644 --- a/libretro.cpp +++ b/libretro.cpp @@ -1188,22 +1188,12 @@ static bool InitCommon(const unsigned cpucache_emumode, const unsigned cart_type MDFN_printf("\n"); #endif - for(unsigned sp = 0; sp < 2; sp++) - { - char buf[64]; - bool sv; - - snprintf(buf, sizeof(buf), "ss.input.sport%u.multitap", sp + 1); - sv = MDFN_GetSettingB(buf); - SMPC_SetMultitap(sp, sv); - -#if 0 - MDFN_printf(_("Multitap on Saturn Port %u: %s\n"), sp + 1, sv ? _("Enabled") : _("Disabled")); -#endif - } + // Apply multi-tap state to SMPC + SMPC_SetMultitap( 0, setting_multitap_port1 ); + SMPC_SetMultitap( 1, setting_multitap_port2 ); - for(unsigned vp = 0; vp < 12; vp++) + /*for(unsigned vp = 0; vp < 12; vp++) { char buf[64]; uint32 sv; @@ -1211,7 +1201,7 @@ static bool InitCommon(const unsigned cpucache_emumode, const unsigned cart_type snprintf(buf, sizeof(buf), "ss.input.port%u.gun_chairs", vp + 1); sv = MDFN_GetSettingUI(buf); SMPC_SetCrosshairsColor(vp, sv); - } + }*/ // // // @@ -1864,6 +1854,32 @@ static void check_variables(bool startup) setting_cart = CART_ULTRAMAN; } + var.key = "beetle_saturn_multitap_port1"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + bool connected = false; + if (!strcmp(var.value, "enabled")) + connected = true; + else if (!strcmp(var.value, "disabled")) + connected = false; + + input_multitap( 1, connected ); + } + + var.key = "beetle_saturn_multitap_port2"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + bool connected = false; + if (!strcmp(var.value, "enabled")) + connected = true; + else if (!strcmp(var.value, "disabled")) + connected = false; + + input_multitap( 2, connected ); + } + var.key = "beetle_saturn_cdimagecache"; if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) @@ -2308,6 +2324,8 @@ void retro_set_environment( retro_environment_t cb ) static const struct retro_variable vars[] = { { "beetle_saturn_region", "System Region; Auto Detect|Japan|North America|Europe|South Korea|Asia (NTSC)|Asia (PAL)|Brazil|Latin America" }, { "beetle_saturn_cart", "Cartridge; Auto Detect|None|Backup Memory|Extended RAM (1MB)|Extended RAM (4MB)|The King of Fighters '95|Ultraman: Hikari no Kyojin Densetsu" }, + { "beetle_saturn_multitap_port1", "6Player Adaptor on Port 1; disabled|enabled" }, + { "beetle_saturn_multitap_port2", "6Player Adaptor on Port 2; disabled|enabled" }, { "beetle_saturn_analog_stick_deadzone", "3D Pad - Analog Deadzone; 15%|20%|25%|30%|0%|5%|10%"}, { "beetle_saturn_trigger_deadzone", "3D Pad - Trigger Deadzone; 15%|20%|25%|30%|0%|5%|10%"}, { "beetle_saturn_mouse_sensitivity", "Mouse - Sensitivity; 100%|105%|110%|115%|120%|125%|130%|135%|140%|145%|150%|155%|160%|165%|170%|175%|180%|185%|190%|195%|200%|5%|10%|15%|20%|25%|30%|35%|40%|45%|50%|55%|60%|65%|70%|75%|80%|85%|90%|95%" }, diff --git a/libretro_settings.cpp b/libretro_settings.cpp index 824f13a..824832b 100644 --- a/libretro_settings.cpp +++ b/libretro_settings.cpp @@ -10,4 +10,5 @@ int setting_last_scanline = 239; int setting_last_scanline_pal = 287; int setting_gun_crosshair = SETTING_GUN_CROSSHAIR_CROSS; bool setting_disc_test = false; - +bool setting_multitap_port1; +bool setting_multitap_port2; diff --git a/libretro_settings.h b/libretro_settings.h index 24dbd21..0fd369c 100644 --- a/libretro_settings.h +++ b/libretro_settings.h @@ -20,5 +20,7 @@ extern int setting_last_scanline; extern int setting_last_scanline_pal; extern int setting_gun_crosshair; extern bool setting_disc_test; +extern bool setting_multitap_port1; +extern bool setting_multitap_port2; #endif diff --git a/mednafen/settings.cpp b/mednafen/settings.cpp index 1787b93..4053039 100644 --- a/mednafen/settings.cpp +++ b/mednafen/settings.cpp @@ -67,8 +67,6 @@ bool MDFN_GetSettingB(const char *name) return int(setting_smpc_autortc); if (!strcmp("ss.bios_sanity", name)) return true; - if (!strcmp("ss.cd_sanity", name)) - return false; if (!strcmp("ss.midsync", name)) return false; /* CDROM */ @@ -77,8 +75,6 @@ bool MDFN_GetSettingB(const char *name) /* FILESYS */ if (!strcmp("filesys.untrusted_fip_check", name)) return 0; - if (!strcmp("filesys.disablesavegz", name)) - return 1; fprintf(stderr, "unhandled setting B: %s\n", name); return 0; } diff --git a/mednafen/ss/smpc.cpp b/mednafen/ss/smpc.cpp index 7c57883..f93faf5 100644 --- a/mednafen/ss/smpc.cpp +++ b/mednafen/ss/smpc.cpp @@ -264,6 +264,7 @@ static void MapPorts(void) for(unsigned i = 0; i < 6; i++) { IODevice* const tsd = VirtualPorts[vp++]; + if (!tsd) continue; // libretro fix - patch for multi-tap set on startup. if(SPorts[sp]->GetSubDevice(i) != tsd) tsd->Power();