From b05d80ef5ceaa6887804840614b3e88649c8e16f Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 25 Sep 2020 00:25:32 +1000 Subject: [PATCH] CDROM: Don't choke on non-mode2 sectors Fixes Formula One 99 circuit selection. --- src/core/cdrom.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/cdrom.cpp b/src/core/cdrom.cpp index 015295edd..d1937d1e5 100644 --- a/src/core/cdrom.cpp +++ b/src/core/cdrom.cpp @@ -1800,8 +1800,8 @@ void CDROM::ProcessDataSector(const u8* raw_sector, const CDImage::SubChannelQ& } // TODO: How does XA relate to this buffering? - m_current_write_sector_buffer = (m_current_write_sector_buffer + 1) % NUM_SECTOR_BUFFERS; - SectorBuffer* sb = &m_sector_buffers[m_current_write_sector_buffer]; + const u32 sb_num = (m_current_write_sector_buffer + 1) % NUM_SECTOR_BUFFERS; + SectorBuffer* sb = &m_sector_buffers[sb_num]; if (sb->size > 0) { Log_DevPrintf("Sector buffer %u was not read, previous sector dropped", @@ -1819,11 +1819,18 @@ void CDROM::ProcessDataSector(const u8* raw_sector, const CDImage::SubChannelQ& else { // TODO: This should actually depend on the mode... - Assert(m_last_sector_header.sector_mode == 2); + if (m_last_sector_header.sector_mode != 2) + { + Log_WarningPrintf("Ignoring non-mode2 sector at %u", m_current_lba); + return; + } + std::memcpy(sb->data.data(), raw_sector + CDImage::SECTOR_SYNC_SIZE + 12, DATA_SECTOR_OUTPUT_SIZE); sb->size = DATA_SECTOR_OUTPUT_SIZE; } + m_current_write_sector_buffer = sb_num; + // Deliver to CPU if (HasPendingAsyncInterrupt()) {