From 38d49136ce15d3506f4885663a5e77464ad79e7e Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Thu, 4 Jul 2019 18:20:05 -0400 Subject: [PATCH] cdrom: add function for reading via LBA numbers --- libretro-common/cdrom/cdrom.c | 53 +++++++++++++++++++ libretro-common/include/cdrom/cdrom.h | 2 + .../vfs/vfs_implementation_cdrom.c | 1 + 3 files changed, 56 insertions(+) diff --git a/libretro-common/cdrom/cdrom.c b/libretro-common/cdrom/cdrom.c index bd6bb81204..e263ca146a 100644 --- a/libretro-common/cdrom/cdrom.c +++ b/libretro-common/cdrom/cdrom.c @@ -1058,6 +1058,59 @@ int cdrom_read(libretro_vfs_implementation_file *stream, unsigned char min, unsi rv = cdrom_send_command(stream, DIRECTION_IN, s, len, cdb, sizeof(cdb), skip); +#ifdef CDROM_DEBUG + printf("read msf status code %d\n", rv); + fflush(stdout); +#endif + + if (rv) + return 1; + + return 0; +} + +int cdrom_read_lba(libretro_vfs_implementation_file *stream, unsigned lba, void *s, size_t len, size_t skip) +{ + /* MMC Command: READ CD */ + unsigned char cdb[] = {0xBE, 0, 0, 0, 0, 0, 0, 0, 0, 0xF8, 0, 0}; + unsigned lba_orig = lba; + int rv; + + lba = swap_if_big32(lba); + + cdb[2] = (lba >> 24) & 0xFF; + cdb[3] = (lba >> 16) & 0xFF; + cdb[4] = (lba >> 8) & 0xFF; + cdb[5] = (lba >> 0) & 0xFF; + + if (len + skip <= 2352) + { + cdb[8] = 1; + +#ifdef CDROM_DEBUG + printf("single-frame read: from %d count %d skip %" PRId64 "\n", lba_orig, 1, skip); + fflush(stdout); +#endif + } + else + { + unsigned frames = lba_orig + ceil((len + skip) / 2352.0); + unsigned lba_count = frames - lba_orig; + + lba_count = swap_if_big32(lba_count); + + cdb[6] = (lba_count >> 16) & 0xFF; + cdb[7] = (lba_count >> 8) & 0xFF; + cdb[8] = (lba_count >> 0) & 0xFF; + +#ifdef CDROM_DEBUG + printf("multi-frame read: from %d to %d len %d skip %" PRId64 "\n", lba_orig, frames, frames - lba_orig, skip); + fflush(stdout); +#endif + } + + rv = cdrom_send_command(stream, DIRECTION_IN, s, len, cdb, sizeof(cdb), skip); + #ifdef CDROM_DEBUG printf("read status code %d\n", rv); fflush(stdout); diff --git a/libretro-common/include/cdrom/cdrom.h b/libretro-common/include/cdrom/cdrom.h index 372c8e8f4a..3c73847240 100644 --- a/libretro-common/include/cdrom/cdrom.h +++ b/libretro-common/include/cdrom/cdrom.h @@ -79,6 +79,8 @@ int cdrom_get_inquiry(const libretro_vfs_implementation_file *stream, char *mode int cdrom_read(libretro_vfs_implementation_file *stream, unsigned char min, unsigned char sec, unsigned char frame, void *s, size_t len, size_t skip); +int cdrom_read_lba(libretro_vfs_implementation_file *stream, unsigned lba, void *s, size_t len, size_t skip); + int cdrom_set_read_speed(libretro_vfs_implementation_file *stream, unsigned speed); int cdrom_stop(const libretro_vfs_implementation_file *stream); diff --git a/libretro-common/vfs/vfs_implementation_cdrom.c b/libretro-common/vfs/vfs_implementation_cdrom.c index 0e9f578b2b..8b90322177 100644 --- a/libretro-common/vfs/vfs_implementation_cdrom.c +++ b/libretro-common/vfs/vfs_implementation_cdrom.c @@ -372,6 +372,7 @@ int64_t retro_vfs_file_read_cdrom(libretro_vfs_implementation_file *stream, #endif rv = cdrom_read(stream, min, sec, frame, s, (size_t)len, skip); + /*rv = cdrom_read_lba(stream, stream->cdrom.cur_lba, s, (size_t)len, skip);*/ if (rv) {