diff --git a/src/common/cd_image.cpp b/src/common/cd_image.cpp index 3c5a6cc87..67152f67b 100644 --- a/src/common/cd_image.cpp +++ b/src/common/cd_image.cpp @@ -24,7 +24,7 @@ std::unique_ptr CDImage::Open(const char* filename) if (CASE_COMPARE(extension, ".cue") == 0) 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); #undef CASE_COMPARE diff --git a/src/common/cd_image.h b/src/common/cd_image.h index 46f61d86f..7f5d52c6c 100644 --- a/src/common/cd_image.h +++ b/src/common/cd_image.h @@ -90,7 +90,9 @@ public: LBA GetPositionInTrack() const { return m_position_in_track; } Position GetMSFPositionInTrack() const { return Position::FromLBA(m_position_in_track); } 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 GetTrackCount() const { return static_cast(m_tracks.size()); } // Seek to data LBA. bool Seek(LBA lba); @@ -120,6 +122,7 @@ protected: u32 file_sector_size; LBA start_lba_on_disc; u32 track_number; + u32 index_number; LBA start_lba_in_track; u32 length; bool is_pregap; diff --git a/src/common/cd_image_bin.cpp b/src/common/cd_image_bin.cpp index f56121573..f7471d80e 100644 --- a/src/common/cd_image_bin.cpp +++ b/src/common/cd_image_bin.cpp @@ -48,6 +48,7 @@ bool CDImageBin::Open(const char* filename) pregap_index.start_lba_in_track = static_cast(-static_cast(pregap_frames)); pregap_index.length = pregap_frames; pregap_index.track_number = 1; + pregap_index.index_number = 0; pregap_index.is_pregap = true; 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.start_lba_on_disc = pregap_index.length; data_index.track_number = 1; + data_index.index_number = 1; data_index.start_lba_in_track = 0; data_index.length = m_lba_count; m_indices.push_back(data_index); diff --git a/src/common/cd_image_cuesheet.cpp b/src/common/cd_image_cuesheet.cpp index 21c200e85..8e17358ac 100644 --- a/src/common/cd_image_cuesheet.cpp +++ b/src/common/cd_image_cuesheet.cpp @@ -118,6 +118,7 @@ bool CDImageCueSheet::OpenAndParse(const char* filename) pregap_index.start_lba_in_track = static_cast(static_cast(-pregap_frames)); pregap_index.length = pregap_frames; pregap_index.track_number = track_num; + pregap_index.index_number = 0; pregap_index.is_pregap = true; m_indices.push_back(pregap_index); @@ -132,6 +133,7 @@ bool CDImageCueSheet::OpenAndParse(const char* filename) Index last_index; last_index.start_lba_on_disc = disc_lba; last_index.track_number = track_num; + last_index.index_number = 1; last_index.file = it->second; last_index.file_sector_size = track_sector_size; 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.index_number = static_cast(index_num); last_index_offset = index_offset; } diff --git a/src/core/cdrom.cpp b/src/core/cdrom.cpp index 1837a4448..bed7bda4a 100644 --- a/src/core/cdrom.cpp +++ b/src/core/cdrom.cpp @@ -407,6 +407,13 @@ void CDROM::PushStatResponse(Interrupt interrupt /*= Interrupt::ACK*/) 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() { m_status.ADPBUSY = false; @@ -755,6 +762,25 @@ void CDROM::ExecuteCommand() } 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: Panic("Unknown command"); break; diff --git a/src/core/cdrom.h b/src/core/cdrom.h index 0a5e584b4..8115c9744 100644 --- a/src/core/cdrom.h +++ b/src/core/cdrom.h @@ -170,6 +170,7 @@ private: bool HasPendingInterrupt() const { return m_interrupt_flag_register != 0; } void SetInterrupt(Interrupt interrupt); void PushStatResponse(Interrupt interrupt = Interrupt::ACK); + void SendErrorResponse(u8 reason = 0x80); void UpdateStatusRegister(); u32 GetAckDelayForCommand() const;