diff --git a/libretro-common/cdrom/cdrom.c b/libretro-common/cdrom/cdrom.c index 0f1918e172..1a01b01921 100644 --- a/libretro-common/cdrom/cdrom.c +++ b/libretro-common/cdrom/cdrom.c @@ -48,7 +48,7 @@ #include #endif -#define CDROM_CUE_TRACK_BYTES 86 +#define CDROM_CUE_TRACK_BYTES 107 #define CDROM_MAX_SENSE_BYTES 16 #define CDROM_MAX_RETRIES 10 @@ -379,7 +379,7 @@ int cdrom_read_subq(libretro_vfs_implementation_file *stream, unsigned char *buf if (/*(control == 4 || control == 6) && */adr == 1 && tno == 0 && point >= 1 && point <= 99) { printf("- Session#: %d TNO %d POINT %d ", session_num, tno, point); - printf("Track start time: (MSF %02u:%02u:%02u) ", pmin, psec, pframe); + printf("Track start time: (MSF %02u:%02u:%02u) ", (unsigned)pmin, (unsigned)psec, (unsigned)pframe); } else if (/*(control == 4 || control == 6) && */adr == 1 && tno == 0 && point == 0xA0) { @@ -395,7 +395,7 @@ int cdrom_read_subq(libretro_vfs_implementation_file *stream, unsigned char *buf else if (/*(control == 4 || control == 6) && */adr == 1 && tno == 0 && point == 0xA2) { printf("- Session#: %d TNO %d POINT %d ", session_num, tno, point); - printf("Lead-out runtime: (MSF %02u:%02u:%02u) ", pmin, psec, pframe); + printf("Lead-out runtime: (MSF %02u:%02u:%02u) ", (unsigned)pmin, (unsigned)psec, (unsigned)pframe); } printf("\n"); @@ -560,7 +560,24 @@ int cdrom_write_cue(libretro_vfs_implementation_file *stream, char **out_buf, si pos += snprintf(*out_buf + pos, len - pos, "FILE \"cdrom://drive%c-track%02d.bin\" BINARY\n", cdrom_drive, point); #endif pos += snprintf(*out_buf + pos, len - pos, " TRACK %02d %s\n", point, track_type); - pos += snprintf(*out_buf + pos, len - pos, " INDEX 01 00:00:00\n"); + + { + unsigned pregap_lba_len = toc->track[point - 1].lba - toc->track[point - 1].lba_start; + + if (toc->track[point - 1].audio && pregap_lba_len > 0) + { + unsigned char min = 0; + unsigned char sec = 0; + unsigned char frame = 0; + + lba_to_msf(pregap_lba_len, &min, &sec, &frame); + + pos += snprintf(*out_buf + pos, len - pos, " INDEX 00 00:00:00\n"); + pos += snprintf(*out_buf + pos, len - pos, " INDEX 01 %02u:%02u:%02u\n", (unsigned)min, (unsigned)sec, (unsigned)frame); + } + else + pos += snprintf(*out_buf + pos, len - pos, " INDEX 01 00:00:00\n"); + } } } diff --git a/libretro-common/vfs/vfs_implementation_cdrom.c b/libretro-common/vfs/vfs_implementation_cdrom.c index 531716b519..3cea268800 100644 --- a/libretro-common/vfs/vfs_implementation_cdrom.c +++ b/libretro-common/vfs/vfs_implementation_cdrom.c @@ -87,11 +87,12 @@ int64_t retro_vfs_file_seek_cdrom(libretro_vfs_implementation_file *stream, int6 } case SEEK_END: { - ssize_t end_lba = (vfs_cdrom_toc.track[vfs_cdrom_toc.num_tracks - 1].lba_start + vfs_cdrom_toc.track[vfs_cdrom_toc.num_tracks - 1].track_size) - 1; + ssize_t pregap_lba_len = (vfs_cdrom_toc.track[stream->cdrom.cur_track - 1].audio ? 0 : (vfs_cdrom_toc.track[stream->cdrom.cur_track - 1].lba - vfs_cdrom_toc.track[stream->cdrom.cur_track - 1].lba_start)); + ssize_t lba_len = vfs_cdrom_toc.track[stream->cdrom.cur_track - 1].track_size - pregap_lba_len; - lba_to_msf(end_lba + lba, &min, &sec, &frame); + lba_to_msf(lba_len + lba, &min, &sec, &frame); - stream->cdrom.byte_pos = end_lba * 2352; + stream->cdrom.byte_pos = lba_len * 2352; seek_type = "SEEK_END"; break; @@ -112,7 +113,7 @@ int64_t retro_vfs_file_seek_cdrom(libretro_vfs_implementation_file *stream, int6 stream->cdrom.cur_lba = msf_to_lba(min, sec, frame); #ifdef CDROM_DEBUG - printf("CDROM Seek %s: Path %s Offset %" PRIu64 " is now at %" PRIu64 " (MSF %02d:%02d:%02d) (LBA %u)...\n", seek_type, stream->orig_path, offset, stream->cdrom.byte_pos, stream->cdrom.cur_min, stream->cdrom.cur_sec, stream->cdrom.cur_frame, stream->cdrom.cur_lba); + printf("CDROM Seek %s: Path %s Offset %" PRIu64 " is now at %" PRIu64 " (MSF %02u:%02u:%02u) (LBA %u)...\n", seek_type, stream->orig_path, offset, stream->cdrom.byte_pos, (unsigned)stream->cdrom.cur_min, (unsigned)stream->cdrom.cur_sec, (unsigned)stream->cdrom.cur_frame, stream->cdrom.cur_lba); fflush(stdout); #endif } @@ -388,7 +389,7 @@ int64_t retro_vfs_file_read_cdrom(libretro_vfs_implementation_file *stream, lba_to_msf(stream->cdrom.cur_lba, &min, &sec, &frame); #ifdef CDROM_DEBUG - printf("CDROM Read: Reading %" PRIu64 " bytes from %s starting at byte offset %" PRIu64 " (MSF %02d:%02d:%02d) (LBA %u) skip %" PRIu64 "...\n", len, stream->orig_path, stream->cdrom.byte_pos, min, sec, frame, stream->cdrom.cur_lba, skip); + printf("CDROM Read: Reading %" PRIu64 " bytes from %s starting at byte offset %" PRIu64 " (MSF %02u:%02u:%02u) (LBA %u) skip %" PRIu64 "...\n", len, stream->orig_path, stream->cdrom.byte_pos, (unsigned)min, (unsigned)sec, (unsigned)frame, stream->cdrom.cur_lba, skip); fflush(stdout); #endif @@ -408,7 +409,7 @@ int64_t retro_vfs_file_read_cdrom(libretro_vfs_implementation_file *stream, lba_to_msf(stream->cdrom.cur_lba, &stream->cdrom.cur_min, &stream->cdrom.cur_sec, &stream->cdrom.cur_frame); #ifdef CDROM_DEBUG - printf("CDROM read %" PRIu64 " bytes, position is now: %" PRIu64 " (MSF %02d:%02d:%02d) (LBA %u)\n", len, stream->cdrom.byte_pos, stream->cdrom.cur_min, stream->cdrom.cur_sec, stream->cdrom.cur_frame, msf_to_lba(stream->cdrom.cur_min, stream->cdrom.cur_sec, stream->cdrom.cur_frame)); + printf("CDROM read %" PRIu64 " bytes, position is now: %" PRIu64 " (MSF %02u:%02u:%02u) (LBA %u)\n", len, stream->cdrom.byte_pos, (unsigned)stream->cdrom.cur_min, (unsigned)stream->cdrom.cur_sec, (unsigned)stream->cdrom.cur_frame, msf_to_lba(stream->cdrom.cur_min, stream->cdrom.cur_sec, stream->cdrom.cur_frame)); fflush(stdout); #endif