From 3a553605720ce4555bcff25134b14f8048ec5232 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sat, 4 Jul 2015 00:39:42 +0200 Subject: [PATCH] FolderMemoryCard: Fix a bug where the cache wouldn't be populated properly on first write to any given page. I'm kinda surprised this didn't horribly break things, honestly. I guess it's because memory card data is always written in blocks, but still. --- pcsx2/gui/MemoryCardFolder.cpp | 22 +++++++++++++--------- pcsx2/gui/MemoryCardFolder.h | 5 +++++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/pcsx2/gui/MemoryCardFolder.cpp b/pcsx2/gui/MemoryCardFolder.cpp index 88bc7cacee..3b64cc0ace 100644 --- a/pcsx2/gui/MemoryCardFolder.cpp +++ b/pcsx2/gui/MemoryCardFolder.cpp @@ -729,14 +729,7 @@ s32 FolderMemoryCard::Read( u8 *dest, u32 adr, int size ) { if ( it != m_cache.end() ) { memcpy( dest, &it->second.raw[offset], dataLength ); } else { - u8* src = GetSystemBlockPointer( adr ); - if ( src != nullptr ) { - memcpy( dest, src, dataLength ); - } else { - if ( !ReadFromFile( dest, adr, dataLength ) ) { - memset( dest, 0xFF, dataLength ); - } - } + ReadDataWithoutCache( dest, adr, dataLength ); } } @@ -765,6 +758,17 @@ s32 FolderMemoryCard::Read( u8 *dest, u32 adr, int size ) { return 1; } +void FolderMemoryCard::ReadDataWithoutCache( u8* const dest, const u32 adr, const u32 dataLength ) { + u8* src = GetSystemBlockPointer( adr ); + if ( src != nullptr ) { + memcpy( dest, src, dataLength ); + } else { + if ( !ReadFromFile( dest, adr, dataLength ) ) { + memset( dest, 0xFF, dataLength ); + } + } +} + s32 FolderMemoryCard::Save( const u8 *src, u32 adr, int size ) { const u32 block = adr / BlockSizeRaw; const u32 cluster = adr / ClusterSizeRaw; @@ -790,7 +794,7 @@ s32 FolderMemoryCard::Save( const u8 *src, u32 adr, int size ) { if ( it == m_cache.end() ) { cachePage = &m_cache[page]; const u32 adrLoad = page * PageSizeRaw; - Read( &cachePage->raw[0], adrLoad, PageSize ); + ReadDataWithoutCache( &cachePage->raw[0], adrLoad, PageSize ); } else { cachePage = &it->second; } diff --git a/pcsx2/gui/MemoryCardFolder.h b/pcsx2/gui/MemoryCardFolder.h index 906d376e03..cfa3b73259 100644 --- a/pcsx2/gui/MemoryCardFolder.h +++ b/pcsx2/gui/MemoryCardFolder.h @@ -402,6 +402,11 @@ protected: // creates a reference to a directory entry, so it can be passed as parent to other files/directories MemoryCardFileMetadataReference* AddDirEntryToMetadataQuickAccess( MemoryCardFileEntry* const entry, MemoryCardFileMetadataReference* const parent ); + + // read data from the memory card, ignoring the cache + // do NOT attempt to read ECC with this method, it will not work + void ReadDataWithoutCache( u8* const dest, const u32 adr, const u32 dataLength ); + bool ReadFromFile( u8 *dest, u32 adr, u32 dataLength ); bool WriteToFile( const u8* src, u32 adr, u32 dataLength );