diff --git a/src/common/cd_image.cpp b/src/common/cd_image.cpp index b17ecbcb1..0799d04f8 100644 --- a/src/common/cd_image.cpp +++ b/src/common/cd_image.cpp @@ -196,7 +196,7 @@ u32 CDImage::Read(ReadMode read_mode, u32 sector_count, void* buffer) { // get raw sector u8 raw_sector[RAW_SECTOR_SIZE]; - if (!ReadRawSector(raw_sector)) + if (!ReadRawSector(raw_sector, nullptr)) break; switch (read_mode) @@ -225,7 +225,7 @@ u32 CDImage::Read(ReadMode read_mode, u32 sector_count, void* buffer) return sectors_read; } -bool CDImage::ReadRawSector(void* buffer) +bool CDImage::ReadRawSector(void* buffer, SubChannelQ* subq) { if (m_position_in_index == m_current_index->length) { @@ -233,41 +233,46 @@ bool CDImage::ReadRawSector(void* buffer) return false; } - if (m_current_index->file_sector_size > 0) + if (buffer) { - // TODO: This is where we'd reconstruct the header for other mode tracks. - if (!ReadSectorFromIndex(buffer, *m_current_index, m_position_in_index)) + if (m_current_index->file_sector_size > 0) { - Log_ErrorPrintf("Read of LBA %u failed", m_position_on_disc); - Seek(m_position_on_disc); - return false; - } - } - else - { - if (m_current_index->track_number == LEAD_OUT_TRACK_NUMBER) - { - // Lead-out area. - std::fill(static_cast(buffer), static_cast(buffer) + RAW_SECTOR_SIZE, u8(0xAA)); + // TODO: This is where we'd reconstruct the header for other mode tracks. + if (!ReadSectorFromIndex(buffer, *m_current_index, m_position_in_index)) + { + Log_ErrorPrintf("Read of LBA %u failed", m_position_on_disc); + Seek(m_position_on_disc); + return false; + } } else { - // This in an implicit pregap. Return silence. - std::fill(static_cast(buffer), static_cast(buffer) + RAW_SECTOR_SIZE, u8(0)); + if (m_current_index->track_number == LEAD_OUT_TRACK_NUMBER) + { + // Lead-out area. + std::fill(static_cast(buffer), static_cast(buffer) + RAW_SECTOR_SIZE, u8(0xAA)); + } + else + { + // This in an implicit pregap. Return silence. + std::fill(static_cast(buffer), static_cast(buffer) + RAW_SECTOR_SIZE, u8(0)); + } } } + if (subq && !ReadSubChannelQ(subq, *m_current_index, m_position_in_index)) + { + Log_ErrorPrintf("Subchannel read of LBA %u failed", m_position_on_disc); + Seek(m_position_on_disc); + return false; + } + m_position_on_disc++; m_position_in_index++; m_position_in_track++; return true; } -bool CDImage::ReadSubChannelQ(SubChannelQ* subq) -{ - return ReadSubChannelQ(subq, *m_current_index, m_position_in_index); -} - bool CDImage::ReadSubChannelQ(SubChannelQ* subq, const Index& index, LBA lba_in_index) { GenerateSubChannelQ(subq, index, lba_in_index); diff --git a/src/common/cd_image.h b/src/common/cd_image.h index 116e8af77..8ac63e26e 100644 --- a/src/common/cd_image.h +++ b/src/common/cd_image.h @@ -244,11 +244,8 @@ public: // Read from the current LBA. Returns the number of sectors read. u32 Read(ReadMode read_mode, u32 sector_count, void* buffer); - // Read a single raw sector from the current LBA. - bool ReadRawSector(void* buffer); - - // Reads sub-channel Q for the current LBA. - bool ReadSubChannelQ(SubChannelQ* subq); + // Read a single raw sector, and subchannel from the current LBA. + bool ReadRawSector(void* buffer, SubChannelQ* subq); // Reads sub-channel Q for the specified index+LBA. virtual bool ReadSubChannelQ(SubChannelQ* subq, const Index& index, LBA lba_in_index); diff --git a/src/common/cd_image_hasher.cpp b/src/common/cd_image_hasher.cpp index cf3f82970..dd93f028c 100644 --- a/src/common/cd_image_hasher.cpp +++ b/src/common/cd_image_hasher.cpp @@ -27,7 +27,7 @@ static bool ReadIndex(CDImage* image, u8 track, u8 index, MD5Digest* digest, Pro if ((lba % update_interval) == 0) progress_callback->SetProgressValue(lba); - if (!image->ReadRawSector(sector.data())) + if (!image->ReadRawSector(sector.data(), nullptr)) { progress_callback->DisplayFormattedModalError("Failed to read sector %u from image", image->GetPositionOnDisc()); return false; diff --git a/src/core/cdrom.cpp b/src/core/cdrom.cpp index d3a4105d3..2997da225 100644 --- a/src/core/cdrom.cpp +++ b/src/core/cdrom.cpp @@ -280,7 +280,7 @@ void CDROM::InsertMedia(std::unique_ptr media) // reading TOC? interestingly this doesn't work for GetlocL though... CDImage::SubChannelQ subq; - if (media->Seek(0) && media->ReadSubChannelQ(&subq) && subq.IsCRCValid()) + if (media->Seek(0) && media->ReadRawSector(nullptr, &subq) && subq.IsCRCValid()) m_last_subq = subq; m_reader.SetMedia(std::move(media)); diff --git a/src/core/cdrom_async_reader.cpp b/src/core/cdrom_async_reader.cpp index f5627fb4e..44fb8e08a 100644 --- a/src/core/cdrom_async_reader.cpp +++ b/src/core/cdrom_async_reader.cpp @@ -88,7 +88,7 @@ bool CDROMAsyncReader::ReadSectorUncached(CDImage::LBA lba, CDImage::SubChannelQ return false; } - if ((subq && !m_media->ReadSubChannelQ(subq)) || (data && !m_media->ReadRawSector(data->data()))) + if (!m_media->ReadRawSector(data, subq)) { Log_WarningPrintf("Read of LBA %u failed", lba); return false; @@ -149,8 +149,8 @@ void CDROMAsyncReader::DoSectorRead() } } - CDImage::LBA pos = m_media->GetPositionOnDisc(); - if (!m_media->ReadSubChannelQ(&m_subq) || !m_media->ReadRawSector(m_sector_buffer.data())) + const CDImage::LBA pos = m_media->GetPositionOnDisc(); + if (!m_media->ReadRawSector(m_sector_buffer.data(), &m_subq)) { m_sector_read_result.store(false); Log_WarningPrintf("Read of LBA %u failed", pos);