CDROM: Deactivate command attempt before queueing another

Reduces chances of ending up with unordered events.
This commit is contained in:
Stenzek 2024-07-20 13:13:15 +10:00
parent efd8aab437
commit 52f9e8556a
No known key found for this signature in database

View file

@ -1197,7 +1197,8 @@ void CDROM::SetAsyncInterrupt(Interrupt interrupt)
} }
else else
{ {
DEBUG_LOG("Delaying async interrupt {} because of pending interrupt", s_interrupt_flag_register); DEBUG_LOG("Delaying async interrupt {} because of pending interrupt {}", s_pending_async_interrupt,
s_interrupt_flag_register);
} }
} }
@ -1536,6 +1537,9 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
s_response_fifo.Clear(); s_response_fifo.Clear();
} }
// Stop command event first, reduces our chances of ending up with out-of-order events.
s_command_event.Deactivate();
switch (s_command) switch (s_command)
{ {
case Command::Getstat: case Command::Getstat:
@ -1907,8 +1911,8 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
QueueCommandSecondResponse(Command::Init, INIT_TICKS); QueueCommandSecondResponse(Command::Init, INIT_TICKS);
EndCommand(); EndCommand();
return;
} }
break;
case Command::MotorOn: case Command::MotorOn:
{ {
@ -1937,7 +1941,6 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
EndCommand(); EndCommand();
return; return;
} }
break;
case Command::Mute: case Command::Mute:
{ {
@ -1945,8 +1948,8 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
s_muted = true; s_muted = true;
SendACKAndStat(); SendACKAndStat();
EndCommand(); EndCommand();
return;
} }
break;
case Command::Demute: case Command::Demute:
{ {
@ -1954,8 +1957,8 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
s_muted = false; s_muted = false;
SendACKAndStat(); SendACKAndStat();
EndCommand(); EndCommand();
return;
} }
break;
case Command::GetlocL: case Command::GetlocL:
{ {
@ -2034,8 +2037,8 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
} }
EndCommand(); EndCommand();
return;
} }
break;
case Command::GetTD: case Command::GetTD:
{ {
@ -2080,8 +2083,8 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
} }
EndCommand(); EndCommand();
return;
} }
break;
case Command::Getmode: case Command::Getmode:
{ {
@ -2094,8 +2097,8 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
s_response_fifo.Push(s_xa_filter_channel_number); s_response_fifo.Push(s_xa_filter_channel_number);
SetInterrupt(Interrupt::ACK); SetInterrupt(Interrupt::ACK);
EndCommand(); EndCommand();
return;
} }
break;
case Command::Sync: case Command::Sync:
{ {
@ -2103,8 +2106,8 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
SendErrorResponse(STAT_ERROR, ERROR_REASON_INVALID_COMMAND); SendErrorResponse(STAT_ERROR, ERROR_REASON_INVALID_COMMAND);
EndCommand(); EndCommand();
return;
} }
break;
case Command::VideoCD: case Command::VideoCD:
{ {
@ -2115,8 +2118,8 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
s_command = Command::None; s_command = Command::None;
s_command_event.Deactivate(); s_command_event.Deactivate();
UpdateStatusRegister(); UpdateStatusRegister();
return;
} }
break;
default: default:
[[unlikely]] [[unlikely]]
@ -2125,8 +2128,8 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
s_param_fifo.GetSize()); s_param_fifo.GetSize());
SendErrorResponse(STAT_ERROR, ERROR_REASON_INVALID_COMMAND); SendErrorResponse(STAT_ERROR, ERROR_REASON_INVALID_COMMAND);
EndCommand(); EndCommand();
return;
} }
break;
} }
} }