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.
This commit is contained in:
Admiral H. Curtiss 2015-07-04 00:39:42 +02:00
parent 8e92d25b75
commit 3a55360572
2 changed files with 18 additions and 9 deletions

View File

@ -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;
}

View File

@ -403,6 +403,11 @@ protected:
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 );