[Patch] BIN/CUE-image support

Discussion of development and patch submission.
Post Reply
bit
Posts: 98
Joined: Sun 19 Mar, 2017 7:04 pm

[Patch] BIN/CUE-image support

Post by bit »

This patch adds support for BIN/CUE-images using the implementation from DosBox. It also has support for ISO-files so cdrom-iso.* is no longer needed.
There are some things I'm not sure about and it would be great if someone with more knowledge in this area could look at:
  • When to add/remove 150 sectors (or not to do it all). It works as it is right now but I'm not sure it is done correctly.
  • The msf-boolean seems to always be true while I've been working on this, not sure if it works as it should when it's false.
  • image_readtoc_raw is implemented but never tested.
  • I've had issues at times when switching images, sometimes the TOC isn't re-read so it plays music from the new image but the layout is from the previous one.
But other than that is seems to work well with the things I've tried (Little Big Adventure, Quake and Audio CDs).

EDIT: Deleted patch. Use the patch from this post instead.
Last edited by bit on Mon 15 May, 2017 1:18 pm, edited 1 time in total.
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

Re: [Patch] BIN/CUE-image support

Post by Battler »

bit wrote:When to add/remove 150 sectors (or not to do it all). It works as it is right now but I'm not sure it is done correctly.
Look at cdrom-ioctl.c, I explained it exactly there, at least as far as Windows and the CD-ROM specification are concerned.
I've had issues at times when switching images, sometimes the TOC isn't re-read so it plays music from the new image but the layout is from the previous one.
That's partially my fault as when I redid the CD-ROM switch detection, I accidentally messed it up for the ISO's.
User avatar
leilei
Posts: 1039
Joined: Fri 25 Apr, 2014 4:47 pm

Re: [Patch] BIN/CUE-image support

Post by leilei »

I've tried the patch and it works as far as I can tell from a quick test and compile. :thumbup:

Any subchannel reading plans? Some games (e.g. Quake) use it for de-emphasis
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

Re: [Patch] BIN/CUE-image support

Post by Battler »

There is a 2 second offset for the audio. The Windows IOCTL code used to have the same problem, when I fixed it and submitted a CD-ROM improvement patch here last year, I left in a comment in cdrom-ioctl.c before the MSFtoLBA #define explaining exactly why I changed it, but Sarah removed the comment for some reason when she committed my patch.
bit
Posts: 98
Joined: Sun 19 Mar, 2017 7:04 pm

Re: [Patch] BIN/CUE-image support

Post by bit »

Battler wrote:There is a 2 second offset for the audio. The Windows IOCTL code used to have the same problem, when I fixed it and submitted a CD-ROM improvement patch here last year, I left in a comment in cdrom-ioctl.c before the MSFtoLBA #define explaining exactly why I changed it, but Sarah removed the comment for some reason when she committed my patch.
Ah I see. I found your comment about this in your commit in 86Box, I will take a look at it later. Thank you!
Battler wrote:That's partially my fault as when I redid the CD-ROM switch detection, I accidentally messed it up for the ISO's.
Do you think it's easy to fix?
leilei wrote:I've tried the patch and it works as far as I can tell from a quick test and compile. :thumbup:

Any subchannel reading plans? Some games (e.g. Quake) use it for de-emphasis
Great to hear that it works! :)
Sorry, I have no plans for that at the moment.
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

Re: [Patch] BIN/CUE-image support

Post by Battler »

- bit: It is, just look at what I did for 86Box. Image changes are detected fine there.
bit
Posts: 98
Joined: Sun 19 Mar, 2017 7:04 pm

Re: [Patch] BIN/CUE-image support

Post by bit »

Battler wrote:- bit: It is, just look at what I did for 86Box. Image changes are detected fine there.
Great! I'll do that :)
User avatar
leilei
Posts: 1039
Joined: Fri 25 Apr, 2014 4:47 pm

Re: [Patch] BIN/CUE-image support

Post by leilei »

The delay is no big deal. CD audio never started instantly (especially on the cheaper drives)
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

