MCPcopy Create free account
hub / github.com/DaedalusX64/daedalus / GetCacheIndex

Method GetCacheIndex

Source/Utility/ROMFileCache.cpp:197–250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195//
196//*****************************************************************************
197ROMFileCache::CacheIdx ROMFileCache::GetCacheIndex( u32 address )
198{
199 u32 chunk_map_idx( AddressToChunkMapIndex( address ) );
200 #ifdef DAEDALUS_ENABLE_ASSERTS
201 DAEDALUS_ASSERT( chunk_map_idx < mChunkMapEntries, "Chunk address is out of range?" );
202 #endif
203 //
204 // Check if this chunk is already cached, load if necessary
205 //
206 CacheIdx idx( mpChunkMap[ chunk_map_idx ] );
207 if(idx == INVALID_IDX)
208 {
209 CacheIdx selected_idx( 0 );
210 u32 oldest_timestamp( mpChunkInfo[ 0 ].LastUseIdx );
211
212 for(CacheIdx i = 1; i < CACHE_SIZE; ++i)
213 {
214 u32 timestamp( mpChunkInfo[ i ].LastUseIdx );
215 if(timestamp < oldest_timestamp)
216 {
217 oldest_timestamp = timestamp;
218 selected_idx = i;
219 }
220 }
221
222 //
223 // Purge the current chunk
224 //
225 PurgeChunk( selected_idx );
226
227 //
228 // And load up the new one
229 //
230 SChunkInfo & chunk_info( mpChunkInfo[ selected_idx ] );
231 chunk_info.StartOffset = GetChunkStartAddress( address );
232 chunk_info.LastUseIdx = ++mMRUIdx;
233
234 #ifdef DAEDALUS_ENABLE_ASSERTS
235 DAEDALUS_ASSERT( chunk_map_idx < mChunkMapEntries, "Chunk address is out of range?" );
236 #endif
237
238 mpChunkMap[ chunk_map_idx ] = selected_idx;
239
240 u32 storage_offset( selected_idx * CHUNK_SIZE );
241 u8 * p_dst( mpStorage + storage_offset );
242
243 //DBGConsole_Msg( 0, "[CRomCache - loading %02x, %08x-%08x", selected_idx, chunk_info.StartOffset, chunk_info.StartOffset + CHUNK_SIZE );
244 mpROMFile->ReadChunk( chunk_info.StartOffset, p_dst, CHUNK_SIZE );
245
246 idx = selected_idx;
247 }
248
249 return idx;
250}
251
252//*****************************************************************************
253//

Callers

nothing calls this directly

Calls 3

AddressToChunkMapIndexFunction · 0.85
GetChunkStartAddressFunction · 0.85
ReadChunkMethod · 0.45

Tested by

no test coverage detected