cdrom: add function for reading via LBA numbers

This commit is contained in:
Brad Parker 2019-07-04 18:20:05 -04:00
parent 788b6cd39c
commit 38d49136ce
3 changed files with 56 additions and 0 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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)
{