CDImage: Support reading MODE1 sectors

This commit is contained in:
Stenzek 2024-09-07 16:05:43 +10:00
parent e7e0b03a70
commit 655fdf8061
No known key found for this signature in database
2 changed files with 21 additions and 2 deletions

View file

@ -267,9 +267,26 @@ u32 CDImage::Read(ReadMode read_mode, u32 sector_count, void* buffer)
switch (read_mode) switch (read_mode)
{ {
case ReadMode::DataOnly: case ReadMode::DataOnly:
std::memcpy(buffer_ptr, raw_sector + 24, DATA_SECTOR_SIZE); {
const SectorHeader* header = reinterpret_cast<const SectorHeader*>(raw_sector + SECTOR_SYNC_SIZE);
if (header->sector_mode == 1)
{
std::memcpy(buffer_ptr, raw_sector + SECTOR_SYNC_SIZE + MODE1_HEADER_SIZE, DATA_SECTOR_SIZE);
}
else if (header->sector_mode == 2)
{
std::memcpy(buffer_ptr, raw_sector + SECTOR_SYNC_SIZE + MODE2_HEADER_SIZE, DATA_SECTOR_SIZE);
}
else
{
ERROR_LOG("Invalid sector mode {} at LBA {}", header->sector_mode,
m_current_index->start_lba_on_disc + m_position_in_track);
break;
}
buffer_ptr += DATA_SECTOR_SIZE; buffer_ptr += DATA_SECTOR_SIZE;
break; }
break;
case ReadMode::RawNoSync: case ReadMode::RawNoSync:
std::memcpy(buffer_ptr, raw_sector + SECTOR_SYNC_SIZE, RAW_SECTOR_SIZE - SECTOR_SYNC_SIZE); std::memcpy(buffer_ptr, raw_sector + SECTOR_SYNC_SIZE, RAW_SECTOR_SIZE - SECTOR_SYNC_SIZE);

View file

@ -30,6 +30,8 @@ public:
DATA_SECTOR_SIZE = 2048, DATA_SECTOR_SIZE = 2048,
SECTOR_SYNC_SIZE = 12, SECTOR_SYNC_SIZE = 12,
SECTOR_HEADER_SIZE = 4, SECTOR_HEADER_SIZE = 4,
MODE1_HEADER_SIZE = 4,
MODE2_HEADER_SIZE = 12,
FRAMES_PER_SECOND = 75, // "sectors", or "timecode frames" (not "channel frames") FRAMES_PER_SECOND = 75, // "sectors", or "timecode frames" (not "channel frames")
SECONDS_PER_MINUTE = 60, SECONDS_PER_MINUTE = 60,
FRAMES_PER_MINUTE = FRAMES_PER_SECOND * SECONDS_PER_MINUTE, FRAMES_PER_MINUTE = FRAMES_PER_SECOND * SECONDS_PER_MINUTE,