diff --git a/core/imgread/cdi.cpp b/core/imgread/cdi.cpp index 3f1dc1d46a..4a3759cc7b 100644 --- a/core/imgread/cdi.cpp +++ b/core/imgread/cdi.cpp @@ -135,7 +135,7 @@ Disc* cdi_parse(const char* file, std::vector *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); diff --git a/core/imgread/chd.cpp b/core/imgread/chd.cpp index 757a673aaf..0bb7417ff8 100644 --- a/core/imgread/chd.cpp +++ b/core/imgread/chd.cpp @@ -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); diff --git a/core/imgread/common.cpp b/core/imgread/common.cpp index 1566fae7a8..151ec55dd9 100644 --- a/core/imgread/common.cpp +++ b/core/imgread/common.cpp @@ -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); @@ -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]; @@ -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) diff --git a/core/imgread/common.h b/core/imgread/common.h index 8da24bf514..78cafc3dd8 100644 --- a/core/imgread/common.h +++ b/core/imgread/common.h @@ -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() @@ -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 *digest = nullptr); diff --git a/core/imgread/gdi.cpp b/core/imgread/gdi.cpp index 2adf4af57e..1197d33758 100644 --- a/core/imgread/gdi.cpp +++ b/core/imgread/gdi.cpp @@ -84,7 +84,7 @@ Disc* load_gdi(const char* file, std::vector *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"); @@ -96,9 +96,11 @@ Disc* load_gdi(const char* file, std::vector *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); }