From 1d7ecda2af97dcd4a1d2140bdf4b78947fc51a49 Mon Sep 17 00:00:00 2001 From: "Christoph \"baka0815\" Schwerdtfeger" Date: Sat, 22 Sep 2018 15:27:08 +0200 Subject: [PATCH] CHD: Check for extra frames If the frame count is not dividable by 4, there are extra frames added to keep a padding. This is true for F355 (450 frames -> 2 extra frames) and others. Also move CD_TRACK_PADDING to chd.cpp to work around problems with including from C and C++. --- core/deps/chdr/cdrom.h | 3 --- core/imgread/chd.cpp | 28 +++++++++++++++++----------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/core/deps/chdr/cdrom.h b/core/deps/chdr/cdrom.h index 65aa18218..60c819262 100644 --- a/core/deps/chdr/cdrom.h +++ b/core/deps/chdr/cdrom.h @@ -20,9 +20,6 @@ CONSTANTS ***************************************************************************/ -/* tracks are padded to a multiple of this many frames */ -extern const uint32_t CD_TRACK_PADDING; - #define CD_MAX_TRACKS (99) /* AFAIK the theoretical limit */ #define CD_MAX_SECTOR_DATA (2352) #define CD_MAX_SUBCODE_DATA (96) diff --git a/core/imgread/chd.cpp b/core/imgread/chd.cpp index 9b4f65dc2..8ac1b1302 100644 --- a/core/imgread/chd.cpp +++ b/core/imgread/chd.cpp @@ -2,6 +2,9 @@ #include "deps/chdr/chd.h" +/* tracks are padded to a multiple of this many frames */ +const uint32_t CD_TRACK_PADDING = 4; + struct CHDDisc : Disc { chd_file* chd; @@ -91,10 +94,11 @@ bool CHDDisc::TryOpen(const wchar* file) u8 flags; char temp[512]; u32 temp_len; - u32 total_frames=150; + u32 total_frames = 150; - u32 total_secs=0; - u32 total_hunks=0; + u32 total_secs = 0; + u32 total_hunks = 0; + int extraframes = 0; for(;;) { @@ -137,15 +141,17 @@ bool CHDDisc::TryOpen(const wchar* file) } printf("%s\n",temp); Track t; - t.StartFAD=total_frames; - total_frames+=frames; - t.EndFAD=total_frames-1; - t.ADDR=0; - t.CTRL=strcmp(type,"AUDIO")==0?0:4; - t.file = new CHDTrack(this,t.StartFAD,total_hunks,strcmp(type,"MODE1")?2352:2048); + t.StartFAD = total_frames + extraframes; + int padded = (frames + CD_TRACK_PADDING - 1) / CD_TRACK_PADDING; + extraframes += (padded * CD_TRACK_PADDING) - frames; + total_frames += frames; + t.EndFAD = total_frames - 1 + extraframes; + t.ADDR = 0; + t.CTRL = strcmp(type,"AUDIO") == 0 ? 0 : 4; + t.file = new CHDTrack(this, t.StartFAD, total_hunks, strcmp(type,"MODE1") ? 2352 : 2048); - total_hunks+=frames/sph; - if (frames%sph) + total_hunks += frames / sph; + if (frames % sph) total_hunks++; tracks.push_back(t);