From 7310aa509a4803faf17bf9185d311fb6a618f9cb Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 16 May 2025 18:14:06 +1000 Subject: [PATCH] CDROM: Stop reading on backend read fail Instead of panicing. Game's probably just going to crash anyway. --- src/core/cdrom.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/core/cdrom.cpp b/src/core/cdrom.cpp index 2ea6b3ffd..a0fe2a4d5 100644 --- a/src/core/cdrom.cpp +++ b/src/core/cdrom.cpp @@ -308,8 +308,8 @@ static void ClearAsyncInterrupt(); static void DeliverAsyncInterrupt(void*, TickCount ticks, TickCount ticks_late); static void QueueDeliverAsyncInterrupt(); static void SendACKAndStat(); -static void SendErrorResponse(u8 stat_bits = STAT_ERROR, u8 reason = 0x80); -static void SendAsyncErrorResponse(u8 stat_bits = STAT_ERROR, u8 reason = 0x80); +static void SendErrorResponse(u8 stat_bits = STAT_ERROR, u8 reason = ERROR_REASON_NOT_READY); +static void SendAsyncErrorResponse(u8 stat_bits = STAT_ERROR, u8 reason = ERROR_REASON_NOT_READY); static void UpdateStatusRegister(); static void UpdateInterruptRequest(); static bool HasPendingDiscEvent(); @@ -353,6 +353,7 @@ static void ProcessDataSector(const u8* raw_sector, const CDImage::SubChannelQ& static void ProcessXAADPCMSector(const u8* raw_sector, const CDImage::SubChannelQ& subq); static void ProcessCDDASector(const u8* raw_sector, const CDImage::SubChannelQ& subq, bool subq_valid); static void StopReadingWithDataEnd(); +static void StopReadingWithError(u8 reason = ERROR_REASON_NOT_READY); static void StartMotor(); static void StopMotor(); static void BeginSeeking(bool logical, bool read_after_seek, bool play_after_seek); @@ -3224,6 +3225,15 @@ void CDROM::StopReadingWithDataEnd() ClearDriveState(); } +void CDROM::StopReadingWithError(u8 reason) +{ + ClearAsyncInterrupt(); + CDROM::SendAsyncErrorResponse(STAT_ERROR, reason); + + s_state.secondary_status.ClearActiveBits(); + ClearDriveState(); +} + void CDROM::StartMotor() { if (s_state.drive_state == DriveState::SpinningUp) @@ -3249,9 +3259,11 @@ void CDROM::StopMotor() void CDROM::DoSectorRead() { // TODO: Queue the next read here and swap the buffer. - // TODO: Error handling if (!s_reader.WaitForReadToComplete()) - Panic("Sector read failed"); + { + StopReadingWithError(); + return; + } s_state.current_lba = s_reader.GetLastReadSector(); s_state.current_subq_lba = s_state.current_lba;