Skip to content

Commit

Permalink
CDROM: Deactivate command attempt before queueing another
Browse files Browse the repository at this point in the history
Reduces chances of ending up with unordered events.
  • Loading branch information
stenzek committed Jul 20, 2024
1 parent efd8aab commit 52f9e85
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/core/cdrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,8 @@ void CDROM::SetAsyncInterrupt(Interrupt interrupt)
}
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);
}
}

Expand Down Expand Up @@ -1536,6 +1537,9 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
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)
{
case Command::Getstat:
Expand Down Expand Up @@ -1907,8 +1911,8 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)

QueueCommandSecondResponse(Command::Init, INIT_TICKS);
EndCommand();
return;
}
break;

case Command::MotorOn:
{
Expand Down Expand Up @@ -1937,25 +1941,24 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
EndCommand();
return;
}
break;

case Command::Mute:
{
DEBUG_LOG("CDROM mute command");
s_muted = true;
SendACKAndStat();
EndCommand();
return;
}
break;

case Command::Demute:
{
DEBUG_LOG("CDROM demute command");
s_muted = false;
SendACKAndStat();
EndCommand();
return;
}
break;

case Command::GetlocL:
{
Expand Down Expand Up @@ -2034,8 +2037,8 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
}

EndCommand();
return;
}
break;

case Command::GetTD:
{
Expand Down Expand Up @@ -2080,8 +2083,8 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
}

EndCommand();
return;
}
break;

case Command::Getmode:
{
Expand All @@ -2094,17 +2097,17 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
s_response_fifo.Push(s_xa_filter_channel_number);
SetInterrupt(Interrupt::ACK);
EndCommand();
return;
}
break;

case Command::Sync:
{
DEBUG_LOG("CDROM sync command");

SendErrorResponse(STAT_ERROR, ERROR_REASON_INVALID_COMMAND);
EndCommand();
return;
}
break;

case Command::VideoCD:
{
Expand All @@ -2115,8 +2118,8 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
s_command = Command::None;
s_command_event.Deactivate();
UpdateStatusRegister();
return;
}
break;

default:
[[unlikely]]
Expand All @@ -2125,8 +2128,8 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
s_param_fifo.GetSize());
SendErrorResponse(STAT_ERROR, ERROR_REASON_INVALID_COMMAND);
EndCommand();
return;
}
break;
}
}

Expand Down

0 comments on commit 52f9e85

Please sign in to comment.