From 4002e2e302e9f85b4b6983abd862ef0fef397095 Mon Sep 17 00:00:00 2001 From: SergioMartin86 Date: Sat, 6 Apr 2024 16:04:22 +0200 Subject: [PATCH] Adding minimal set of changes to the savestate procedures to ensure full re-record sync --- core/input_hw/gamepad.c | 9 +-------- core/input_hw/gamepad.h | 10 ++++++++++ core/shared.h | 1 + core/state.c | 16 +++++++++++++++- core/system.c | 2 +- core/system.h | 1 + 6 files changed, 29 insertions(+), 10 deletions(-) diff --git a/core/input_hw/gamepad.c b/core/input_hw/gamepad.c index 24efa9e..305a835 100644 --- a/core/input_hw/gamepad.c +++ b/core/input_hw/gamepad.c @@ -40,13 +40,7 @@ #include "shared.h" #include "gamepad.h" -static struct -{ - uint8 State; - uint8 Counter; - uint8 Timeout; - uint32 Latency; -} gamepad[MAX_DEVICES]; +struct gamepad_t gamepad[MAX_DEVICES]; static struct { @@ -56,7 +50,6 @@ static struct static uint8 latch; - void gamepad_reset(int port) { /* default state (Gouketsuji Ichizoku / Power Instinct, Samurai Spirits / Samurai Shodown) */ diff --git a/core/input_hw/gamepad.h b/core/input_hw/gamepad.h index 1a04bf3..a823175 100644 --- a/core/input_hw/gamepad.h +++ b/core/input_hw/gamepad.h @@ -40,6 +40,16 @@ #ifndef _GAMEPAD_H_ #define _GAMEPAD_H_ +struct gamepad_t +{ + uint8 State; + uint8 Counter; + uint8 Timeout; + uint32 Latency; +}; + +extern struct gamepad_t gamepad[MAX_DEVICES]; + /* Function prototypes */ extern void gamepad_reset(int port); extern void gamepad_refresh(int port); diff --git a/core/shared.h b/core/shared.h index 700f27b..8da963d 100644 --- a/core/shared.h +++ b/core/shared.h @@ -21,6 +21,7 @@ #include "membnk.h" #include "io_ctrl.h" #include "input.h" +#include "gamepad.h" #include "sound.h" #include "psg.h" #include "ym2413.h" diff --git a/core/state.c b/core/state.c index 79264f1..fd89f10 100644 --- a/core/state.c +++ b/core/state.c @@ -71,6 +71,9 @@ int state_load(unsigned char *state) zbank_memory_map[i].write = zbank_write_vdp; } + /* SYSTEM */ + load_param(&pause_b, sizeof(pause_b)); + /* GENESIS */ if ((system_hw & SYSTEM_PBC) == SYSTEM_MD) { @@ -109,6 +112,9 @@ int state_load(unsigned char *state) io_reg[0] = 0x80 | (region_code >> 1); } + /* CONTROLLERS */ + load_param(gamepad, sizeof(gamepad)); + /* VDP */ bufferptr += vdp_context_load(&state[bufferptr]); @@ -152,6 +158,7 @@ int state_load(unsigned char *state) load_param(&m68k.cycles, sizeof(m68k.cycles)); load_param(&m68k.int_level, sizeof(m68k.int_level)); load_param(&m68k.stopped, sizeof(m68k.stopped)); + load_param(&m68k.refresh_cycles, sizeof(m68k.refresh_cycles)); } /* Z80 */ @@ -200,6 +207,9 @@ int state_save(unsigned char *state) memcpy(version,STATE_VERSION,16); save_param(version, 16); + /* SYSTEM */ + save_param(&pause_b, sizeof(pause_b)); + /* GENESIS */ if ((system_hw & SYSTEM_PBC) == SYSTEM_MD) { @@ -215,7 +225,10 @@ int state_save(unsigned char *state) /* IO */ save_param(io_reg, sizeof(io_reg)); - + + /* CONTROLLERS */ + save_param(gamepad, sizeof(gamepad)); + /* VDP */ bufferptr += vdp_context_save(&state[bufferptr]); @@ -251,6 +264,7 @@ int state_save(unsigned char *state) save_param(&m68k.cycles, sizeof(m68k.cycles)); save_param(&m68k.int_level, sizeof(m68k.int_level)); save_param(&m68k.stopped, sizeof(m68k.stopped)); + save_param(&m68k.refresh_cycles, sizeof(m68k.refresh_cycles)); } /* Z80 */ diff --git a/core/system.c b/core/system.c index a7eb370..fcf61e0 100644 --- a/core/system.c +++ b/core/system.c @@ -51,7 +51,7 @@ uint8 system_bios; uint32 system_clock; int16 SVP_cycles = 800; -static uint8 pause_b; +uint8 pause_b; static EQSTATE eq[2]; static int16 llp,rrp; diff --git a/core/system.h b/core/system.h index fb6ca76..888b7c2 100644 --- a/core/system.h +++ b/core/system.h @@ -103,6 +103,7 @@ extern int16 SVP_cycles; extern uint8 system_hw; extern uint8 system_bios; extern uint32 system_clock; +extern uint8 pause_b; /* Function prototypes */ extern int audio_init(int samplerate, double framerate);