From b800ca15e7000d8e471a31b66d162e1fb6b9710d Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sat, 4 Apr 2026 12:34:20 +0300 Subject: [PATCH] Fixed 6.0.x statefile bug and added partial workaround --- custom.cpp | 2 +- include/savestate.h | 1 + newcpu.cpp | 9 +++++++++ savestate.cpp | 21 +++++++++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/custom.cpp b/custom.cpp index d620cea9..1f04f227 100644 --- a/custom.cpp +++ b/custom.cpp @@ -12436,7 +12436,7 @@ uae_u32 wait_cpu_cycle_read(uaecptr addr, int mode) } #endif - x_do_cycles_post(CYCLE_UNIT, 0); + x_do_cycles_post(CYCLE_UNIT, v); regs.chipset_latch_rw = regs.chipset_latch_read = v; diff --git a/include/savestate.h b/include/savestate.h index c750a8e3..74fbfb96 100644 --- a/include/savestate.h +++ b/include/savestate.h @@ -265,6 +265,7 @@ extern bool savestate_restore_finish(void); extern void savestate_restore_final(void); extern void savestate_memorysave(void); extern bool is_savestate_incompatible(void); +extern uae_u32 get_statefile_version(void); extern void custom_prepare_savestate(void); diff --git a/newcpu.cpp b/newcpu.cpp index a7e3997b..2501a571 100644 --- a/newcpu.cpp +++ b/newcpu.cpp @@ -482,6 +482,15 @@ static bool get_trace(uaecptr addr, int accessmode, int size, uae_u32 *data) } } check_trace(); + + // Partially fix 6.0.x statefiles where 68000 word read value was stored as a zero. + // This can be only fixed when it was 68000 instruction prefetch. + if ((get_statefile_version() & 0xffffff00) == 0x00060000) { + if (!ctm->data && accessmode == 2 && currprefs.cpu_model <= 68010 && currprefs.cpu_cycle_exact && addr > regs.pc && addr < regs.pc + 20) { + return true; + } + } + *data = ctm->data; return false; } diff --git a/savestate.cpp b/savestate.cpp index ea9886cb..538de5b9 100644 --- a/savestate.cpp +++ b/savestate.cpp @@ -82,6 +82,7 @@ struct zfile *savestate_file; #define SAVESTATE_ALWAYSUSEPATH 16 #define SAVESTATE_SPECIALDUMP (SAVESTATE_SPECIALDUMP1 | SAVESTATE_SPECIALDUMP2) static int savestate_flags; +static uae_u32 statefile_version; TCHAR savestate_fname[MAX_DPATH]; TCHAR path_statefile[MAX_DPATH]; @@ -577,6 +578,11 @@ static uae_u8 *restore_log (uae_u8 *src) return src; } +uae_u32 get_statefile_version(void) +{ + return statefile_version; +} + static void restore_header (uae_u8 *src) { TCHAR *emuname, *emuversion, *description; @@ -587,6 +593,21 @@ static void restore_header (uae_u8 *src) description = restore_string (); write_log (_T("Saved with: '%s %s', description: '%s'\n"), emuname, emuversion, description); + + statefile_version = 0; + TCHAR *tmpp = _tcschr(emuversion, '.'); + if (tmpp) { + *tmpp++ = 0; + TCHAR *tmpp2 = tmpp; + statefile_version = _tstol(emuversion) << 16; + tmpp = _tcschr(tmpp, '.'); + if (tmpp) { + *tmpp++ = 0; + statefile_version |= _tstol(tmpp2) << 8; + statefile_version |= _tstol(tmpp); + } + } + xfree (description); xfree (emuversion); xfree (emuname); -- 2.47.3