Re: [Patch] BIN/CUE-image support

Post by Battler »

- leilei: In this case it's a bug, and I helped bit figure out why it happens. It's also not a delay, but the actual position incorrectly being 2 frames behind the reported position due to wrong MSF<->LBA conversion. I've never had a real CD-ROM drive that did that.

- bit: Your Read TOC handlers break loading ISO files in Windows 95 as well as 2000.

Edit: I just fixed that (for 86Box) by using the old ISO Read TOC handlers if the image is ISO but your new ones if it's CUE/BIN.
bit
Posts: 98
Joined: Sun 19 Mar, 2017 7:04 pm

Re: [Patch] BIN/CUE-image support

Post by bit »

Battler wrote:- bit: Your Read TOC handlers break loading ISO files in Windows 95 as well as 2000.

Edit: I just fixed that (for 86Box) by using the old ISO Read TOC handlers if the image is ISO but your new ones if it's CUE/BIN.
Oh, I thought I tried ISOs on W95 but seems like I didn't :)
Thanks for letting me know! I'm going to look into fixing these issues now.
bit
Posts: 98
Joined: Sun 19 Mar, 2017 7:04 pm

Re: [Patch] BIN/CUE-image support

Post by bit »

Here are fixes for the 2 second delay and ISOs on Windows 95. It replaces the first patch.
I tried to fix the issue with TOC when switching images but I couldn't get it to work, maybe someone with more knowledge about that is willing to take a look at it.

I've tried this with a bunch of different images in both DOS and Windows 95 and so far it works very well.
Attachments
cdrom_image_170512.patch
(56.73 KiB) Downloaded 508 times
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

Re: [Patch] BIN/CUE-image support

Post by Battler »

- bit: I got a report from a Korean site that data tracks after the first one are not loaded correctly from CUE/BIN, please look into what happens.
basic2004
Posts: 124
Joined: Sun 08 Jan, 2017 5:59 pm

Re: [Patch] BIN/CUE-image support

Post by basic2004 »

Battler wrote:- bit: I got a report from a Korean site that data tracks after the first one are not loaded correctly from CUE/BIN, please look into what happens.
Oh, I saw in there, you translated this Korean sentence from there correctly.
하지만 2번째 트랙 이후의 데이터는 아직 제대로 불러오지 못하고 있습니다.
I wrote this report. I mount BIN/CUE, and play CD-Audio start from 2nd track, I heard noise.
Mount BIN/CUE with Daemon Tools and load mounted drive, CD-Audio plays correctly.
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

Re: [Patch] BIN/CUE-image support

Post by Battler »

- bit: At least in Windows 95 OSR 2.x, I still can't read the mounted ISO's.

Edit: You're writing, into the TOC, the data track and a seemingly failed second track (attr 0x00), but not a lead out track (attr 0x16).

Edit #2: This is how to fix the ISO's:
1. In image_get_last_block(), change:
address = MSFtoLBA(tmsf.min, tmsf.sec, tmsf.fr);
To:
address = MSFtoLBA(tmsf.min, tmsf.sec, tmsf.fr) - 150;
.
This is because the DOSBox code returns real MSF, starting from 00:02:00 (corresponding to LBA 0x00000000).

2. In image_readtoc() and image_readtoc_session(), change:
MSFtoLBA(tmsf.min, tmsf.sec, tmsf.fr);
To:
MSFtoLBA(tmsf.min, tmsf.sec, tmsf.fr) - 150;
.
This is because the DOSBox code returns real MSF, starting from 00:02:00 (corresponding to LBA 0x00000000).

3. In CDROM_Interface_Image::LoadIsoFile(char* filename), add:
track.track_number = 1;
After:
track.number = 1;
.
This is because the DOSBox code erroneously forgets to set the reported number of the data track to 1.

4. In the same function, change:
track.attr = 0;
To:
track.attr = 0x16;
.
I believe 0x16 is the correct lead out control byte.

