Core/Memory: Properly reset memory on reset

[SAVEVERSION+]
This commit is contained in:
Stenzek 2023-12-17 07:51:12 +00:00 committed by refractionpcsx2
parent 33a61558e1
commit 14fd42ad91
4 changed files with 26 additions and 9 deletions

View File

@ -23,10 +23,10 @@
#include "DEV9/DEV9.h" #include "DEV9/DEV9.h"
#include "IopHw.h" #include "IopHw.h"
uptr *psxMemWLUT = NULL; uptr *psxMemWLUT = nullptr;
const uptr *psxMemRLUT = NULL; const uptr *psxMemRLUT = nullptr;
IopVM_MemoryAllocMess* iopMem = NULL; IopVM_MemoryAllocMess* iopMem = nullptr;
alignas(__pagesize) u8 iopHw[Ps2MemSize::IopHardware]; alignas(__pagesize) u8 iopHw[Ps2MemSize::IopHardware];
@ -104,6 +104,8 @@ void iopMemReset()
// this one looks like an old hack for some special write-only memory area, // this one looks like an old hack for some special write-only memory area,
// but leaving it in for reference (air) // but leaving it in for reference (air)
//for (i=0; i<0x0008; i++) psxMemWLUT[i + 0xbfc0] = (uptr)&psR[i << 16]; //for (i=0; i<0x0008; i++) psxMemWLUT[i + 0xbfc0] = (uptr)&psR[i << 16];
std::memset(iopMem, 0, sizeof(*iopMem));
} }
u8 iopMemRead8(u32 mem) u8 iopMemRead8(u32 mem)

View File

@ -41,6 +41,7 @@ BIOS
#include "VUmicro.h" #include "VUmicro.h"
#include "MTVU.h" #include "MTVU.h"
#include "DEV9/DEV9.h" #include "DEV9/DEV9.h"
#include "SaveState.h"
#include "ps2/HwInternal.h" #include "ps2/HwInternal.h"
#include "ps2/BiosTools.h" #include "ps2/BiosTools.h"
@ -53,6 +54,7 @@ BIOS
#endif #endif
int MemMode = 0; // 0 is Kernel Mode, 1 is Supervisor Mode, 2 is User Mode int MemMode = 0; // 0 is Kernel Mode, 1 is Supervisor Mode, 2 is User Mode
static int s_ba6 = 0;
void memSetKernelMode() { void memSetKernelMode() {
//Do something here //Do something here
@ -70,11 +72,12 @@ u16 ba0R16(u32 mem)
{ {
//MEM_LOG("ba00000 Memory read16 address %x", mem); //MEM_LOG("ba00000 Memory read16 address %x", mem);
if (mem == 0x1a000006) { if (mem == 0x1a000006)
static int ba6; {
ba6++; s_ba6++;
if (ba6 == 3) ba6 = 0; if (s_ba6 == 3)
return ba6; s_ba6 = 0;
return s_ba6;
} }
return 0; return 0;
} }
@ -824,6 +827,10 @@ void memReset()
vtlb_VMap(0x00000000,0x00000000,0x20000000); vtlb_VMap(0x00000000,0x00000000,0x20000000);
vtlb_VMapUnmap(0x20000000,0x60000000); vtlb_VMapUnmap(0x20000000,0x60000000);
s_ba6 = 0;
// BIOS is included in eeMem, so it needs to be copied after zeroing.
std::memset(eeMem, 0, sizeof(*eeMem));
CopyBIOSToMemory(); CopyBIOSToMemory();
} }
@ -831,3 +838,9 @@ void memRelease()
{ {
eeMem = nullptr; eeMem = nullptr;
} }
bool SaveStateBase::memFreeze()
{
Freeze(s_ba6);
return IsOkay();
}

View File

@ -218,6 +218,7 @@ bool SaveStateBase::FreezeInternals()
return false; return false;
bool okay = rcntFreeze(); bool okay = rcntFreeze();
okay = okay && memFreeze();
okay = okay && gsFreeze(); okay = okay && gsFreeze();
okay = okay && vuMicroFreeze(); okay = okay && vuMicroFreeze();
okay = okay && vuJITFreeze(); okay = okay && vuJITFreeze();

View File

@ -37,7 +37,7 @@ enum class FreezeAction
// [SAVEVERSION+] // [SAVEVERSION+]
// This informs the auto updater that the users savestates will be invalidated. // This informs the auto updater that the users savestates will be invalidated.
static const u32 g_SaveVersion = (0x9A49 << 16) | 0x0000; static const u32 g_SaveVersion = (0x9A4A << 16) | 0x0000;
// the freezing data between submodules and core // the freezing data between submodules and core
@ -204,6 +204,7 @@ protected:
bool vmFreeze(); bool vmFreeze();
bool mtvuFreeze(); bool mtvuFreeze();
bool rcntFreeze(); bool rcntFreeze();
bool memFreeze();
bool vuMicroFreeze(); bool vuMicroFreeze();
bool vuJITFreeze(); bool vuJITFreeze();
bool vif0Freeze(); bool vif0Freeze();