mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-04-28 21:08:04 +03:00
HW: Connect memcards to FlushUnsavedDataEvent.
This commit is contained in:
parent
ba6331723b
commit
d985f247e5
3 changed files with 34 additions and 7 deletions
|
@ -9,6 +9,8 @@
|
|||
#include <vector>
|
||||
|
||||
#include "Common/Event.h"
|
||||
#include "Common/HookableEvent.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/HW/GCMemcard/GCIFile.h"
|
||||
#include "Core/HW/GCMemcard/GCMemcard.h"
|
||||
#include "Core/HW/GCMemcard/GCMemcardBase.h"
|
||||
|
@ -33,8 +35,6 @@ public:
|
|||
|
||||
static std::vector<std::string> GetFileNamesForGameID(const std::string& directory,
|
||||
const std::string& game_id);
|
||||
void FlushToFile();
|
||||
void FlushThread();
|
||||
s32 Read(u32 src_address, s32 length, u8* dest_address) override;
|
||||
s32 Write(u32 dest_address, s32 length, const u8* src_address) override;
|
||||
void ClearBlock(u32 address) override;
|
||||
|
@ -42,6 +42,9 @@ public:
|
|||
void DoState(PointerWrap& p) override;
|
||||
|
||||
private:
|
||||
void FlushToFile();
|
||||
void FlushThread();
|
||||
|
||||
bool LoadGCI(Memcard::GCIFile gci);
|
||||
inline s32 SaveAreaRW(u32 block, bool writing = false);
|
||||
// s32 DirectoryRead(u32 offset, u32 length, u8* dest_address);
|
||||
|
@ -65,4 +68,7 @@ private:
|
|||
std::mutex m_write_mutex;
|
||||
Common::Flag m_exiting;
|
||||
std::thread m_flush_thread;
|
||||
|
||||
Common::EventHook m_flush_data_hook = Core::FlushUnsavedDataEvent::Register(
|
||||
std::bind_front(&GCMemcardDirectory::FlushToFile, this), "GCMemcardDirectory flush");
|
||||
};
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include <fmt/format.h>
|
||||
|
||||
#include "Common/ChunkFile.h"
|
||||
#include "Common/CommonPaths.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/IOFile.h"
|
||||
|
@ -39,6 +38,8 @@ MemoryCard::MemoryCard(const std::string& filename, ExpansionInterface::Slot car
|
|||
u16 size_mbits)
|
||||
: MemoryCardBase(card_slot, size_mbits), m_filename(filename)
|
||||
{
|
||||
m_clean.Set(true);
|
||||
|
||||
File::IOFile file(m_filename, "rb");
|
||||
if (file)
|
||||
{
|
||||
|
@ -92,6 +93,12 @@ MemoryCard::~MemoryCard()
|
|||
}
|
||||
}
|
||||
|
||||
void MemoryCard::FlushWrites()
|
||||
{
|
||||
m_flush_trigger.Set();
|
||||
m_clean.Wait(true);
|
||||
}
|
||||
|
||||
void MemoryCard::FlushThread()
|
||||
{
|
||||
if (!Config::Get(Config::SESSION_SAVE_DATA_WRITABLE))
|
||||
|
@ -153,6 +160,9 @@ void MemoryCard::FlushThread()
|
|||
}
|
||||
file.WriteBytes(&m_flush_buffer[0], m_memory_card_size);
|
||||
|
||||
file.Close();
|
||||
m_clean.Set();
|
||||
|
||||
if (do_exit)
|
||||
return;
|
||||
|
||||
|
@ -164,7 +174,8 @@ void MemoryCard::FlushThread()
|
|||
|
||||
void MemoryCard::MakeDirty()
|
||||
{
|
||||
m_dirty.Set();
|
||||
m_clean.Set(false);
|
||||
m_dirty.Set(true);
|
||||
}
|
||||
|
||||
s32 MemoryCard::Read(u32 src_address, s32 length, u8* dest_address)
|
||||
|
|
|
@ -7,8 +7,12 @@
|
|||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include "Common/Event.h"
|
||||
#include "Common/Flag.h"
|
||||
#include "Common/HookableEvent.h"
|
||||
#include "Common/WaitableFlag.h"
|
||||
|
||||
#include "Core/Core.h"
|
||||
#include "Core/HW/GCMemcard/GCMemcard.h"
|
||||
#include "Core/HW/GCMemcard/GCMemcardBase.h"
|
||||
|
||||
|
@ -20,8 +24,6 @@ public:
|
|||
MemoryCard(const std::string& filename, ExpansionInterface::Slot card_slot,
|
||||
u16 size_mbits = Memcard::MBIT_SIZE_MEMORY_CARD_2043);
|
||||
~MemoryCard();
|
||||
void FlushThread();
|
||||
void MakeDirty();
|
||||
|
||||
s32 Read(u32 src_address, s32 length, u8* dest_address) override;
|
||||
s32 Write(u32 dest_address, s32 length, const u8* src_address) override;
|
||||
|
@ -30,6 +32,10 @@ public:
|
|||
void DoState(PointerWrap& p) override;
|
||||
|
||||
private:
|
||||
void FlushThread();
|
||||
void MakeDirty();
|
||||
void FlushWrites();
|
||||
|
||||
bool IsAddressInBounds(u32 address, u32 length) const
|
||||
{
|
||||
u64 end_address = static_cast<u64>(address) + static_cast<u64>(length);
|
||||
|
@ -43,5 +49,9 @@ private:
|
|||
std::mutex m_flush_mutex;
|
||||
Common::Event m_flush_trigger;
|
||||
Common::Flag m_dirty;
|
||||
Common::WaitableFlag m_clean;
|
||||
u32 m_memory_card_size;
|
||||
|
||||
Common::EventHook m_flush_data_hook = Core::FlushUnsavedDataEvent::Register(
|
||||
std::bind_front(&MemoryCard::FlushWrites, this), "MemoryCard flush");
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue