CDROM: Implement GetTN command

This commit is contained in:
Connor McLaughlin 2019-10-18 22:44:28 +10:00
parent baf97cb864
commit 4959de9859
6 changed files with 36 additions and 1 deletions

View file

@ -24,7 +24,7 @@ std::unique_ptr<CDImage> CDImage::Open(const char* filename)
if (CASE_COMPARE(extension, ".cue") == 0) if (CASE_COMPARE(extension, ".cue") == 0)
return OpenCueSheetImage(filename); return OpenCueSheetImage(filename);
else if (CASE_COMPARE(extension, ".bin") == 0) else if (CASE_COMPARE(extension, ".bin") == 0 || CASE_COMPARE(extension, ".img") == 0)
return OpenBinImage(filename); return OpenBinImage(filename);
#undef CASE_COMPARE #undef CASE_COMPARE

View file

@ -90,7 +90,9 @@ public:
LBA GetPositionInTrack() const { return m_position_in_track; } LBA GetPositionInTrack() const { return m_position_in_track; }
Position GetMSFPositionInTrack() const { return Position::FromLBA(m_position_in_track); } Position GetMSFPositionInTrack() const { return Position::FromLBA(m_position_in_track); }
LBA GetLBACount() const { return m_lba_count; } LBA GetLBACount() const { return m_lba_count; }
u32 GetIndexNumber() const { return m_current_index->index_number; }
u32 GetTrackNumber() const { return m_current_index->track_number; } u32 GetTrackNumber() const { return m_current_index->track_number; }
u32 GetTrackCount() const { return static_cast<u32>(m_tracks.size()); }
// Seek to data LBA. // Seek to data LBA.
bool Seek(LBA lba); bool Seek(LBA lba);
@ -120,6 +122,7 @@ protected:
u32 file_sector_size; u32 file_sector_size;
LBA start_lba_on_disc; LBA start_lba_on_disc;
u32 track_number; u32 track_number;
u32 index_number;
LBA start_lba_in_track; LBA start_lba_in_track;
u32 length; u32 length;
bool is_pregap; bool is_pregap;

View file

@ -48,6 +48,7 @@ bool CDImageBin::Open(const char* filename)
pregap_index.start_lba_in_track = static_cast<LBA>(-static_cast<s32>(pregap_frames)); pregap_index.start_lba_in_track = static_cast<LBA>(-static_cast<s32>(pregap_frames));
pregap_index.length = pregap_frames; pregap_index.length = pregap_frames;
pregap_index.track_number = 1; pregap_index.track_number = 1;
pregap_index.index_number = 0;
pregap_index.is_pregap = true; pregap_index.is_pregap = true;
m_indices.push_back(pregap_index); m_indices.push_back(pregap_index);
@ -58,6 +59,7 @@ bool CDImageBin::Open(const char* filename)
data_index.file_sector_size = track_sector_size; data_index.file_sector_size = track_sector_size;
data_index.start_lba_on_disc = pregap_index.length; data_index.start_lba_on_disc = pregap_index.length;
data_index.track_number = 1; data_index.track_number = 1;
data_index.index_number = 1;
data_index.start_lba_in_track = 0; data_index.start_lba_in_track = 0;
data_index.length = m_lba_count; data_index.length = m_lba_count;
m_indices.push_back(data_index); m_indices.push_back(data_index);

View file

@ -118,6 +118,7 @@ bool CDImageCueSheet::OpenAndParse(const char* filename)
pregap_index.start_lba_in_track = static_cast<LBA>(static_cast<unsigned long>(-pregap_frames)); pregap_index.start_lba_in_track = static_cast<LBA>(static_cast<unsigned long>(-pregap_frames));
pregap_index.length = pregap_frames; pregap_index.length = pregap_frames;
pregap_index.track_number = track_num; pregap_index.track_number = track_num;
pregap_index.index_number = 0;
pregap_index.is_pregap = true; pregap_index.is_pregap = true;
m_indices.push_back(pregap_index); m_indices.push_back(pregap_index);
@ -132,6 +133,7 @@ bool CDImageCueSheet::OpenAndParse(const char* filename)
Index last_index; Index last_index;
last_index.start_lba_on_disc = disc_lba; last_index.start_lba_on_disc = disc_lba;
last_index.track_number = track_num; last_index.track_number = track_num;
last_index.index_number = 1;
last_index.file = it->second; last_index.file = it->second;
last_index.file_sector_size = track_sector_size; last_index.file_sector_size = track_sector_size;
last_index.file_offset = 0; last_index.file_offset = 0;
@ -156,6 +158,7 @@ bool CDImageCueSheet::OpenAndParse(const char* filename)
} }
last_index.file_offset = index_offset * last_index.file_sector_size; last_index.file_offset = index_offset * last_index.file_sector_size;
last_index.index_number = static_cast<u32>(index_num);
last_index_offset = index_offset; last_index_offset = index_offset;
} }

View file

@ -407,6 +407,13 @@ void CDROM::PushStatResponse(Interrupt interrupt /*= Interrupt::ACK*/)
SetInterrupt(interrupt); SetInterrupt(interrupt);
} }
void CDROM::SendErrorResponse(u8 reason /*= 0x80*/)
{
m_response_fifo.Push(m_secondary_status.bits | 0x01);
m_response_fifo.Push(reason);
SetInterrupt(Interrupt::INT5);
}
void CDROM::UpdateStatusRegister() void CDROM::UpdateStatusRegister()
{ {
m_status.ADPBUSY = false; m_status.ADPBUSY = false;
@ -755,6 +762,25 @@ void CDROM::ExecuteCommand()
} }
break; break;
case Command::GetTN:
{
Log_DebugPrintf("CDROM GetTN command");
if (m_media)
{
m_response_fifo.Push(m_secondary_status.bits);
m_response_fifo.Push(DecimalToBCD(Truncate8(m_media->GetTrackNumber())));
m_response_fifo.Push(DecimalToBCD(Truncate8(m_media->GetTrackCount())));
SetInterrupt(Interrupt::ACK);
}
else
{
SendErrorResponse(0x80);
}
EndCommand();
}
break;
default: default:
Panic("Unknown command"); Panic("Unknown command");
break; break;

View file

@ -170,6 +170,7 @@ private:
bool HasPendingInterrupt() const { return m_interrupt_flag_register != 0; } bool HasPendingInterrupt() const { return m_interrupt_flag_register != 0; }
void SetInterrupt(Interrupt interrupt); void SetInterrupt(Interrupt interrupt);
void PushStatResponse(Interrupt interrupt = Interrupt::ACK); void PushStatResponse(Interrupt interrupt = Interrupt::ACK);
void SendErrorResponse(u8 reason = 0x80);
void UpdateStatusRegister(); void UpdateStatusRegister();
u32 GetAckDelayForCommand() const; u32 GetAckDelayForCommand() const;