From 6c99f05cf74193c9b9a2d813f5bad6352f1c38be Mon Sep 17 00:00:00 2001 From: David Walters Date: Sun, 12 Nov 2017 11:39:29 +0000 Subject: [PATCH] Include 3D Pad mode switch setting in save state. --- input.cpp | 23 ++++++++++++++++++++--- input.h | 6 ++++++ libretro.cpp | 6 ++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/input.cpp b/input.cpp index 3bfbb19..091f20b 100644 --- a/input.cpp +++ b/input.cpp @@ -3,6 +3,7 @@ #include "mednafen/mednafen-types.h" #include "mednafen/ss/ss.h" #include "mednafen/ss/smpc.h" +#include "mednafen/state.h" #include #include @@ -38,7 +39,7 @@ static uint32_t input_type[ MAX_CONTROLLERS ] = {0}; #define INPUT_MODE_3D_PAD_DEFAULT INPUT_MODE_3D_PAD_ANALOG // Mode switch for 3D Control Pad (per player) -static uint32_t input_mode[ MAX_CONTROLLERS ] = {0}; +static uint16_t input_mode[ MAX_CONTROLLERS ] = {0}; @@ -308,8 +309,8 @@ void input_update( retro_input_state_t input_state_cb ) { // Handle MODE button as a switch - unsigned prev = ( input_mode[iplayer] & INPUT_MODE_3D_PAD_PREVIOUS_MASK ); - unsigned held = input_state_cb( iplayer, RETRO_DEVICE_JOYPAD, 0, input_map_3d_pad_mode_switch ) + uint16_t prev = ( input_mode[iplayer] & INPUT_MODE_3D_PAD_PREVIOUS_MASK ); + uint16_t held = input_state_cb( iplayer, RETRO_DEVICE_JOYPAD, 0, input_map_3d_pad_mode_switch ) ? INPUT_MODE_3D_PAD_PREVIOUS_MASK : 0; // Rising edge trigger @@ -437,6 +438,22 @@ void input_update( retro_input_state_t input_state_cb ) }; // for each player } +// save state function for input +int input_StateAction( StateMem* sm, const unsigned load, const bool data_only ) +{ + int success; + + SFORMAT StateRegs[] = + { + SFARRAY16N( input_mode, sizeof( input_mode ), "mode" ), + SFEND + }; + + success = MDFNSS_StateAction( sm, load, data_only, StateRegs, "LRINPUT" ); + + // ok? + return success; +} //------------------------------------------------------------------------------ // Libretro Interface diff --git a/input.h b/input.h index 8b6eea5..1ab7b4f 100644 --- a/input.h +++ b/input.h @@ -1,6 +1,9 @@ #ifndef __INPUT_H__ #define __INPUT_H__ +#include "libretro.h" +#include "mednafen/state.h" + // These input routines tell libretro about Saturn peripherals // and map input from the abstract 'retropad' into Saturn land. @@ -14,4 +17,7 @@ extern void input_set_deadzone_stick( int percent ); 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 ); + #endif diff --git a/libretro.cpp b/libretro.cpp index 3792c70..246c17e 100644 --- a/libretro.cpp +++ b/libretro.cpp @@ -2012,6 +2012,12 @@ MDFN_COLD int LibRetro_StateAction( StateMem* sm, const unsigned load, const boo return 0; } + success = input_StateAction( sm, load, data_only ); + if ( success == 0 ) { + log_cb( RETRO_LOG_ERROR, "Input save-state failed.\n" ); + return 0; + } + if ( load ) { BackupRAM_Dirty = true;