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 TickCount CDROM::GetAckDelayForCommand() const
{ {
const u32 default_ack_delay = 3000; const u32 default_ack_delay = 3000;
if (m_command == Command::Init) if (m_command == Command::Init || m_command == Command::ReadTOC)
return 60000; return 60000;
else else
return default_ack_delay; return default_ack_delay;
@ -548,6 +548,10 @@ void CDROM::Execute(TickCount ticks)
DoIDRead(); DoIDRead();
break; break;
case DriveState::ReadingTOC:
DoTOCRead();
break;
case DriveState::Reading: case DriveState::Reading:
case DriveState::Playing: case DriveState::Playing:
DoSectorRead(); DoSectorRead();
@ -637,6 +641,25 @@ void CDROM::ExecuteCommand()
return; 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: case Command::Setfilter:
{ {
const u8 file = m_param_fifo.Peek(0); const u8 file = m_param_fifo.Peek(0);
@ -1121,6 +1144,15 @@ void CDROM::DoIDRead()
SetAsyncInterrupt(Interrupt::INT2); 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() void CDROM::DoSectorRead()
{ {
// TODO: Error handling // TODO: Error handling
@ -1417,8 +1449,8 @@ void CDROM::DrawDebugWindow()
if (ImGui::CollapsingHeader("Status/Mode", ImGuiTreeNodeFlags_DefaultOpen)) if (ImGui::CollapsingHeader("Status/Mode", ImGuiTreeNodeFlags_DefaultOpen))
{ {
static constexpr std::array<const char*, 8> drive_state_names = { static constexpr std::array<const char*, 9> drive_state_names = {
{"Idle", "Spinning Up", "Seeking", "Reading ID", "Reading", "Playing", "Pausing", "Stopping"}}; {"Idle", "Spinning Up", "Seeking", "Reading ID", "Reading TOC", "Reading", "Playing", "Pausing", "Stopping"}};
ImGui::Columns(3); ImGui::Columns(3);

View File

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