diff --git a/Externals/libretro-common/include/boolean.h b/Externals/libretro-common/include/boolean.h new file mode 100644 index 0000000000..9d0d7c129e --- /dev/null +++ b/Externals/libretro-common/include/boolean.h @@ -0,0 +1,39 @@ +/* Copyright (C) 2010-2020 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (boolean.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_BOOLEAN_H +#define __LIBRETRO_SDK_BOOLEAN_H + +#ifndef __cplusplus + +#if defined(_MSC_VER) && _MSC_VER < 1800 && !defined(SN_TARGET_PS3) +/* Hack applied for MSVC when compiling in C89 mode as it isn't C99 compliant. */ +#define bool unsigned char +#define true 1 +#define false 0 +#else +#include +#endif + +#endif + +#endif diff --git a/Externals/Libretro/Include/libretro.h b/Externals/libretro-common/include/libretro.h similarity index 98% rename from Externals/Libretro/Include/libretro.h rename to Externals/libretro-common/include/libretro.h index 32b732e6d2..b0948cdeb8 100644 --- a/Externals/Libretro/Include/libretro.h +++ b/Externals/libretro-common/include/libretro.h @@ -485,6 +485,7 @@ enum retro_language RETRO_LANGUAGE_GALICIAN = 33, RETRO_LANGUAGE_NORWEGIAN = 34, RETRO_LANGUAGE_IRISH = 35, + RETRO_LANGUAGE_THAI = 36, RETRO_LANGUAGE_LAST, /** Defined to ensure that sizeof(retro_language) == sizeof(int). Do not use. */ @@ -519,6 +520,9 @@ enum retro_language /* Video ram lets a frontend peek into a game systems video RAM (VRAM). */ #define RETRO_MEMORY_VIDEO_RAM 3 +/* ROM lets a frontend peek into a game systems ROM. */ +#define RETRO_MEMORY_ROM 4 + /** @} */ /* Keysyms used for ID in input state callback when polling RETRO_KEYBOARD. */ @@ -2587,6 +2591,71 @@ enum retro_mod */ #define RETRO_ENVIRONMENT_GET_TARGET_SAMPLE_RATE (81 | RETRO_ENVIRONMENT_EXPERIMENTAL) +/** + * Returns the local player's netplay client index when using frontend-managed + * multiplayer/rollback netplay. + * + * @param[out] data unsigned *. + * Pointer to an unsigned integer where the frontend stores the local client index. + * 0 indicates host. Values > 0 indicate connected clients. + * @return \\c true if the environment call is available and value was written, + * \\c false otherwise. +*/ +#define RETRO_ENVIRONMENT_GET_NETPLAY_CLIENT_INDEX (82 | RETRO_ENVIRONMENT_EXPERIMENTAL) + +/** + * Allocates a region of executable memory, optionally dual-mapped. + * + * The frontend allocates memory suitable for JIT code generation and returns + * it to the core. The returned mode tells the core how to use the memory: + * + * - \c RETRO_EXEC_MEM_MODE_UNRESTRICTED: The platform has no restrictions + * on executable memory. The core should self-allocate. Do not call + * this environment with a non-zero size in this mode. + * - \c RETRO_EXEC_MEM_MODE_RWX: Single mapping, read-write-execute. + * \c rx and \c rw point to the same region. + * - \c RETRO_EXEC_MEM_MODE_WX_TOGGLE: Single mapping, write XOR execute. + * \c rx and \c rw point to the same region; the core must toggle + * protections itself (e.g. mprotect) before writing or executing. + * - \c RETRO_EXEC_MEM_MODE_DUAL_MAP: Separate read-execute and read-write + * mappings of the same physical pages. The core writes through \c rw + * and executes from \c rx. + * + * Returned memory is page-aligned. The frontend tracks all allocations + * and frees any outstanding ones when the core is unloaded. + * + * The core sets \c version and \c size before calling. The frontend fills + * in \c mode, \c rx, and \c rw on success. + * + * If \c size is 0, this is a probe: the frontend returns \c true and sets + * \c mode to indicate what kind of memory it would provide, but does not + * allocate. \c rx and \c rw will be NULL. Cores can use this to decide + * whether to take a JIT code path before committing to an allocation. + * + * @param[in,out] data struct retro_exec_mem_alloc *. + * @return \c true if the allocation succeeded, \c false otherwise. + * If the frontend does not support this call, returns \c false + * and the core should fall back to managing its own executable memory. + * @see retro_exec_mem_alloc + * @see RETRO_ENVIRONMENT_EXEC_MEM_FREE + */ +#define RETRO_ENVIRONMENT_EXEC_MEM_ALLOC 83 + +/** + * Frees a region of executable memory previously allocated with + * \c RETRO_ENVIRONMENT_EXEC_MEM_ALLOC. + * + * This is optional; the frontend will free all outstanding allocations + * when the core is unloaded. Cores that never need to release memory + * mid-session need not call this. + * + * @param[in] data struct retro_exec_mem_free *. + * @return \c true if the memory was freed, \c false otherwise. + * @see retro_exec_mem_free + * @see RETRO_ENVIRONMENT_EXEC_MEM_ALLOC + */ +#define RETRO_ENVIRONMENT_EXEC_MEM_FREE 84 + /**@}*/ /** @@ -2920,6 +2989,19 @@ typedef int (RETRO_CALLCONV *retro_vfs_rename_t)(const char *old_path, const cha */ typedef int (RETRO_CALLCONV *retro_vfs_stat_t)(const char *path, int32_t *size); +/** + * Gets information about the given file (64-bit size). + * + * @param path The path to the file to query. + * @param[out] size The reported size of the file in bytes. + * May be \c NULL, in which case this value is ignored. + * @return A bitmask of \c RETRO_VFS_STAT flags, + * or 0 if \c path doesn't refer to a valid file. + * @see RETRO_VFS_STAT + * @since VFS API v4 + */ +typedef int (RETRO_CALLCONV *retro_vfs_stat_64_t)(const char *path, int64_t *size); + /** * Creates a directory at the given path. * @@ -3075,6 +3157,10 @@ struct retro_vfs_interface /** @copydoc retro_vfs_closedir_t */ retro_vfs_closedir_t closedir; + + /* VFS API v4 */ + /** @copydoc retro_vfs_stat_64_t */ + retro_vfs_stat_64_t stat_64; }; /** @@ -4215,6 +4301,9 @@ struct retro_log_callback /** Indicates CPU support for the ASIMD instruction set. */ #define RETRO_SIMD_ASIMD (1 << 21) +/** Indicates CPU support for the AVX512 instruction set. */ +#define RETRO_SIMD_AVX512 (1 << 22) + /** @} */ /** @@ -4476,15 +4565,18 @@ enum retro_sensor_action /* Id values for SENSOR types. */ /** - * Returns the device's acceleration along its local X axis minus the effect of gravity, in m/s^2. + * Returns the device's acceleration along its local X axis, in g (standard gravity, 9.80665 m/s^2). + * Includes the effect of gravity; + * a device at rest on a table will have values close to 0, 0, 1. * - * Positive values mean that the device is accelerating to the right. + * Positive values mean that the device is accelerating to the right, * assuming the user is looking at it head-on. */ #define RETRO_SENSOR_ACCELEROMETER_X 0 /** - * Returns the device's acceleration along its local Y axis minus the effect of gravity, in m/s^2. + * Returns the device's acceleration along its local Y axis, in g (standard gravity, 9.80665 m/s^2). + * Includes the effect of gravity. * * Positive values mean that the device is accelerating upwards, * assuming the user is looking at it head-on. @@ -4492,7 +4584,8 @@ enum retro_sensor_action #define RETRO_SENSOR_ACCELEROMETER_Y 1 /** - * Returns the the device's acceleration along its local Z axis minus the effect of gravity, in m/s^2. + * Returns the device's acceleration along its local Z axis, in g (standard gravity, 9.80665 m/s^2). + * Includes the effect of gravity. * * Positive values indicate forward acceleration towards the user, * assuming the user is looking at the device head-on. @@ -7395,6 +7488,45 @@ struct retro_device_power /** @} */ +/** @defgroup Executable Memory Modes + * Describes how the frontend provisions executable memory. + * @{ + */ + +#define RETRO_EXEC_MEM_MODE_UNAVAILABLE 0 /**< No executable memory available */ +#define RETRO_EXEC_MEM_MODE_UNRESTRICTED 1 /**< No restrictions; core should self-allocate */ +#define RETRO_EXEC_MEM_MODE_RWX 2 /**< Single mapping, read-write-execute */ +#define RETRO_EXEC_MEM_MODE_WX_TOGGLE 3 /**< Single mapping, write XOR execute (core toggles) */ +#define RETRO_EXEC_MEM_MODE_DUAL_MAP 4 /**< Separate R-X and R-W mappings of same pages */ + +/** + * Parameters for \c RETRO_ENVIRONMENT_EXEC_MEM_ALLOC. + * + * The core fills in \c version and \c size before calling. + * The frontend fills in \c mode, \c rx, and \c rw on success. + * @see RETRO_ENVIRONMENT_EXEC_MEM_ALLOC + */ +struct retro_exec_mem_alloc +{ + unsigned version; /**< Set by core (currently 1). */ + size_t size; /**< Set by core: requested bytes. */ + unsigned mode; /**< Set by frontend: one of \c RETRO_EXEC_MEM_MODE_*. */ + void *rx; /**< Set by frontend: execute from this pointer. */ + void *rw; /**< Set by frontend: write through this pointer. + Equal to \c rx when mode is RWX or WX_TOGGLE. */ +}; + +/** + * Parameters for \c RETRO_ENVIRONMENT_EXEC_MEM_FREE. + * @see RETRO_ENVIRONMENT_EXEC_MEM_FREE + */ +struct retro_exec_mem_free +{ + void *rx; /**< The \c rx pointer returned by a previous alloc call. */ +}; + +/** @} */ + /** * @defgroup Callbacks * @{ diff --git a/Externals/Libretro/Include/libretro_d3d.h b/Externals/libretro-common/include/libretro_d3d.h similarity index 100% rename from Externals/Libretro/Include/libretro_d3d.h rename to Externals/libretro-common/include/libretro_d3d.h diff --git a/Externals/Libretro/Include/libretro_d3d11.h b/Externals/libretro-common/include/libretro_d3d11.h similarity index 100% rename from Externals/Libretro/Include/libretro_d3d11.h rename to Externals/libretro-common/include/libretro_d3d11.h diff --git a/Externals/Libretro/Include/libretro_d3d12.h b/Externals/libretro-common/include/libretro_d3d12.h similarity index 100% rename from Externals/Libretro/Include/libretro_d3d12.h rename to Externals/libretro-common/include/libretro_d3d12.h diff --git a/Externals/Libretro/Include/libretro_vulkan.h b/Externals/libretro-common/include/libretro_vulkan.h similarity index 100% rename from Externals/Libretro/Include/libretro_vulkan.h rename to Externals/libretro-common/include/libretro_vulkan.h diff --git a/Externals/libretro-common/include/retro_common_api.h b/Externals/libretro-common/include/retro_common_api.h new file mode 100644 index 0000000000..a8b79e4310 --- /dev/null +++ b/Externals/libretro-common/include/retro_common_api.h @@ -0,0 +1,148 @@ +/* Copyright (C) 2010-2020 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (retro_common_api.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_COMMON_RETRO_COMMON_API_H +#define _LIBRETRO_COMMON_RETRO_COMMON_API_H + +/* +This file is designed to normalize the libretro-common compiling environment +for public API headers. This should be leaner than a normal compiling environment, +since it gets #included into other project's sources. +*/ + +/* ------------------------------------ */ + +/* +Ordinarily we want to put #ifdef __cplusplus extern "C" in C library +headers to enable them to get used by c++ sources. +However, we want to support building this library as C++ as well, so a +special technique is called for. +*/ + +#define RETRO_BEGIN_DECLS +#define RETRO_END_DECLS +#define RETRO_BEGIN_DECLS_CXX +#define RETRO_END_DECLS_CXX + +#ifdef __cplusplus + +#ifdef CXX_BUILD +/* build wants everything to be built as c++, so no extern "C" */ +#else +#undef RETRO_BEGIN_DECLS +#undef RETRO_END_DECLS +#define RETRO_BEGIN_DECLS extern "C" { +#define RETRO_END_DECLS } +/* Force C++ linkage for a region inside a header that may be included + * from within a caller's extern "C" { ... } block -- needed when the + * region pulls in a C++ standard library header (e.g. ). */ +#undef RETRO_BEGIN_DECLS_CXX +#undef RETRO_END_DECLS_CXX +#define RETRO_BEGIN_DECLS_CXX extern "C++" { +#define RETRO_END_DECLS_CXX } +#endif + +#else + +/* header is included by a C source file, so no extern "C" */ + +#endif + +/* +IMO, this non-standard ssize_t should not be used. +However, it's a good example of how to handle something like this. +*/ +#ifdef _MSC_VER +#ifndef HAVE_SSIZE_T +#define HAVE_SSIZE_T +#if defined(_WIN64) +typedef __int64 ssize_t; +#elif defined(_WIN32) +typedef int ssize_t; +#endif +#endif +#elif defined(__MACH__) && defined(__APPLE__) +#include +#endif + +#ifdef _MSC_VER +#if _MSC_VER >= 1800 +#include +#else +#ifndef PRId64 +#define PRId64 "I64d" +#define PRIu64 "I64u" +#define PRIuPTR "Iu" +#endif +#endif +#else +/* C++11 says this one isn't needed, but apparently (some versions of) mingw require it anyways */ +/* https://stackoverflow.com/questions/8132399/how-to-printf-uint64-t-fails-with-spurious-trailing-in-format */ +/* https://github.com/libretro/RetroArch/issues/6009 */ +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS 1 +#endif +#include +#endif +#ifndef PRId64 +#error "inttypes.h is being screwy" +#endif +#define STRING_REP_INT64 "%" PRId64 +#define STRING_REP_UINT64 "%" PRIu64 +#define STRING_REP_USIZE "%" PRIuPTR + +/* Wrap a declaration in RETRO_DEPRECATED() to produce a compiler warning when +it's used. This is intended for developer machines, so it won't work on ancient +or obscure compilers */ +#if defined(_MSC_VER) +#if _MSC_VER >= 1400 /* Visual C 2005 or later */ +#define RETRO_DEPRECATED(decl) __declspec(deprecated) decl +#endif +#elif defined(__GNUC__) +#if __GNUC__ >= 3 /* GCC 3 or later */ +#define RETRO_DEPRECATED(decl) decl __attribute__((deprecated)) +#endif +#elif defined(__clang__) +#if __clang_major__ >= 3 /* clang 3 or later */ +#define RETRO_DEPRECATED(decl) decl __attribute__((deprecated)) +#endif +#endif +#ifndef RETRO_DEPRECATED /* Unsupported compilers */ +#define RETRO_DEPRECATED(decl) decl +#endif + +/* +I would like to see retro_inline.h moved in here; possibly boolean too. + +rationale: these are used in public APIs, and it is easier to find problems +and write code that works the first time portably when they are included uniformly +than to do the analysis from scratch each time you think you need it, for each feature. + +Moreover it helps force you to make hard decisions: if you EVER bring in boolean.h, +then you should pay the price everywhere, so you can see how much grief it will cause. + +Of course, another school of thought is that you should do as little damage as possible +in as few places as possible... +*/ + +/* _LIBRETRO_COMMON_RETRO_COMMON_API_H */ +#endif diff --git a/Externals/libretro-common/include/retro_environment.h b/Externals/libretro-common/include/retro_environment.h new file mode 100644 index 0000000000..2130f851d1 --- /dev/null +++ b/Externals/libretro-common/include/retro_environment.h @@ -0,0 +1,111 @@ +/* Copyright (C) 2010-2020 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (retro_environment.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_ENVIRONMENT_H +#define __LIBRETRO_SDK_ENVIRONMENT_H + +/* +This file is designed to create a normalized environment for compiling +libretro-common's private implementations, or any other sources which might +enjoy use of it's environment (RetroArch for instance). +This should be an elaborately crafted environment so that sources don't +need to be full of platform-specific workarounds. +*/ + +#if defined (__cplusplus) +/* The expected values would be + * 199711L, for ISO/IEC 14882:1998 or 14882:2003 + */ + +#elif defined(__STDC__) +/* This is standard C. */ + +#if (__STDC__ == 1) +/* The implementation is ISO-conforming. */ +#define __STDC_ISO__ +#else +/* The implementation is not ISO-conforming. */ +#endif + +#if defined(__STDC_VERSION__) +#if (__STDC_VERSION__ >= 201112L) +/* This is C11. */ +#define __STDC_C11__ +#elif (__STDC_VERSION__ >= 199901L) +/* This is C99. */ +#define __STDC_C99__ +#elif (__STDC_VERSION__ >= 199409L) +/* This is C89 with amendment 1. */ +#define __STDC_C89__ +#define __STDC_C89_AMENDMENT_1__ +#else +/* This is C89 without amendment 1. */ +#define __STDC_C89__ +#endif +#else /* !defined(__STDC_VERSION__) */ +/* This is C89. __STDC_VERSION__ is not defined. */ +#define __STDC_C89__ +#endif + +#else /* !defined(__STDC__) */ +/* This is not standard C. __STDC__ is not defined. */ +#endif + +#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) +/* Try to find out if we're compiling for WinRT or non-WinRT */ +#if defined(_MSC_VER) && defined(__has_include) +#if __has_include() +#define HAVE_WINAPIFAMILY_H 1 +#else +#define HAVE_WINAPIFAMILY_H 0 +#endif + +/* If _USING_V110_SDK71_ is defined it means we are using the Windows XP toolset. */ +#elif defined(_MSC_VER) && (_MSC_VER >= 1700 && !_USING_V110_SDK71_) /* _MSC_VER == 1700 for Visual Studio 2012 */ +#define HAVE_WINAPIFAMILY_H 1 +#else +#define HAVE_WINAPIFAMILY_H 0 +#endif + +#if HAVE_WINAPIFAMILY_H +#include +#define WINAPI_FAMILY_WINRT (!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)) +#else +#define WINAPI_FAMILY_WINRT 0 +#endif /* HAVE_WINAPIFAMILY_H */ + +#if WINAPI_FAMILY_WINRT +#undef __WINRT__ +#define __WINRT__ 1 +#endif + +/* MSVC obviously has to have some non-standard constants... */ +#if _M_IX86_FP == 1 +#define __SSE__ 1 +#elif _M_IX86_FP == 2 || (defined(_M_AMD64) || defined(_M_X64)) +#define __SSE__ 1 +#define __SSE2__ 1 +#endif + +#endif + +#endif diff --git a/Externals/libretro-common/include/vfs/vfs.h b/Externals/libretro-common/include/vfs/vfs.h new file mode 100644 index 0000000000..6f53c890de --- /dev/null +++ b/Externals/libretro-common/include/vfs/vfs.h @@ -0,0 +1,122 @@ +/* Copyright (C) 2010-2020 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 +#include +#include + +#ifdef RARCH_INTERNAL +#ifndef VFS_FRONTEND +#define VFS_FRONTEND +#endif +#endif + +RETRO_BEGIN_DECLS + +#ifdef _WIN32 +typedef void* HANDLE; +#endif + +#ifdef HAVE_CDROM +typedef struct +{ + int64_t byte_pos; + char *cue_buf; + size_t cue_len; + unsigned cur_lba; + unsigned last_frame_lba; + unsigned char cur_min; + unsigned char cur_sec; + unsigned char cur_frame; + unsigned char cur_track; + unsigned char last_frame[2352]; + char drive; + bool last_frame_valid; +} vfs_cdrom_t; +#endif + +enum vfs_scheme +{ + VFS_SCHEME_NONE = 0, + VFS_SCHEME_CDROM, + VFS_SCHEME_SAF, + VFS_SCHEME_SMB +}; + +#if !(defined(__WINRT__) && defined(__cplusplus_winrt)) +#ifdef VFS_FRONTEND +struct retro_vfs_file_handle +#else +struct libretro_vfs_implementation_file +#endif +{ +#ifdef HAVE_CDROM + vfs_cdrom_t cdrom; /* int64_t alignment */ +#endif + int64_t size; + uint64_t mappos; + uint64_t mapsize; + FILE *fp; +#ifdef _WIN32 + HANDLE fh; +#endif + char *buf; + char* orig_path; + uint8_t *mapped; + int fd; + unsigned hints; + enum vfs_scheme scheme; +#ifdef HAVE_SMBCLIENT + intptr_t smb_fh; + intptr_t smb_ctx; +#endif +#if defined(HAVE_CDROM) && defined(__APPLE__) + void *iokit_plugin; /* IOCFPlugInInterface ** */ + void *iokit_mmc; /* MMCDeviceInterface ** */ +#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/Externals/libretro-common/include/vfs/vfs_implementation.h b/Externals/libretro-common/include/vfs/vfs_implementation.h new file mode 100644 index 0000000000..56d11a36de --- /dev/null +++ b/Externals/libretro-common/include/vfs/vfs_implementation.h @@ -0,0 +1,84 @@ +/* Copyright (C) 2010-2020 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_IMPLEMENTATION_H +#define __LIBRETRO_SDK_VFS_IMPLEMENTATION_H + +#include +#include +#include +#include +#include + +RETRO_BEGIN_DECLS + +libretro_vfs_implementation_file *retro_vfs_file_open_impl(const char *path, unsigned mode, unsigned hints); + +int retro_vfs_file_close_impl(libretro_vfs_implementation_file *stream); + +int retro_vfs_file_error_impl(libretro_vfs_implementation_file *stream); + +int64_t retro_vfs_file_size_impl(libretro_vfs_implementation_file *stream); + +int64_t retro_vfs_file_truncate_impl(libretro_vfs_implementation_file *stream, int64_t length); + +int64_t retro_vfs_file_tell_impl(libretro_vfs_implementation_file *stream); + +int64_t retro_vfs_file_seek_impl(libretro_vfs_implementation_file *stream, int64_t offset, int seek_position); + +int64_t retro_vfs_file_read_impl(libretro_vfs_implementation_file *stream, void *s, uint64_t len); + +int64_t retro_vfs_file_write_impl(libretro_vfs_implementation_file *stream, const void *s, uint64_t len); + +int retro_vfs_file_flush_impl(libretro_vfs_implementation_file *stream); + +int retro_vfs_file_remove_impl(const char *path); + +int retro_vfs_file_rename_impl(const char *old_path, const char *new_path); + +const char *retro_vfs_file_get_path_impl(libretro_vfs_implementation_file *stream); + +int retro_vfs_stat_impl(const char *path, int32_t *size); + +int retro_vfs_stat_64_impl(const char *path, int64_t *size); + +int retro_vfs_mkdir_impl(const char *dir); + +libretro_vfs_implementation_dir *retro_vfs_opendir_impl(const char *dir, bool include_hidden); + +bool retro_vfs_readdir_impl(libretro_vfs_implementation_dir *dirstream); + +const char *retro_vfs_dirent_get_name_impl(libretro_vfs_implementation_dir *dirstream); + +bool retro_vfs_dirent_is_dir_impl(libretro_vfs_implementation_dir *dirstream); + +int retro_vfs_closedir_impl(libretro_vfs_implementation_dir *dirstream); + +#ifdef __WINRT__ + +void uwp_set_acl(const wchar_t* path, const wchar_t* AccessString); + +#endif + +RETRO_END_DECLS + +#endif diff --git a/Externals/libretro-common/include/vfs/vfs_implementation_cdrom.h b/Externals/libretro-common/include/vfs/vfs_implementation_cdrom.h new file mode 100644 index 0000000000..f809963f4f --- /dev/null +++ b/Externals/libretro-common/include/vfs/vfs_implementation_cdrom.h @@ -0,0 +1,52 @@ +/* Copyright (C) 2010-2020 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (vfs_implementation_cdrom.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_IMPLEMENTATION_CDROM_H +#define __LIBRETRO_SDK_VFS_IMPLEMENTATION_CDROM_H + +#include +#include + +RETRO_BEGIN_DECLS + +int64_t retro_vfs_file_seek_cdrom(libretro_vfs_implementation_file *stream, int64_t offset, int whence); + +void retro_vfs_file_open_cdrom( + libretro_vfs_implementation_file *stream, + const char *path, unsigned mode, unsigned hints); + +int retro_vfs_file_close_cdrom(libretro_vfs_implementation_file *stream); + +int64_t retro_vfs_file_tell_cdrom(libretro_vfs_implementation_file *stream); + +int64_t retro_vfs_file_read_cdrom(libretro_vfs_implementation_file *stream, + void *s, uint64_t len); + +int retro_vfs_file_error_cdrom(libretro_vfs_implementation_file *stream); + +const cdrom_toc_t* retro_vfs_file_get_cdrom_toc(void); + +const vfs_cdrom_t* retro_vfs_file_get_cdrom_position(const libretro_vfs_implementation_file *stream); + +RETRO_END_DECLS + +#endif diff --git a/Externals/libretro-common/include/vfs/vfs_implementation_saf.h b/Externals/libretro-common/include/vfs/vfs_implementation_saf.h new file mode 100644 index 0000000000..0ad820fe09 --- /dev/null +++ b/Externals/libretro-common/include/vfs/vfs_implementation_saf.h @@ -0,0 +1,110 @@ +/* Copyright (C) 2010-2020 The RetroArch team +* +* --------------------------------------------------------------------------------------- +* The following license statement only applies to this file (vfs_implementation_saf.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_IMPLEMENTATION_SAF_H +#define __LIBRETRO_SDK_VFS_IMPLEMENTATION_SAF_H + +#include +#include +#include +#include +#include +#include +#include + +RETRO_BEGIN_DECLS + +typedef struct libretro_vfs_implementation_saf_dir +{ + jobject directory_object; + jstring dirent_name_object; + const char *dirent_name; + bool dirent_is_dir; +} libretro_vfs_implementation_saf_dir; + +struct libretro_vfs_implementation_saf_path_split_result +{ + char *tree; + char *path; +}; + +/* + * Initialize this VFS backend. This must be called prior to using any of the VFS operations provided by this backend. + * get_jni_env should be a function that returns the JNIEnv for the current thread. + * activity_object should be the current Android android.app.Activity. + */ +bool retro_vfs_init_saf(JNIEnv *(*get_jni_env)(void), jobject activity_object); + +/* + * Deinitialize this VFS backend. + */ +bool retro_vfs_deinit_saf(void); + +/* + * Split a serialized "saf://" path string into tree and path components for use with this backend. + * Returns true if successful or false if not. + * The results will be returned in `out` and must be freed by the caller. + */ +bool retro_vfs_path_split_saf(struct libretro_vfs_implementation_saf_path_split_result *out, const char *serialized_path); + +/* + * Join the tree and path components into a single serialized "saf://" path string. + * Returns the serialized path if successful or NULL if not. + * The returned path must be freed by the caller. + */ +char *retro_vfs_path_join_saf(const char *tree, const char *path); + +/* + * Split a "content://" document URI returned by the Android Storage Access Framework into tree and path components for use with this backend. + * Returns true if successful or false if not. + * The results will be returned in `out` and must be freed by the caller. + */ +bool retro_vfs_path_split_content_saf(struct libretro_vfs_implementation_saf_path_split_result *out, const char *content_uri); + +/* + * Open a file, returning its file descriptor if successful or -1 if not. + * The file descriptor can be operated on using the POSIX file system API (`read()`, `write()`, `lseek()`, `close()`, etc). + * You can also turn the file descriptor into a `FILE *` by calling `fdopen()` on it. + */ +int retro_vfs_file_open_saf(const char *tree, const char *path, unsigned mode); + +int retro_vfs_file_remove_saf(const char *tree, const char *path); + +int retro_vfs_file_rename_saf(const char *old_tree, const char *old_path, const char *new_tree, const char *new_path); + +int retro_vfs_stat_saf(const char *tree, const char *path, int64_t *size); + +int retro_vfs_mkdir_saf(const char *tree, const char *dir); + +libretro_vfs_implementation_saf_dir *retro_vfs_opendir_saf(const char *tree, const char *dir, bool include_hidden); + +bool retro_vfs_readdir_saf(libretro_vfs_implementation_saf_dir *dirstream); + +const char *retro_vfs_dirent_get_name_saf(libretro_vfs_implementation_saf_dir *dirstream); + +bool retro_vfs_dirent_is_dir_saf(libretro_vfs_implementation_saf_dir *dirstream); + +int retro_vfs_closedir_saf(libretro_vfs_implementation_saf_dir *dirstream); + +RETRO_END_DECLS + +#endif diff --git a/Source/Core/AudioCommon/CMakeLists.txt b/Source/Core/AudioCommon/CMakeLists.txt index 2e4904b5c2..f3d16f8096 100644 --- a/Source/Core/AudioCommon/CMakeLists.txt +++ b/Source/Core/AudioCommon/CMakeLists.txt @@ -104,5 +104,5 @@ if(MSVC) endif() if(LIBRETRO) - target_include_directories(audiocommon PRIVATE ${CMAKE_SOURCE_DIR}/Externals/Libretro/Include) + target_include_directories(audiocommon PRIVATE ${CMAKE_SOURCE_DIR}/Externals/libretro-common/include) endif() diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index 9ae419b01f..0ed507cb84 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -417,6 +417,6 @@ if(MSVC) endif() if(LIBRETRO) - target_include_directories(common PRIVATE ${CMAKE_SOURCE_DIR}/Externals/Libretro/Include) + target_include_directories(common PRIVATE ${CMAKE_SOURCE_DIR}/Externals/libretro-common/include) target_link_libraries(common PRIVATE dolphin_libretro_videocontexts) endif() diff --git a/Source/Core/DolphinLibretro/CMakeLists.txt b/Source/Core/DolphinLibretro/CMakeLists.txt index 34b2e7c45c..50497a7171 100644 --- a/Source/Core/DolphinLibretro/CMakeLists.txt +++ b/Source/Core/DolphinLibretro/CMakeLists.txt @@ -15,14 +15,14 @@ if(ENABLE_VULKAN) ) endif() -include_directories(${CMAKE_SOURCE_DIR}/Externals/Libretro/Include) +include_directories(${CMAKE_SOURCE_DIR}/Externals/libretro-common/include) if(ENABLE_VULKAN) include_directories(${CMAKE_SOURCE_DIR}/Externals/Vulkan-Headers/include) include_directories(${CMAKE_SOURCE_DIR}/Externals/VulkanMemoryAllocator/include) endif() -target_include_directories(dolphin_libretro PRIVATE ${CMAKE_SOURCE_DIR}/Externals/Libretro/Include) +target_include_directories(dolphin_libretro PRIVATE ${CMAKE_SOURCE_DIR}/Externals/libretro-common/include) set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}") @@ -61,7 +61,7 @@ else() ) endif() -set(LIBRETRO_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/Externals/Libretro/Include) +set(LIBRETRO_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/Externals/libretro-common/include) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Common) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/VideoContexts)