cdvdgigaherz: Only update cache if the read succeeds

This commit is contained in:
Jonathan Li 2016-11-16 20:42:31 +00:00 committed by Gregory Hainaut
parent bb25ce1c6a
commit a34942c882
1 changed files with 21 additions and 26 deletions

View File

@ -108,6 +108,23 @@ void cdvdCacheReset()
}
}
bool cdvdReadBlockOfSectors(u32 sector, s32 mode, u8 *data)
{
u32 count = std::min(16U, src->GetSectorCount() - sector);
// TODO: Is it really necessary to retry 3 times if it fails?
for (int tries = 0; tries < 4; ++tries) {
if (mode == CDVD_MODE_2048) {
if (src->ReadSectors2048(sector, count, data))
return true;
} else {
if (src->ReadSectors2352(sector, count, data))
return true;
}
}
return false;
}
void cdvdCallNewDiscCB()
{
weAreInNewDiskCB = true;
@ -170,18 +187,7 @@ void cdvdThread()
}
if (threadRequestPending || prefetch_left) {
u32 count = std::min(16U, src->GetSectorCount() - info.lsn);
for (int tries = 0; tries < 4; ++tries) {
if (info.mode == CDVD_MODE_2048) {
if (src->ReadSectors2048(info.lsn, count, info.data))
break;
} else {
if (src->ReadSectors2352(info.lsn, count, info.data))
break;
}
}
if (cdvdReadBlockOfSectors(info.lsn, info.mode, info.data))
cdvdCacheUpdate(info.lsn, info.mode, info.data);
if (handlingRequest) {
@ -286,18 +292,7 @@ s32 cdvdDirectReadSector(u32 first, s32 mode, u8 *buffer)
u32 sector = first & (~15); //align to 16-sector block
if (!cdvdCacheFetch(sector, mode, data)) {
u32 count = std::min(16U, src->GetSectorCount() - sector);
for (int tries = 0; tries < 4; ++tries) {
if (mode == CDVD_MODE_2048) {
if (src->ReadSectors2048(sector, count, data))
break;
} else {
if (src->ReadSectors2352(sector, count, data))
break;
}
}
if (cdvdReadBlockOfSectors(sector, mode, data))
cdvdCacheUpdate(sector, mode, data);
}