CDROM: Implement ReadTOC command

This commit is contained in:
Connor McLaughlin 2019-11-09 00:21:11 +10:00
parent 7e7b7dc216
commit 5dd4f6f65e
2 changed files with 37 additions and 3 deletions

View File

@ -488,7 +488,7 @@ void CDROM::UpdateInterruptRequest()
TickCount CDROM::GetAckDelayForCommand() const
{
const u32 default_ack_delay = 3000;
if (m_command == Command::Init)
if (m_command == Command::Init || m_command == Command::ReadTOC)
return 60000;
else
return default_ack_delay;
@ -548,6 +548,10 @@ void CDROM::Execute(TickCount ticks)
DoIDRead();
break;
case DriveState::ReadingTOC:
DoTOCRead();
break;
case DriveState::Reading:
case DriveState::Playing:
DoSectorRead();
@ -637,6 +641,25 @@ void CDROM::ExecuteCommand()
return;
}
case Command::ReadTOC:
{
Log_DebugPrintf("CDROM ReadTOC command");
if (!HasMedia())
{
SendErrorResponse(0x80);
}
else
{
SendACKAndStat();
m_drive_state = DriveState::ReadingTOC;
m_drive_remaining_ticks = MASTER_CLOCK / 2; // half a second
}
EndCommand();
return;
}
case Command::Setfilter:
{
const u8 file = m_param_fifo.Peek(0);
@ -1121,6 +1144,15 @@ void CDROM::DoIDRead()
SetAsyncInterrupt(Interrupt::INT2);
}
void CDROM::DoTOCRead()
{
Log_DebugPrintf("TOC read complete");
m_drive_state = DriveState::Idle;
m_async_response_fifo.Clear();
m_async_response_fifo.Push(m_secondary_status.bits);
SetAsyncInterrupt(Interrupt::INT2);
}
void CDROM::DoSectorRead()
{
// TODO: Error handling
@ -1417,8 +1449,8 @@ void CDROM::DrawDebugWindow()
if (ImGui::CollapsingHeader("Status/Mode", ImGuiTreeNodeFlags_DefaultOpen))
{
static constexpr std::array<const char*, 8> drive_state_names = {
{"Idle", "Spinning Up", "Seeking", "Reading ID", "Reading", "Playing", "Pausing", "Stopping"}};
static constexpr std::array<const char*, 9> drive_state_names = {
{"Idle", "Spinning Up", "Seeking", "Reading ID", "Reading TOC", "Reading", "Playing", "Pausing", "Stopping"}};
ImGui::Columns(3);

View File

@ -112,6 +112,7 @@ private:
SpinningUp,
Seeking,
ReadingID,
ReadingTOC,
Reading,
Playing,
Pausing,
@ -201,6 +202,7 @@ private:
void DoPauseComplete();
void DoStopComplete();
void DoIDRead();
void DoTOCRead();
void DoSectorRead();
void ProcessDataSector(const u8* raw_sector);
void ProcessXAADPCMSector(const u8* raw_sector);