Sio: Fix host pointer getting serialized

[SAVEVERSION+] It wasn't saving the FIFO anyway. Sorry for the save
state bump, but it's unavoidable :(
This commit is contained in:
Connor McLaughlin 2022-11-21 23:01:50 +10:00 committed by refractionpcsx2
parent 4b4b82bd5f
commit d0673f9133
3 changed files with 36 additions and 74 deletions

View File

@ -15,9 +15,12 @@
#pragma once
#include <deque>
#include <memory>
#include <vector>
#include "System.h"
#include "common/Assertions.h"
#include "common/Exceptions.h"
enum class FreezeAction
@ -33,7 +36,7 @@ enum class FreezeAction
// [SAVEVERSION+]
// This informs the auto updater that the users savestates will be invalidated.
static const u32 g_SaveVersion = (0x9A32 << 16) | 0x0000;
static const u32 g_SaveVersion = (0x9A33 << 16) | 0x0000;
// the freezing data between submodules and core
@ -118,6 +121,36 @@ public:
void PrepBlock( int size );
template <typename T>
void FreezeDeque(std::deque<T>& q)
{
// overwritten when loading
u32 count = static_cast<u32>(q.size());
Freeze(count);
// have to use a temp array, because deque doesn't have a contiguous block of memory
std::unique_ptr<T[]> temp;
if (count > 0)
{
temp = std::make_unique<T[]>(count);
if (IsSaving())
{
u32 pos = 0;
for (const T& it : q)
temp[pos++] = it;
}
FreezeMem(temp.get(), static_cast<int>(sizeof(T) * count));
}
if (IsLoading())
{
q.clear();
for (u32 i = 0; i < count; i++)
q.push_back(temp[i]);
}
}
uint GetCurrentPos() const
{
return m_idx;

View File

@ -868,53 +868,9 @@ void SaveStateBase::sio2Freeze()
{
FreezeTag("sio2");
if (IsSaving())
{
std::deque<u8>::iterator iter;
size_t backupSize;
// Copy fifoIn
if (fifoIn.size())
{
sio2.fifoInBackup = std::make_unique<u8[]>(fifoIn.size());
iter = fifoIn.begin();
backupSize = 0;
while (iter != fifoIn.end())
{
const u8 val = *iter++;
sio2.fifoInBackup.get()[backupSize++] = val;
}
sio2.fifoInBackupSize = backupSize;
}
else
{
sio2.fifoInBackupSize = 0;
}
// Copy fifoOut
if (fifoOut.size())
{
sio2.fifoOutBackup = std::make_unique<u8[]>(fifoOut.size());
iter = fifoOut.begin();
backupSize = 0;
while (iter != fifoOut.end())
{
const u8 val = *iter++;
sio2.fifoOutBackup.get()[backupSize++] = val;
}
sio2.fifoOutBackupSize = backupSize;
}
else
{
sio2.fifoOutBackupSize = 0;
}
}
Freeze(sio2);
FreezeDeque(fifoIn);
FreezeDeque(fifoOut);
// CRCs for memory cards.
// If the memory card hasn't changed when loading state, we can safely skip ejecting it.
@ -944,28 +900,6 @@ void SaveStateBase::sio2Freeze()
}
}
}
// Restore fifoIn
fifoIn.clear();
if (sio2.fifoInBackupSize)
{
for (size_t i = 0; i < sio2.fifoInBackupSize; i++)
{
fifoIn.push_back(sio2.fifoInBackup.get()[i]);
}
}
// Restore fifoOut
fifoOut.clear();
if (sio2.fifoOutBackupSize)
{
for (size_t j = 0; j < sio2.fifoOutBackupSize; j++)
{
fifoOut.push_back(sio2.fifoOutBackup.get()[j]);
}
}
}
}

View File

@ -198,11 +198,6 @@ public:
size_t dmaBlockSize = 0;
bool send3Complete = false;
std::unique_ptr<u8[]> fifoInBackup;
size_t fifoInBackupSize;
std::unique_ptr<u8[]> fifoOutBackup;
size_t fifoOutBackupSize;
Sio2();
~Sio2();