cdrom: add flush for debug prints because they were never appearing, remove unused variables

This commit is contained in:
Brad Parker 2019-06-28 18:14:04 -04:00
parent 11106cc2a7
commit 12388e038a
3 changed files with 52 additions and 18 deletions

View File

@ -199,6 +199,7 @@ static int cdrom_send_command(libretro_vfs_implementation_file *stream, CDROM_CM
}
printf("\n");
fflush(stdout);
}
#endif
@ -230,6 +231,7 @@ retry:
{
#ifdef CDROM_DEBUG
printf("CDROM Read Retry...\n");
fflush(stdout);
#endif
retries_left--;
usleep(1000 * 1000);
@ -240,6 +242,7 @@ retry:
rv = 1;
#ifdef CDROM_DEBUG
printf("CDROM Read Retries failed, giving up.\n");
fflush(stdout);
#endif
}
@ -313,6 +316,8 @@ retry:
printf("ASC: %02X\n", sense[12]);
printf("ASCQ: %02X\n", sense[13]);
fflush(stdout);
rv = 1;
#endif
}
@ -390,6 +395,8 @@ int cdrom_read_subq(libretro_vfs_implementation_file *stream, unsigned char *buf
printf("\n");
}
fflush(stdout);
#endif
return 0;
}
@ -422,6 +429,7 @@ static int cdrom_read_track_info(libretro_vfs_implementation_file *stream, unsig
printf("Data Mode: %d ", buf[6] & 0xF);
printf("LBA Start: %d ", lba);
printf("Track Size: %d\n", track_size);
fflush(stdout);
#endif
return 0;
@ -440,6 +448,7 @@ int cdrom_write_cue(libretro_vfs_implementation_file *stream, char **out_buf, si
{
#ifdef CDROM_DEBUG
printf("Invalid buffer/length pointer for CDROM cue sheet\n");
fflush(stdout);
#endif
return 1;
}
@ -463,6 +472,7 @@ int cdrom_write_cue(libretro_vfs_implementation_file *stream, char **out_buf, si
*num_tracks = pmin;
#ifdef CDROM_DEBUG
printf("Number of CDROM tracks: %d\n", *num_tracks);
fflush(stdout);
#endif
break;
}
@ -472,6 +482,7 @@ int cdrom_write_cue(libretro_vfs_implementation_file *stream, char **out_buf, si
{
#ifdef CDROM_DEBUG
printf("Invalid number of CDROM tracks: %d\n", *num_tracks);
fflush(stdout);
#endif
return 1;
}
@ -497,9 +508,6 @@ int cdrom_write_cue(libretro_vfs_implementation_file *stream, char **out_buf, si
if (/*(control == 4 || control == 6) && */adr == 1 && tno == 0 && point >= 1 && point <= 99)
{
unsigned char next_pmin = (pframe == 74) ? (psec < 59 ? pmin : pmin + 1) : pmin;
unsigned char next_psec = (pframe == 74) ? (psec < 59 ? (psec + 1) : 0) : psec;
unsigned char next_pframe = (pframe < 74) ? (pframe + 1) : 0;
unsigned char mode = 1;
bool audio = false;
const char *track_type = "MODE1/2352";
@ -509,6 +517,7 @@ int cdrom_write_cue(libretro_vfs_implementation_file *stream, char **out_buf, si
#ifdef CDROM_DEBUG
printf("Track %02d CONTROL %01X ADR %01X MODE %d AUDIO? %d\n", point, control, adr, mode, audio);
fflush(stdout);
#endif
toc->track[point - 1].track_num = point;
@ -586,6 +595,7 @@ int cdrom_read(libretro_vfs_implementation_file *stream, unsigned char min, unsi
#ifdef CDROM_DEBUG
printf("single-frame read: from %d %d %d to %d %d %d skip %" PRId64 "\n", cdb[3], cdb[4], cdb[5], cdb[6], cdb[7], cdb[8], skip);
fflush(stdout);
#endif
}
else
@ -596,6 +606,7 @@ int cdrom_read(libretro_vfs_implementation_file *stream, unsigned char min, unsi
#ifdef CDROM_DEBUG
printf("multi-frame read: from %d %d %d to %d %d %d skip %" PRId64 "\n", cdb[3], cdb[4], cdb[5], cdb[6], cdb[7], cdb[8], skip);
fflush(stdout);
#endif
}
@ -603,6 +614,7 @@ int cdrom_read(libretro_vfs_implementation_file *stream, unsigned char min, unsi
#ifdef CDROM_DEBUG
printf("read status code %d\n", rv);
fflush(stdout);
#endif
if (rv)

View File

@ -420,11 +420,14 @@ libretro_vfs_implementation_file *retro_vfs_file_open_impl(
}
else
#endif
{
fp = (FILE*)fopen_utf8(path, mode_str);
if (!fp)
goto error;
if (!fp)
goto error;
stream->fp = fp;
}
/* Regarding setvbuf:
*
* https://www.freebsd.org/cgi/man.cgi?query=setvbuf&apropos=0&sektion=0&manpath=FreeBSD+11.1-RELEASE&arch=default&format=html
@ -435,10 +438,10 @@ libretro_vfs_implementation_file *retro_vfs_file_open_impl(
* Since C89 does not support specifying a null buffer with a non-zero size, we create and track our own buffer for it.
*/
/* TODO: this is only useful for a few platforms, find which and add ifdef */
stream->fp = fp;
#if !defined(PS2) && !defined(PSP)
stream->buf = (char*)calloc(1, 0x4000);
setvbuf(stream->fp, stream->buf, _IOFBF, 0x4000);
if (stream->fp)
setvbuf(stream->fp, stream->buf, _IOFBF, 0x4000);
#endif
#endif
}
@ -506,15 +509,18 @@ int retro_vfs_file_close_impl(libretro_vfs_implementation_file *stream)
if (!stream)
return -1;
#ifdef HAVE_CDROM
if (stream->scheme == VFS_SCHEME_CDROM)
{
retro_vfs_file_close_cdrom(stream);
goto end;
}
#endif
if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0)
{
if (stream->fp)
{
#ifdef HAVE_CDROM
if (stream->scheme == VFS_SCHEME_CDROM)
retro_vfs_file_close_cdrom(stream);
else
#endif
fclose(stream->fp);
}
}
@ -535,6 +541,7 @@ int retro_vfs_file_close_impl(libretro_vfs_implementation_file *stream)
close(stream->fd);
#endif
}
end:
if (stream->buf)
free(stream->buf);

View File

@ -52,6 +52,7 @@ int64_t retro_vfs_file_seek_cdrom(libretro_vfs_implementation_file *stream, int6
#ifdef CDROM_DEBUG
printf("CDROM Seek: Path %s Offset %" PRIu64 " is now at %" PRIu64 "\n", stream->orig_path, offset, stream->cdrom_byte_pos);
fflush(stdout);
#endif
}
else if (string_is_equal_noncase(ext, "bin"))
@ -98,8 +99,6 @@ int64_t retro_vfs_file_seek_cdrom(libretro_vfs_implementation_file *stream, int6
case SEEK_SET:
default:
{
unsigned lba = msf_to_lba(min, sec, frame);
seek_type = "SEEK_SET";
stream->cdrom_byte_pos = offset;
@ -113,6 +112,7 @@ int64_t retro_vfs_file_seek_cdrom(libretro_vfs_implementation_file *stream, int6
#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, vfs_cdrom_toc.cur_min, vfs_cdrom_toc.cur_sec, vfs_cdrom_toc.cur_frame, msf_to_lba(vfs_cdrom_toc.cur_min, vfs_cdrom_toc.cur_sec, vfs_cdrom_toc.cur_frame));
fflush(stdout);
#endif
}
else
@ -148,6 +148,7 @@ void retro_vfs_file_open_cdrom(
#ifdef CDROM_DEBUG
printf("CDROM Open: Path %s URI %s\n", cdrom_path, path);
fflush(stdout);
#endif
stream->fp = (FILE*)fopen_utf8(cdrom_path, "r+b");
@ -155,10 +156,9 @@ void retro_vfs_file_open_cdrom(
{
if (!cdrom_get_inquiry(stream, model, sizeof(model)))
{
size_t len = 0;
#ifdef CDROM_DEBUG
printf("CDROM Model: %s\n", model);
fflush(stdout);
#endif
}
}
@ -184,7 +184,10 @@ void retro_vfs_file_open_cdrom(
#ifdef CDROM_DEBUG
if (string_is_empty(stream->cdrom_cue_buf))
{
printf("Error writing cue sheet.\n");
fflush(stdout);
}
else
{
printf("CDROM CUE Sheet:\n%s\n", stream->cdrom_cue_buf);
@ -216,6 +219,7 @@ void retro_vfs_file_open_cdrom(
#ifdef CDROM_DEBUG
printf("CDROM Open: Path %s URI %s\n", cdrom_path, path);
fflush(stdout);
#endif
stream->fh = CreateFile(cdrom_path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
@ -229,6 +233,7 @@ void retro_vfs_file_open_cdrom(
#ifdef CDROM_DEBUG
printf("CDROM Model: %s\n", model);
fflush(stdout);
#endif
}
}
@ -252,7 +257,10 @@ void retro_vfs_file_open_cdrom(
#ifdef CDROM_DEBUG
if (string_is_empty(stream->cdrom_cue_buf))
{
printf("Error writing cue sheet.\n");
fflush(stdout);
}
else
{
printf("CDROM CUE Sheet:\n%s\n", stream->cdrom_cue_buf);
@ -266,8 +274,8 @@ void retro_vfs_file_open_cdrom(
int retro_vfs_file_close_cdrom(libretro_vfs_implementation_file *stream)
{
#ifdef CDROM_DEBUG
if (stream->scheme == VFS_SCHEME_CDROM)
printf("CDROM Close: Path %s\n", stream->orig_path);
printf("CDROM Close: Path %s\n", stream->orig_path);
fflush(stdout);
#endif
#ifdef _WIN32
@ -292,6 +300,7 @@ int64_t retro_vfs_file_tell_cdrom(libretro_vfs_implementation_file *stream)
{
#ifdef CDROM_DEBUG
printf("CDROM (cue) Tell: Path %s Position %" PRIu64 "\n", stream->orig_path, stream->cdrom_byte_pos);
fflush(stdout);
#endif
return stream->cdrom_byte_pos;
}
@ -301,6 +310,7 @@ int64_t retro_vfs_file_tell_cdrom(libretro_vfs_implementation_file *stream)
#ifdef CDROM_DEBUG
printf("CDROM (bin) Tell: Path %s Position %u\n", stream->orig_path, lba * 2352);
fflush(stdout);
#endif
return lba * 2352;
}
@ -320,6 +330,7 @@ int64_t retro_vfs_file_read_cdrom(libretro_vfs_implementation_file *stream,
{
#ifdef CDROM_DEBUG
printf("CDROM Read: Reading %" PRIu64 " bytes from cuesheet starting at %" PRIu64 "...\n", len, stream->cdrom_byte_pos);
fflush(stdout);
#endif
memcpy(s, stream->cdrom_cue_buf + stream->cdrom_byte_pos, len);
stream->cdrom_byte_pos += len;
@ -330,6 +341,7 @@ int64_t retro_vfs_file_read_cdrom(libretro_vfs_implementation_file *stream,
{
#ifdef CDROM_DEBUG
printf("CDROM Read: Reading %" PRIu64 " bytes from cuesheet starting at %" PRIu64 " failed.\n", len, stream->cdrom_byte_pos);
fflush(stdout);
#endif
return 0;
}
@ -353,6 +365,7 @@ int64_t retro_vfs_file_read_cdrom(libretro_vfs_implementation_file *stream,
#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, msf_to_lba(min, sec, frame), skip);
fflush(stdout);
#endif
rv = cdrom_read(stream, min, sec, frame, s, (size_t)len, skip);
@ -361,6 +374,7 @@ int64_t retro_vfs_file_read_cdrom(libretro_vfs_implementation_file *stream,
{
#ifdef CDROM_DEBUG
printf("Failed to read %" PRIu64 " bytes from CD.\n", len);
fflush(stdout);
#endif
return 0;
}
@ -374,6 +388,7 @@ int64_t retro_vfs_file_read_cdrom(libretro_vfs_implementation_file *stream,
#ifdef CDROM_DEBUG
printf("CDROM read %" PRIu64 " bytes, position is now: %" PRIu64 " (MSF %02d:%02d:%02d) (LBA %u)\n", len, stream->cdrom_byte_pos, vfs_cdrom_toc.cur_min, vfs_cdrom_toc.cur_sec, vfs_cdrom_toc.cur_frame, msf_to_lba(vfs_cdrom_toc.cur_min, vfs_cdrom_toc.cur_sec, vfs_cdrom_toc.cur_frame));
fflush(stdout);
#endif
return len;