From 767e8f08e0fc5054c9b1dad2e033116fb633b4dc Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 26 Sep 2019 00:15:06 +1000 Subject: [PATCH] CDROM: Move pregap handling to image class --- src/common/cd_image.cpp | 11 ++++++----- src/common/cd_image.h | 7 +++++-- src/pse/cdrom.cpp | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/common/cd_image.cpp b/src/common/cd_image.cpp index 7841c18bc..b3cc635ea 100644 --- a/src/common/cd_image.cpp +++ b/src/common/cd_image.cpp @@ -11,14 +11,15 @@ CDImage::~CDImage() m_data_file->Release(); } -constexpr u64 CDImage::MSFToLBA(u32 minute, u32 second, u32 frame) +constexpr u64 CDImage::MSFToLBA(u32 pregap_seconds, u32 minute, u32 second, u32 frame) { - return ZeroExtend64(minute) * FRAMES_PER_MINUTE + ZeroExtend64(second) * FRAMES_PER_SECOND + ZeroExtend64(frame); + return ZeroExtend64(minute) * FRAMES_PER_MINUTE + ZeroExtend64(second) * FRAMES_PER_SECOND + ZeroExtend64(frame) - + ZeroExtend64(pregap_seconds) * FRAMES_PER_SECOND; } -constexpr void CDImage::LBAToMSF(u64 lba, u32* minute, u32* second, u32* frame) +constexpr void CDImage::LBAToMSF(u32 pregap_seconds, u64 lba, u32* minute, u32* second, u32* frame) { - const u32 offset = lba % FRAMES_PER_MINUTE; + const u64 offset = (lba + (pregap_seconds * FRAMES_PER_SECOND) % FRAMES_PER_MINUTE); *minute = Truncate32(lba / FRAMES_PER_MINUTE); *second = Truncate32(offset / FRAMES_PER_SECOND); *frame = Truncate32(offset % FRAMES_PER_SECOND); @@ -52,7 +53,7 @@ bool CDImage::Seek(u64 lba) bool CDImage::Seek(u32 minute, u32 second, u32 frame) { - return Seek(MSFToLBA(minute, second, frame)); + return Seek(MSFToLBA(m_pregap_seconds, minute, second, frame)); } u32 CDImage::Read(ReadMode read_mode, u64 lba, u32 sector_count, void* buffer) diff --git a/src/common/cd_image.h b/src/common/cd_image.h index 3bcfe1ae1..f27c78f51 100644 --- a/src/common/cd_image.h +++ b/src/common/cd_image.h @@ -27,8 +27,8 @@ public: }; // Conversion helpers. - static constexpr u64 MSFToLBA(u32 minute, u32 second, u32 frame); - static constexpr void LBAToMSF(u64 lba, u32* minute, u32* second, u32* frame); + static constexpr u64 MSFToLBA(u32 pregap_seconds, u32 minute, u32 second, u32 frame); + static constexpr void LBAToMSF(u32 pregap_seconds, u64 lba, u32* minute, u32* second, u32* frame); // Accessors. u64 GetCurrentLBA() const { return m_current_lba; } @@ -53,6 +53,9 @@ private: // TODO: Multiple data files from cue sheet ByteStream* m_data_file = nullptr; + // Pregap size. + u32 m_pregap_seconds = 2; + // Current LBA/total LBAs. u64 m_current_lba = 0; u64 m_lba_count = 0; diff --git a/src/pse/cdrom.cpp b/src/pse/cdrom.cpp index 4853a90df..49c1d3c2a 100644 --- a/src/pse/cdrom.cpp +++ b/src/pse/cdrom.cpp @@ -565,7 +565,7 @@ void CDROM::ExecuteCommand() { Assert(m_setloc_dirty); StopReading(); - if (!m_media || !m_media->Seek(m_setloc.minute, m_setloc.second - 2 /* pregap */, m_setloc.frame)) + if (!m_media || !m_media->Seek(m_setloc.minute, m_setloc.second, m_setloc.frame)) { Panic("Error in Setloc command"); return; @@ -619,7 +619,7 @@ void CDROM::ExecuteCommand() // TODO: Seek timing and clean up... if (m_setloc_dirty) { - if (!m_media || !m_media->Seek(m_setloc.minute, m_setloc.second - 2 /* pregap */, m_setloc.frame)) + if (!m_media || !m_media->Seek(m_setloc.minute, m_setloc.second, m_setloc.frame)) { Panic("Seek error"); }