Skip to content

Commit

Permalink
CDImage: Support reading MODE1 sectors
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Sep 7, 2024
1 parent 6ea2bb1 commit 1b2ff7e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/util/cd_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,26 @@ u32 CDImage::Read(ReadMode read_mode, u32 sector_count, void* buffer)
switch (read_mode)
{
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;
break;
}
break;

case ReadMode::RawNoSync:
std::memcpy(buffer_ptr, raw_sector + SECTOR_SYNC_SIZE, RAW_SECTOR_SIZE - SECTOR_SYNC_SIZE);
Expand Down
2 changes: 2 additions & 0 deletions src/util/cd_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class CDImage
DATA_SECTOR_SIZE = 2048,
SECTOR_SYNC_SIZE = 12,
SECTOR_HEADER_SIZE = 4,
MODE1_HEADER_SIZE = 4,
MODE2_HEADER_SIZE = 12,
FRAMES_PER_SECOND = 75, // "sectors", or "timecode frames" (not "channel frames")
SECONDS_PER_MINUTE = 60,
FRAMES_PER_MINUTE = FRAMES_PER_SECOND * SECONDS_PER_MINUTE,
Expand Down

0 comments on commit 1b2ff7e

Please sign in to comment.