Pad: Set up memory cards via settings

This commit is contained in:
Connor McLaughlin
2019-10-27 16:45:23 +10:00
parent 739ada4721
commit 0092cb1016
10 changed files with 149 additions and 18 deletions

View File

@ -1,7 +1,9 @@
#include "pad.h"
#include "YBaseLib/Log.h"
#include "common/state_wrapper.h"
#include "host_interface.h"
#include "interrupt_controller.h"
#include "memory_card.h"
#include "pad_device.h"
#include "system.h"
Log_SetChannel(Pad);
@ -46,6 +48,28 @@ bool Pad::DoState(StateWrapper& sw)
return false;
}
bool card_present = static_cast<bool>(m_memory_cards[i]);
sw.Do(&card_present);
if (card_present && !m_memory_cards[i])
{
const TinyString message = TinyString::FromFormat(
"Memory card %c present in save state but not in system. Creating temporary card.", 'A' + i);
m_system->GetHostInterface()->AddOSDMessage(message);
Log_WarningPrint(message);
m_memory_cards[i] = MemoryCard::Create(m_system);
}
else if (!card_present && m_memory_cards[i])
{
const TinyString message =
TinyString::FromFormat("Memory card %u present system but not save state. Removing card.", 'A' + i);
m_system->GetHostInterface()->AddOSDMessage(message);
Log_WarningPrint(message);
m_memory_cards[i].reset();
}
if (m_memory_cards[i])
{
if (!sw.DoMarker("MemoryCard") || !m_memory_cards[i]->DoState(sw))