New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util/cdrom: Refactor parse_cue and parse_gdicue #12087
Conversation
if (wavlen != 0) | ||
{ | ||
outtoc.tracks[trknum].frames = wavlen/2352; | ||
outinfo.track[trknum].offset = wavoffs; | ||
wavoffs = wavlen = 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This originally set outtoc.tracks[trknum].trktype = CD_TRACK_AUDIO;
but directly below this convert_type_string_to_track_info
gets called which will set outtoc.tracks[trknum].trktype
based on the TRACK's typestring so I removed it.
Maybe it would be a better idea to move the call to convert_type_string_to_track_info
before this so the track type can be forced when a WAVE file type is selected as input?
9443cb3
to
5250a57
Compare
I ended up reverting #11913 and rewrote how Dreamcast cue/bins are parsed. This PR breaks both the SHA1 and sometimes the Data SHA1 of any Dreamcast CHDs previously made using Redump cue/bins but it feels necessary. CHDs created using GDIs (both TOSEC and Redump GDIs) are unaffected. I didn't test with a ton of games but I did test with all of the type varieties previously implemented. Most games are either "type I" or "type III split". Here's the breakdown using all of the Dreamcast cues from redump's database:
For easy testing/reference, here are the type II and type III (non-split) games:
Disclaimer: The TOSEC .raw files all seem to have the audio data start at a random offset (dump method issue?) whereas Redump's audio tracks were all uniform from my testing, so for testing purposes I manually modified the TOSEC .raw files to have the data start at offset 0 and padded the files an appropriate length to keep the same filesize.
|
…ous compatibility fixes (fixes everything except 150 lost pregap frames from type III split formats)
5250a57
to
d3169c7
Compare
if (cdrom->is_gdrom() && (mode == MODE_CUEBIN)) | ||
{ | ||
util::stream_format(std::cout, "Warning: extracting GD-ROM CHDs as bin/cue is not fully supported and will result in an unusable CD-ROM cue file.\n"); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This never worked even before the recent changes, so finally add a warning about it. Someone needs to go in and add proper support for GD-ROM cues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn’t see any major issues with a quick read, but I’m pretty tired and I’m not overly familiar with this part of the code. It really needs testing, and probably some more pairs of eyes.
I’m not very happy about the fallout from the last change to the GD-ROM handling, or the other issues in chdman that keep being found. Issues in CHD handling don’t just affect MAME.
while ((i < linebuffersize) && (j < tokensize)) | ||
while ((i < linebuffersize) && (j < tokensize) && (linebuffer[i] != '\0')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does linebuffer[i] != '\0'
happen? Is linebuffersize
the size of the buffer rather than the size of its content? The code seemed to be treating it as the size of the content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
linebuffersize
is just sizeof(linebuffer)
so it's the entire buffer size rather than its contents. So without the null byte check, the entire buffer is processed every time instead of just ending when reasonable.
Lines 1411 to 1422 in 1565fb9
* @def TOKENIZE(); | |
* | |
* @brief A macro that defines tokenize. | |
* | |
* @param linebuffer The linebuffer. | |
* @param i Zero-based index of the. | |
* @param sizeof(linebuffer) The sizeof(linebuffer) | |
* @param token The token. | |
* @param sizeof(token) The sizeof(token) | |
*/ | |
#define TOKENIZE i = tokenize( linebuffer, i, sizeof(linebuffer), token, sizeof(token) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eugh, if linebuffer is a pointer, bad things will happen. Will it work if you change it to tokenize( linebuffer, i, std::size(linebuffer), token, std::size(token) );
so it will give an error if linebuffer
and token
aren’t array-like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it works from some quick testing.
a8388ef
f63c605
to
0ed1996
Compare
…element count for tokenizer
I merged this. It should put us in a better position than where we’ve been for the last few months, anyway. I’d still appreciate if more people could give it a spin. |
…Hub mamedev#12081). (mamedev#12087) This should greatly improve data integrity when creating and extracting GD-ROM images. * util/cdrom.cpp: Refactored parse_cue to handle GD-ROMs. * util/cdrom.cpp: Don't discard any data from GD-ROM cue/bin input including pre-gap data. * tools/chdman.cpp: Fixed splitframes handling. * tools/chdman.cpp: Added warning when extracting GD-ROM CHDs to cue/bin format.
@cuavas Tested against a nearly complete Redump set (a few seem MIA) using oxyromon as the ROM manager. Re-validated the CHD files using the original CUE files with no obvious issues. |
Thanks. |
Closes #12081. Follow up to #11913.
After fixing the problem mentioned in the issue (the first commit) I realized there isn't that much unique code between
parse_gdicue
andparse_cue
so I decided to merge them into one function so that there's no need to maintain two separate .cue parsers anymore.Additionally I did some other small cleanups such as clearing out some of the line buffers and adding some additional error checks in. Sufficient size checks were already in place already so it wasn't likely to crash anything but I figured it didn't hurt while I'm at changing things around. Mainly was concerned that it looks like you could end up copying a bunch of garbage into
token
iflinebuffer
had garbage in it whencdrom_file::tokenize
was called.For testing I extracted some v5 CHDs I had on hand and then recreated them to make sure the hashes matched. Also tried a few Redump Dreamcast dumps to make sure the extracted .bin matched the original Redump data (compared with all individual tracks combined into a single file so I could just do a SHA1 check between the CHD dump and original data).