diff --git a/libretro-common/cdrom/cdrom.c b/libretro-common/cdrom/cdrom.c index ac409e4ba2..fd11449bbe 100644 --- a/libretro-common/cdrom/cdrom.c +++ b/libretro-common/cdrom/cdrom.c @@ -277,7 +277,7 @@ static int cdrom_send_command_win32(HANDLE fh, CDROM_CMD_Direction dir, void *bu break; } - sptd.s.TimeOutValue = 30; + sptd.s.TimeOutValue = 5; sptd.s.DataBuffer = buf; sptd.s.DataTransferLength = len; sptd.s.SenseInfoLength = sizeof(sptd.sense); @@ -322,7 +322,7 @@ static int cdrom_send_command_linux(int fd, CDROM_CMD_Direction dir, void *buf, sgio.dxfer_len = len; sgio.sbp = sense; sgio.mx_sb_len = sense_len; - sgio.timeout = 30000; + sgio.timeout = 5000; rv = ioctl(fd, SG_IO, &sgio); @@ -1357,3 +1357,77 @@ bool cdrom_is_media_inserted(const libretro_vfs_implementation_file *stream) return true; } +bool cdrom_set_read_cache(const libretro_vfs_implementation_file *stream, bool enabled) +{ + /* MMC Command: MODE SENSE (10) and MODE SELECT (10) */ + unsigned char cdb_sense_changeable[] = {0x5A, 0, 0x48, 0, 0, 0, 0, 0, 0x14, 0}; + unsigned char cdb_sense[] = {0x5A, 0, 0x8, 0, 0, 0, 0, 0, 0x14, 0}; + unsigned char cdb_select[] = {0x55, 0x10, 0, 0, 0, 0, 0, 0, 0x14, 0}; + unsigned char buf[20] = {0}; + int rv, i; + + rv = cdrom_send_command(stream, DIRECTION_IN, buf, sizeof(buf), cdb_sense_changeable, sizeof(cdb_sense_changeable), 0); + +#ifdef CDROM_DEBUG + printf("mode sense changeable status code %d\n", rv); + fflush(stdout); +#endif + + if (rv) + return false; + + if (!(buf[10] & 0x1)) + { + /* RCD (read cache disable) bit is not changeable */ +#ifdef CDROM_DEBUG + printf("RCD (read cache disable) bit is not changeable.\n"); + fflush(stdout); +#endif + return false; + } + + memset(buf, 0, sizeof(buf)); + + rv = cdrom_send_command(stream, DIRECTION_IN, buf, sizeof(buf), cdb_sense, sizeof(cdb_sense), 0); + +#ifdef CDROM_DEBUG + printf("mode sense status code %d\n", rv); + fflush(stdout); +#endif + + if (rv) + return false; + +#ifdef CDROM_DEBUG + printf("Mode sense data for caching mode page: "); + + for (i = 0; i < sizeof(buf); i++) + { + printf("%02X ", buf[i]); + } + + printf("\n"); + fflush(stdout); +#endif + + /* "When transferred during execution of the MODE SELECT (10) command, Mode Data Length is reserved." */ + for (i = 0; i < 8; i++) + buf[i] = 0; + + if (enabled) + buf[10] &= ~1; + else + buf[10] |= 1; + + rv = cdrom_send_command(stream, DIRECTION_OUT, buf, sizeof(buf), cdb_select, sizeof(cdb_select), 0); + +#ifdef CDROM_DEBUG + printf("mode select status code %d\n", rv); + fflush(stdout); +#endif + + if (rv) + return false; + + return true; +} diff --git a/libretro-common/include/cdrom/cdrom.h b/libretro-common/include/cdrom/cdrom.h index 528fc66dd9..3e5e3ee7f7 100644 --- a/libretro-common/include/cdrom/cdrom.h +++ b/libretro-common/include/cdrom/cdrom.h @@ -28,18 +28,13 @@ #include #include +#include #include #include #include #include -#ifdef VFS_FRONTEND -typedef struct retro_vfs_file_handle libretro_vfs_implementation_file; -#else -typedef struct libretro_vfs_implementation_file libretro_vfs_implementation_file; -#endif - struct string_list; RETRO_BEGIN_DECLS @@ -108,6 +103,8 @@ void cdrom_get_current_config_random_readable(const libretro_vfs_implementation_ int cdrom_get_sense(const libretro_vfs_implementation_file *stream, unsigned char *sense, size_t len); +bool cdrom_set_read_cache(const libretro_vfs_implementation_file *stream, bool enabled); + RETRO_END_DECLS #endif diff --git a/libretro-common/include/vfs/vfs.h b/libretro-common/include/vfs/vfs.h new file mode 100644 index 0000000000..0b9066d753 --- /dev/null +++ b/libretro-common/include/vfs/vfs.h @@ -0,0 +1,97 @@ +/* Copyright (C) 2010-2019 The RetroArch team +* +* --------------------------------------------------------------------------------------- +* The following license statement only applies to this file (vfs_implementation.h). +* --------------------------------------------------------------------------------------- +* +* Permission is hereby granted, free of charge, +* to any person obtaining a copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation the rights to +* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, +* and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef __LIBRETRO_SDK_VFS_H +#define __LIBRETRO_SDK_VFS_H + +#include + +RETRO_BEGIN_DECLS + +#ifdef HAVE_CDROM +typedef struct +{ + char *cue_buf; + size_t cue_len; + int64_t byte_pos; + char drive; + unsigned char cur_min; + unsigned char cur_sec; + unsigned char cur_frame; + unsigned char cur_track; + unsigned cur_lba; +} vfs_cdrom_t; +#endif + +enum vfs_scheme +{ + VFS_SCHEME_NONE = 0, + VFS_SCHEME_CDROM +}; + +#ifndef __WINRT__ +#ifdef VFS_FRONTEND +struct retro_vfs_file_handle +#else +struct libretro_vfs_implementation_file +#endif +{ + int fd; + unsigned hints; + int64_t size; + char *buf; + FILE *fp; +#ifdef _WIN32 + HANDLE fh; +#endif + char* orig_path; + uint64_t mappos; + uint64_t mapsize; + uint8_t *mapped; + enum vfs_scheme scheme; +#ifdef HAVE_CDROM + vfs_cdrom_t cdrom; +#endif +}; +#endif + +/* Replace the following symbol with something appropriate + * to signify the file is being compiled for a front end instead of a core. + * This allows the same code to act as reference implementation + * for VFS and as fallbacks for when the front end does not provide VFS functionality. + */ + +#ifdef VFS_FRONTEND +typedef struct retro_vfs_file_handle libretro_vfs_implementation_file; +#else +typedef struct libretro_vfs_implementation_file libretro_vfs_implementation_file; +#endif + +#ifdef VFS_FRONTEND +typedef struct retro_vfs_dir_handle libretro_vfs_implementation_dir; +#else +typedef struct libretro_vfs_implementation_dir libretro_vfs_implementation_dir; +#endif + +RETRO_END_DECLS + +#endif diff --git a/libretro-common/include/vfs/vfs_implementation.h b/libretro-common/include/vfs/vfs_implementation.h index 6ba84e3c0c..035d70108f 100644 --- a/libretro-common/include/vfs/vfs_implementation.h +++ b/libretro-common/include/vfs/vfs_implementation.h @@ -27,6 +27,7 @@ #include #include #include +#include #ifdef HAVE_CDROM #include @@ -36,56 +37,6 @@ typedef void* HANDLE; #endif -enum vfs_scheme -{ - VFS_SCHEME_NONE = 0, - VFS_SCHEME_CDROM -}; - -#ifndef __WINRT__ -#ifdef VFS_FRONTEND -struct retro_vfs_file_handle -#else -struct libretro_vfs_implementation_file -#endif -{ - int fd; - unsigned hints; - int64_t size; - char *buf; - FILE *fp; -#ifdef _WIN32 - HANDLE fh; -#endif - char* orig_path; - uint64_t mappos; - uint64_t mapsize; - uint8_t *mapped; - enum vfs_scheme scheme; -#ifdef HAVE_CDROM - vfs_cdrom_t cdrom; -#endif -}; -#endif - -/* Replace the following symbol with something appropriate - * to signify the file is being compiled for a front end instead of a core. - * This allows the same code to act as reference implementation - * for VFS and as fallbacks for when the front end does not provide VFS functionality. - */ - -#ifdef VFS_FRONTEND -typedef struct retro_vfs_file_handle libretro_vfs_implementation_file; -#else -typedef struct libretro_vfs_implementation_file libretro_vfs_implementation_file; -#endif - -#ifdef VFS_FRONTEND -typedef struct retro_vfs_dir_handle libretro_vfs_implementation_dir; -#else -typedef struct libretro_vfs_implementation_dir libretro_vfs_implementation_dir; -#endif - #ifdef __cplusplus extern "C" { #endif diff --git a/libretro-common/include/vfs/vfs_implementation_cdrom.h b/libretro-common/include/vfs/vfs_implementation_cdrom.h index 9a91f26d33..285896127e 100644 --- a/libretro-common/include/vfs/vfs_implementation_cdrom.h +++ b/libretro-common/include/vfs/vfs_implementation_cdrom.h @@ -23,31 +23,13 @@ #ifndef __LIBRETRO_SDK_VFS_IMPLEMENTATION_CDROM_H #define __LIBRETRO_SDK_VFS_IMPLEMENTATION_CDROM_H +#include #include RETRO_BEGIN_DECLS typedef struct RFILE RFILE; -typedef struct -{ - char *cue_buf; - size_t cue_len; - int64_t byte_pos; - char drive; - unsigned char cur_min; - unsigned char cur_sec; - unsigned char cur_frame; - unsigned char cur_track; - unsigned cur_lba; -} vfs_cdrom_t; - -#ifdef VFS_FRONTEND -struct retro_vfs_file_handle; -#else -struct libretro_vfs_implementation_file; -#endif - int64_t retro_vfs_file_seek_cdrom(libretro_vfs_implementation_file *stream, int64_t offset, int whence); void retro_vfs_file_open_cdrom( diff --git a/libretro-common/vfs/vfs_implementation_uwp.cpp b/libretro-common/vfs/vfs_implementation_uwp.cpp index ef685fcd16..6ed1da1cc8 100644 --- a/libretro-common/vfs/vfs_implementation_uwp.cpp +++ b/libretro-common/vfs/vfs_implementation_uwp.cpp @@ -42,6 +42,7 @@ using namespace Windows::Storage::FileProperties; #endif #endif +#include #include #include #include