Skip to content

Commit

Permalink
gdrom: set correct lead-out FAD of single-density area
Browse files Browse the repository at this point in the history
Use end FAD +1 of track 2 as start of lead-out for single density area.
gdi: set track end FAD based on track size, not start of next track
chd: ignore pad frames when calculating end FAD
cdi: end FAD was one off
Issue #1386
  • Loading branch information
flyinghead committed Feb 6, 2024
1 parent c146a92 commit e592650
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion core/imgread/cdi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Disc* cdi_parse(const char* file, std::vector<u8> *digest)
else
{
std::fseek(fsource, track.total_length * track.sector_size, SEEK_CUR);
rv->EndFAD=track.start_lba +track.total_length;
rv->EndFAD = track.start_lba + track.total_length - 1;
}
track.position = std::ftell(fsource);

Expand Down
2 changes: 1 addition & 1 deletion core/imgread/chd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void CHDDisc::tryOpen(const char* file)
Track t;
t.StartFAD = total_frames;
total_frames += frames;
t.EndFAD = total_frames - 1;
t.EndFAD = total_frames - 1 - padframes;
t.CTRL = strcmp(type,"AUDIO") == 0 ? 0 : 4;

u32 sectorSize = getSectorSize(type);
Expand Down
17 changes: 14 additions & 3 deletions core/imgread/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ void libGDR_GetToc(u32* to, DiskArea area)
to[100] = createTrackInfoFirstLast(disc->tracks[last_track - 1], last_track);

if (disc->type == GdRom && area == SingleDensity)
// use smaller LEADOUT
to[101] = createTrackInfo(disc->LeadOut, 13085);
to[101] = createTrackInfo(disc->LeadOut, disc->tracks[1].EndFAD + 1);
else
to[101] = createTrackInfo(disc->LeadOut, disc->LeadOut.StartFAD);

Expand All @@ -241,6 +240,18 @@ DiscType GuessDiscType(bool m1, bool m2, bool da)
return CdRom;
}

bool Disc::readSector(u32 FAD, u8 *dst, SectorFormat *sector_type, u8 *subcode, SubcodeFormat *subcode_type)
{
for (size_t i = tracks.size(); i-- > 0; )
{
*subcode_type = SUBFMT_NONE;
if (tracks[i].Read(FAD, dst, sector_type, subcode, subcode_type))
return true;
}

return false;
}

void Disc::ReadSectors(u32 FAD, u32 count, u8* dst, u32 fmt, LoadProgress *progress)
{
u8 temp[2448];
Expand All @@ -256,7 +267,7 @@ void Disc::ReadSectors(u32 FAD, u32 count, u8* dst, u32 fmt, LoadProgress *progr
progress->label = "Loading...";
progress->progress = (float)i / count;
}
if (ReadSector(FAD,temp,&secfmt,q_subchannel,&subfmt))
if (readSector(FAD, temp, &secfmt, q_subchannel, &subfmt))
{
//TODO: Proper sector conversions
if (secfmt==SECFMT_2352)
Expand Down
15 changes: 3 additions & 12 deletions core/imgread/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,6 @@ struct Disc
DiscType type;
std::string catalog;

bool ReadSector(u32 FAD,u8* dst,SectorFormat* sector_type,u8* subcode,SubcodeFormat* subcode_type)
{
for (size_t i=tracks.size();i-->0;)
{
*subcode_type=SUBFMT_NONE;
if (tracks[i].Read(FAD,dst,sector_type,subcode,subcode_type))
return true;
}

return false;
}

void ReadSectors(u32 FAD, u32 count, u8 *dst, u32 fmt, LoadProgress *progress = nullptr);

virtual ~Disc()
Expand Down Expand Up @@ -211,6 +199,9 @@ struct Disc
GetSessionInfo(ses, ses[2]);
return (ses[3] << 16) | (ses[4] << 8) | (ses[5] << 0);
}

private:
bool readSector(u32 FAD, u8 *dst, SectorFormat *sector_type, u8 *subcode, SubcodeFormat *subcode_type);
};

Disc* OpenDisc(const std::string& path, std::vector<u8> *digest = nullptr);
Expand Down
8 changes: 5 additions & 3 deletions core/imgread/gdi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Disc* load_gdi(const char* file, std::vector<u8> *digest)
t.StartFAD = FADS + 150;
t.CTRL = CTRL;

if (SSIZE!=0)
if (SSIZE != 0)
{
std::string path = hostfs::storage().getSubPath(basepath, track_filename);
FILE *file = hostfs::storage().openFile(path, "rb");
Expand All @@ -96,9 +96,11 @@ Disc* load_gdi(const char* file, std::vector<u8> *digest)
if (digest != nullptr)
md5.add(file);
t.file = new RawTrackFile(file, OFFSET, t.StartFAD, SSIZE);
hostfs::FileInfo fileInfo = hostfs::storage().getFileInfo(path);
if ((fileInfo.size - OFFSET) % SSIZE != 0)
WARN_LOG(GDROM, "Warning: Size of track %s is not multiple of sector size %d", track_filename.c_str(), SSIZE);
t.EndFAD = t.StartFAD + (u32)(fileInfo.size - OFFSET) / SSIZE - 1;
}
if (!disc->tracks.empty())
disc->tracks.back().EndFAD = t.StartFAD - 1;
disc->tracks.push_back(t);
}

Expand Down

0 comments on commit e592650

Please sign in to comment.