5. In CDROM_Interface_Image::LoadCueSheet(char *cuefile), change:
track.attr = 0;
To:
track.attr = 0x16;
After:
track.track_number = 0xAA;
.
This is for CUE/BIN rather than ISO but I believe 0x16 is the correct lead out control byte.

This is it. :p
bit
Posts: 98
Joined: Sun 19 Mar, 2017 7:04 pm

Re: [Patch] BIN/CUE-image support

Post by bit »

basic2004 wrote:
Battler wrote:- bit: I got a report from a Korean site that data tracks after the first one are not loaded correctly from CUE/BIN, please look into what happens.
Oh, I saw in there, you translated this Korean sentence from there correctly.
하지만 2번째 트랙 이후의 데이터는 아직 제대로 불러오지 못하고 있습니다.
I wrote this report. I mount BIN/CUE, and play CD-Audio start from 2nd track, I heard noise.
Mount BIN/CUE with Daemon Tools and load mounted drive, CD-Audio plays correctly.
I haven't experienced this myself with any of my images. Is the image available somewhere so I take a look at it?

Battler: track.track_number = 1 is added in the patch from 170512, that's what fixed the ISOs with Win95 (also tested with OSR2 and Win98). You probably just missed it as it was a small fix, so I should probably have mentioned what was changed :)
But those other fixes you mentioned looks good, I will add them. Thank you!
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

Re: [Patch] BIN/CUE-image support

Post by Battler »

- basic2004: If you could PM me the specific CUE/BIN you're having problems with, and how to reproduce the problem, I'll try it.

- bit: My fixes might fix that actually, though I'm still awaiting response from another user who reported a similar problem to see if they do.
Katakis
Posts: 118
Joined: Thu 05 Mar, 2015 6:42 am

Re: [Patch] BIN/CUE-image support

Post by Katakis »

This patch just saved me from requesting this in the "Katakis's Christmas Wishlist" I plan to do at the end of the year.

Good thing, too, considering that neither A120% or DT are only available for Windows, Linux users were unable to play games using CD-Audio tracks.
ETPC
Posts: 4
Joined: Fri 10 Mar, 2017 4:10 am

Re: [Patch] BIN/CUE-image support

Post by ETPC »

Pardon my noobishness, but how can I roll this patch into a regular build of PCem? Is it usable right now?
User avatar
omarsis81
Posts: 945
Joined: Thu 17 Dec, 2015 6:20 pm

Re: [Patch] BIN/CUE-image support

Post by omarsis81 »

ETPC wrote:Pardon my noobishness, but how can I roll this patch into a regular build of PCem? Is it usable right now?
Most likely you'll have to wait until the main developer (Sarah) commit the patch into the mainline so you can compile it
User avatar
SarahWalker
Site Admin
Posts: 2054
Joined: Thu 24 Apr, 2014 4:18 pm

Re: [Patch] BIN/CUE-image support

Post by SarahWalker »

Committed at rev 736. I made a couple of fixes (fixing IOCTL audio, and image loading on startup), hopefully I haven't introduced any new issues...
User avatar
leilei
Posts: 1039
Joined: Fri 25 Apr, 2014 4:47 pm

Re: [Patch] BIN/CUE-image support

Post by leilei »

Tried the latest PCem revision with this, did notice there's delays when dealing with seeking on early Sierra CD games (Stellar 7 in particular, one audio track with many points to seek to)

Quake (DOS, v1.01) will seem to break CD audio for the rest of the running PCem session, at least when under Windows 98SE.
EluanCM
Posts: 112
Joined: Tue 27 Oct, 2015 2:07 pm
Location: Brazil
Contact:

Re: [Patch] BIN/CUE-image support

Post by EluanCM »

To anyone having problems with this on Linux: remember about case-sensitivity. Some older cd ripping programs write the cuesheets contents in upper case, including the filename of the .bin. Just edit the cuesheet/rename the .bin and it should work. Or you can use all uppercases when ripping. I can confirm that Alcohol 52%/120% write cuesheets with proper cases.
Post Reply