CDROM: Move pregap handling to image class
This commit is contained in:
parent
ba67f69c2a
commit
767e8f08e0
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue