CDROM: Move pregap handling to image class

This commit is contained in:
Connor McLaughlin
2019-09-26 00:15:06 +10:00
parent ba67f69c2a
commit 767e8f08e0
3 changed files with 13 additions and 9 deletions

View File

@ -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)