FolderMemoryCard: On reads and writes to actual data, check if the relevant data is actually in use according to the FAT.

This allows us to skip a bunch of accesses trying to find a matching file or memory location, presumably without actual consequences. This isn't really gonna change much in actual game use, but does speed up conversions of FileMemoryCards.
This commit is contained in:
Admiral H. Curtiss 2015-06-02 01:38:48 +02:00
parent 41c3eacb6f
commit f731e3dc1b
1 changed files with 14 additions and 0 deletions

View File

@ -474,6 +474,10 @@ u8* FolderMemoryCard::GetSystemBlockPointer( const u32 adr ) {
if ( cluster >= startDataCluster && cluster < endDataCluster ) { if ( cluster >= startDataCluster && cluster < endDataCluster ) {
// trying to access a file entry? // trying to access a file entry?
const u32 fatCluster = cluster - m_superBlock.data.alloc_offset; const u32 fatCluster = cluster - m_superBlock.data.alloc_offset;
// if this cluster is unused according to FAT, we can assume we won't find anything
if ( ( m_fat.data[0][0][fatCluster] & 0x80000000 ) == 0 ) {
return nullptr;
}
return GetFileEntryPointer( m_superBlock.data.rootdir_cluster, fatCluster, page % 2, offset ); return GetFileEntryPointer( m_superBlock.data.rootdir_cluster, fatCluster, page % 2, offset );
} }
@ -584,6 +588,11 @@ bool FolderMemoryCard::ReadFromFile( u8 *dest, u32 adr, u32 dataLength ) {
const u32 cluster = adr / ClusterSizeRaw; const u32 cluster = adr / ClusterSizeRaw;
const u32 fatCluster = cluster - m_superBlock.data.alloc_offset; const u32 fatCluster = cluster - m_superBlock.data.alloc_offset;
// if the cluster is unused according to FAT, just return
if ( ( m_fat.data[0][0][fatCluster] & 0x80000000 ) == 0 ) {
return false;
}
// figure out which file to read from // figure out which file to read from
wxFileName fileName( m_folderName ); wxFileName fileName( m_folderName );
u32 clusterNumber; u32 clusterNumber;
@ -871,6 +880,11 @@ bool FolderMemoryCard::WriteToFile( const u8* src, u32 adr, u32 dataLength ) {
const u32 offset = adr % PageSizeRaw; const u32 offset = adr % PageSizeRaw;
const u32 fatCluster = cluster - m_superBlock.data.alloc_offset; const u32 fatCluster = cluster - m_superBlock.data.alloc_offset;
// if the cluster is unused according to FAT, just skip all this, we're not gonna find anything anyway
if ( ( m_fat.data[0][0][fatCluster] & 0x80000000 ) == 0 ) {
return false;
}
// figure out which file to write to // figure out which file to write to
wxFileName fileName( m_folderName ); wxFileName fileName( m_folderName );
u32 clusterNumber; u32 clusterNumber;