Skip to content

Improve async CDROM support #888

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

Closed
wants to merge 6 commits into from
Closed

Conversation

pcercuei
Copy link

  • Decouple libretro from the async-cdrom code. Libretro has no business being in libpcsxcore.
  • Add C11 threads wrapper for non-libretro platforms
  • Add support for reading subchannel data with hardware CD-ROM readers
  • Misc. fixes.

This allows me to use the async. CDROM functionality with ISOs and hardware CD-ROM in my Bloom downstream PSX emulator for Dreamcast.

Note that I suspect the async CDROM code to be slightly buggy, regarding subchannel data. If I enable subchannel reads in my CDROM driver (set acdrom.have_subchannel), libcrypt games will boot (FF8 in my case) properly, but some other games (original copy of Need for Speed) won't boot unless disabled.

This stuff doesn't belong here, and prevents other emulators using
libpcsxcore from implementing the new async CDROM API properly.

Signed-off-by: Paul Cercueil <[email protected]>
Rename cdrom_read_sector() to rcdrom_readSector(), and
cdrom_is_media_inserted() to rcdrom_isMediaInserted() to match the rest
of the "rcdrom" API.

Update rcdrom_open() to return a handle, which will then be passed
around to every other rcdrom API call.

Signed-off-by: Paul Cercueil <[email protected]>
Add function rcdrom_readSub(), that can be implemented by frontends, and
update rcdrom_open() to take an extra parameter, that can be set by the
frontend to tell the async CD-ROM code whether or not subchannel reads
are supported.

Signed-off-by: Paul Cercueil <[email protected]>
Libretro threads only work on... libretro.
Add support for C11 threads for the non-libretro platforms that still
want the async CD-ROM code.

Signed-off-by: Paul Cercueil <[email protected]>
An empty path string previously meant we were going to use the hardware
CD-ROM. This is obvious when looking at the UsingIso() function for
instance.

Signed-off-by: Paul Cercueil <[email protected]>
Align the address and size of read buffers to 64 bytes, which
should be bigger or equal than the size of the cache lines on most
systems.

This allows hardware CD-ROM implementations to perform reads using DMA,
which generally have tight requirements on alignment.

Signed-off-by: Paul Cercueil <[email protected]>
@notaz
Copy link
Collaborator

notaz commented Apr 15, 2025

Subchannel support was intentionally omitted as the prefetcher is unable to handle it now and I left it to be faked by the fallback code instead. The way PSX works is that the subchannel data is from a few sectors ahead of the data sector accessible through the FIFO, and the prefetcher always throws older sectors out right now, causing seeks back and forth making it all unusable on PC.

That said from what I see you only set have_subchannel to 0 for libretro so it shouldn't hurt the usual targets. Still I'll want to test this on PC cdrom before merging.

@pcercuei
Copy link
Author

Would it help if the subchannel data for a sector was read in (and returned from) the rcdrom_readSector directly?
Then if the PSX code tries to read subchannel data, it would also fetch the corresponding sector, acting as a prefetch of sorts.

@notaz
Copy link
Collaborator

notaz commented Apr 24, 2025

It would help but it also needs to be updated to prevent it evicting the current data sector. It's now possible to select the buffer size of 0 or 1 sectors which won't work as-is.

Anyway applied this to my main repo (+a double-free fix), will merge here some other time.

@notaz notaz closed this Apr 24, 2025
@pcercuei
Copy link
Author

@notaz the reason I'm asking, is that on Dreamcast at least, you need to read a sector first to be able to get its subchannel data, so it makes sense to read both at the same time. I can imagine it works like that on PC drives as well. And if it permits to simplify things in PCSX that's even better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants