mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-29 09:05:41 +00:00
MemoryCard: Save state support
This commit is contained in:
parent
623b9996c7
commit
9fc608aa34
|
@ -1,5 +1,6 @@
|
|||
#include "memory_card.h"
|
||||
#include "YBaseLib/Log.h"
|
||||
#include "common/state_wrapper.h"
|
||||
Log_SetChannel(MemoryCard);
|
||||
|
||||
MemoryCard::MemoryCard()
|
||||
|
@ -10,6 +11,23 @@ MemoryCard::MemoryCard()
|
|||
|
||||
MemoryCard::~MemoryCard() = default;
|
||||
|
||||
void MemoryCard::Reset()
|
||||
{
|
||||
ResetTransferState();
|
||||
}
|
||||
|
||||
bool MemoryCard::DoState(StateWrapper& sw)
|
||||
{
|
||||
sw.Do(&m_state);
|
||||
sw.Do(&m_address);
|
||||
sw.Do(&m_sector_offset);
|
||||
sw.Do(&m_checksum);
|
||||
sw.Do(&m_last_byte);
|
||||
sw.Do(&m_data);
|
||||
|
||||
return !sw.HasError();
|
||||
}
|
||||
|
||||
void MemoryCard::ResetTransferState()
|
||||
{
|
||||
m_state = State::Idle;
|
||||
|
|
|
@ -19,6 +19,9 @@ public:
|
|||
|
||||
static std::shared_ptr<MemoryCard> Create();
|
||||
|
||||
void Reset() override;
|
||||
bool DoState(StateWrapper& sw) override;
|
||||
|
||||
void ResetTransferState() override;
|
||||
bool Transfer(const u8 data_in, u8* data_out) override;
|
||||
|
||||
|
|
|
@ -20,10 +20,34 @@ bool Pad::Initialize(System* system, InterruptController* interrupt_controller)
|
|||
void Pad::Reset()
|
||||
{
|
||||
SoftReset();
|
||||
|
||||
for (u32 i = 0; i < NUM_SLOTS; i++)
|
||||
{
|
||||
if (m_controllers[i])
|
||||
m_controllers[i]->Reset();
|
||||
|
||||
if (m_memory_cards[i])
|
||||
m_memory_cards[i]->Reset();
|
||||
}
|
||||
}
|
||||
|
||||
bool Pad::DoState(StateWrapper& sw)
|
||||
{
|
||||
for (u32 i = 0; i < NUM_SLOTS; i++)
|
||||
{
|
||||
if (m_controllers[i])
|
||||
{
|
||||
if (!sw.DoMarker("Controller") || !m_controllers[i]->DoState(sw))
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m_memory_cards[i])
|
||||
{
|
||||
if (!sw.DoMarker("MemortCard") || !m_memory_cards[i]->DoState(sw))
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
sw.Do(&m_state);
|
||||
sw.Do(&m_ticks_remaining);
|
||||
sw.Do(&m_JOY_CTRL.bits);
|
||||
|
@ -172,6 +196,7 @@ void Pad::SoftReset()
|
|||
m_JOY_MODE.bits = 0;
|
||||
m_RX_FIFO.Clear();
|
||||
m_TX_FIFO.Clear();
|
||||
ResetDeviceTransferState();
|
||||
UpdateJoyStat();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,17 @@
|
|||
#include "pad_device.h"
|
||||
#include "common/state_wrapper.h"
|
||||
|
||||
PadDevice::PadDevice() = default;
|
||||
|
||||
PadDevice::~PadDevice() = default;
|
||||
|
||||
void PadDevice::Reset() {}
|
||||
|
||||
bool PadDevice::DoState(StateWrapper& sw)
|
||||
{
|
||||
return !sw.HasError();
|
||||
}
|
||||
|
||||
void PadDevice::ResetTransferState() {}
|
||||
|
||||
bool PadDevice::Transfer(const u8 data_in, u8* data_out)
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
#pragma once
|
||||
#include "types.h"
|
||||
|
||||
class StateWrapper;
|
||||
|
||||
class PadDevice
|
||||
{
|
||||
public:
|
||||
PadDevice();
|
||||
virtual ~PadDevice();
|
||||
|
||||
virtual void Reset();
|
||||
virtual bool DoState(StateWrapper& sw);
|
||||
|
||||
// Resets all state for the transferring to/from the device.
|
||||
virtual void ResetTransferState();
|
||||
|
||||
|
|
Loading…
Reference in a new issue