Save state support

This commit is contained in:
Connor McLaughlin
2019-09-14 20:28:47 +10:00
parent 851ef67814
commit 2560efbebd
16 changed files with 256 additions and 56 deletions

View File

@ -1,5 +1,7 @@
#include "system.h"
#include "YBaseLib/ByteStream.h"
#include "bus.h"
#include "common/state_wrapper.h"
#include "cpu_core.h"
#include "dma.h"
#include "gpu.h"
@ -32,6 +34,23 @@ bool System::Initialize()
return true;
}
bool System::DoState(StateWrapper& sw)
{
if (!sw.DoMarker("CPU") || !m_cpu->DoState(sw))
return false;
if (!sw.DoMarker("Bus") || !m_bus->DoState(sw))
return false;
if (!sw.DoMarker("DMA") || !m_dma->DoState(sw))
return false;
if (!sw.DoMarker("GPU") || !m_gpu->DoState(sw))
return false;
return !sw.HasError();
}
void System::Reset()
{
m_cpu->Reset();
@ -41,6 +60,18 @@ void System::Reset()
m_frame_number = 1;
}
bool System::LoadState(ByteStream* state)
{
StateWrapper sw(state, StateWrapper::Mode::Read);
return DoState(sw);
}
bool System::SaveState(ByteStream* state)
{
StateWrapper sw(state, StateWrapper::Mode::Write);
return DoState(sw);
}
void System::RunFrame()
{
u32 current_frame_number = m_frame_number;
@ -134,3 +165,4 @@ bool System::LoadEXE(const char* filename)
return true;
}