From 2c19c7ce57d12dd732cdaa7b099d0800ed1a2401 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 19 Jun 2021 15:01:42 +1000 Subject: [PATCH] CDROM: Cancel speed changes if they're not complete --- src/core/cdrom.cpp | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/core/cdrom.cpp b/src/core/cdrom.cpp index 456112259..7d007ad9e 100644 --- a/src/core/cdrom.cpp +++ b/src/core/cdrom.cpp @@ -1020,23 +1020,34 @@ void CDROM::ExecuteCommand(TickCount ticks_late) SendACKAndStat(); EndCommand(); - if (speed_change && m_drive_state != DriveState::SeekingImplicit && - m_drive_state != DriveState::ChangingSpeedOrTOCRead) + if (speed_change) { - // if we're seeking or reading, we need to add time to the current seek/read - const TickCount change_ticks = GetTicksForSpeedChange(); - if (m_drive_state != DriveState::Idle) + if (m_drive_state == DriveState::ChangingSpeedOrTOCRead) { - Log_DevPrintf("Drive is %s, delaying event by %d ticks for speed change to %s-speed", - s_drive_state_names[static_cast(m_drive_state)], change_ticks, - m_mode.double_speed ? "double" : "single"); - m_drive_event->Delay(change_ticks); + // cancel the speed change if it's less than a quarter complete + if (m_drive_event->GetTicksUntilNextExecution() >= (GetTicksForSpeedChange() / 4)) + { + Log_DevPrintf("Cancelling speed change event"); + ClearDriveState(); + } } - else + else if (m_drive_state != DriveState::SeekingImplicit) { - Log_DevPrintf("Drive is idle, speed change takes %d ticks", change_ticks); - m_drive_state = DriveState::ChangingSpeedOrTOCRead; - m_drive_event->Schedule(change_ticks); + // if we're seeking or reading, we need to add time to the current seek/read + const TickCount change_ticks = GetTicksForSpeedChange(); + if (m_drive_state != DriveState::Idle) + { + Log_DevPrintf("Drive is %s, delaying event by %d ticks for speed change to %s-speed", + s_drive_state_names[static_cast(m_drive_state)], change_ticks, + m_mode.double_speed ? "double" : "single"); + m_drive_event->Delay(change_ticks); + } + else + { + Log_DevPrintf("Drive is idle, speed change takes %d ticks", change_ticks); + m_drive_state = DriveState::ChangingSpeedOrTOCRead; + m_drive_event->Schedule(change_ticks); + } } }