From f6db0b026bf1336caf2e1169091baa29c44bdef1 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 13 Apr 2018 01:58:48 +0200 Subject: [PATCH] Updates --- .../libretro-common/compat/compat_snprintf.c | 20 ++++- .../libretro-common/include/compat/msvc.h | 30 +++++++- .../include/compat/msvc/stdint.h | 16 ++-- .../libretro-common/include/libretro.h | 75 ++++++++++++++++++- .../libretro-common/include/retro_common.h | 2 +- .../include/retro_common_api.h | 36 +++++---- .../include/streams/memory_stream.h | 12 +-- .../libretro-common/streams/memory_stream.c | 36 ++++----- 8 files changed, 174 insertions(+), 53 deletions(-) diff --git a/src/drivers/libretro/libretro-common/compat/compat_snprintf.c b/src/drivers/libretro/libretro-common/compat/compat_snprintf.c index 8baa56a..40734a6 100644 --- a/src/drivers/libretro/libretro-common/compat/compat_snprintf.c +++ b/src/drivers/libretro/libretro-common/compat/compat_snprintf.c @@ -25,9 +25,27 @@ #include -#include +#include /* added for _vsnprintf_s and _vscprintf on VS2015 and VS2017 */ #include +#if _MSC_VER < 1800 +#define va_copy(dst, src) ((dst) = (src)) +#endif + +#if _MSC_VER < 1300 +#define _vscprintf c89_vscprintf_retro__ + +static int c89_vscprintf_retro__(const char *format, va_list pargs) +{ + int retval; + va_list argcopy; + va_copy(argcopy, pargs); + retval = vsnprintf(NULL, 0, format, argcopy); + va_end(argcopy); + return retval; +} +#endif + /* http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010 */ int c99_vsnprintf_retro__(char *outBuf, size_t size, const char *format, va_list ap) diff --git a/src/drivers/libretro/libretro-common/include/compat/msvc.h b/src/drivers/libretro/libretro-common/include/compat/msvc.h index 76bc2e4..fea4b53 100644 --- a/src/drivers/libretro/libretro-common/include/compat/msvc.h +++ b/src/drivers/libretro/libretro-common/include/compat/msvc.h @@ -35,12 +35,12 @@ extern "C" { #ifndef snprintf #define snprintf c99_snprintf_retro__ #endif - + int c99_snprintf_retro__(char *outBuf, size_t size, const char *format, ...); #endif /* Pre-MSVC 2010 compilers don't implement vsnprintf in a cross-platform manner? Not sure about this one. */ -#if _MSC_VER < 1600 +#if _MSC_VER < 1600 #include #include #ifndef vsnprintf @@ -86,9 +86,33 @@ typedef int ssize_t; #pragma warning(disable : 4723) #pragma warning(disable : 4996) -/* roundf is available since MSVC 2013 */ +/* roundf and va_copy is available since MSVC 2013 */ #if _MSC_VER < 1800 #define roundf(in) (in >= 0.0f ? floorf(in + 0.5f) : ceilf(in - 0.5f)) +#define va_copy(x, y) ((x) = (y)) +#endif + +#if _MSC_VER <= 1310 + #ifndef __cplusplus + /* VC6 math.h doesn't define some functions when in C mode. + * Trying to define a prototype gives "undefined reference". + * But providing an implementation then gives "function already has body". + * So the equivalent of the implementations from math.h are used as + * defines here instead, and it seems to work. + */ + #define cosf(x) ((float)cos((double)x)) + #define powf(x, y) ((float)pow((double)x, (double)y)) + #define sinf(x) ((float)sin((double)x)) + #define ceilf(x) ((float)ceil((double)x)) + #define floorf(x) ((float)floor((double)x)) + #define sqrtf(x) ((float)sqrt((double)x)) + #define fabsf(x) ((float)fabs((double)(x))) + #endif + + #ifndef _strtoui64 + #define _strtoui64(x, y, z) (_atoi64(x)) + #endif + #endif #ifndef PATH_MAX diff --git a/src/drivers/libretro/libretro-common/include/compat/msvc/stdint.h b/src/drivers/libretro/libretro-common/include/compat/msvc/stdint.h index da8c6f0..c791176 100644 --- a/src/drivers/libretro/libretro-common/include/compat/msvc/stdint.h +++ b/src/drivers/libretro/libretro-common/include/compat/msvc/stdint.h @@ -1,5 +1,5 @@ /* ISO C9x compliant stdint.h for Microsoft Visual Studio - * Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 + * Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 * * Copyright (c) 2006-2008 Alexander Chemeris * @@ -22,7 +22,7 @@ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. @@ -47,11 +47,11 @@ * error C2733: second C linkage of overloaded function 'wmemchr' not allowed */ #ifdef __cplusplus -#if _MSC_VER <= 1200 -extern "C++" { -#else -extern "C" { -#endif +#if _MSC_VER <= 1200 +extern "C++" { +#else +extern "C" { +#endif #endif # include #ifdef __cplusplus @@ -216,7 +216,7 @@ typedef uint64_t uintmax_t; #ifndef WCHAR_MIN /* [ */ # define WCHAR_MIN 0 #endif /* WCHAR_MIN ] */ -#ifndef WCHAR_MAX /* [ */ +#ifndef WCHAR_MAX // [ # define WCHAR_MAX _UI16_MAX #endif /* WCHAR_MAX ] */ diff --git a/src/drivers/libretro/libretro-common/include/libretro.h b/src/drivers/libretro/libretro-common/include/libretro.h index 315123c..7d01185 100644 --- a/src/drivers/libretro/libretro-common/include/libretro.h +++ b/src/drivers/libretro/libretro-common/include/libretro.h @@ -32,7 +32,7 @@ extern "C" { #endif #ifndef __cplusplus -#if defined(_MSC_VER) && !defined(SN_TARGET_PS3) +#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 @@ -270,6 +270,7 @@ enum retro_language RETRO_LANGUAGE_ESPERANTO = 13, RETRO_LANGUAGE_POLISH = 14, RETRO_LANGUAGE_VIETNAMESE = 15, + RETRO_LANGUAGE_ARABIC = 16, RETRO_LANGUAGE_LAST, /* Ensure sizeof(enum) == sizeof(int) */ @@ -375,6 +376,10 @@ enum retro_key RETROK_x = 120, RETROK_y = 121, RETROK_z = 122, + RETROK_LEFTBRACE = 123, + RETROK_BAR = 124, + RETROK_RIGHTBRACE = 125, + RETROK_TILDE = 126, RETROK_DELETE = 127, RETROK_KP0 = 256, @@ -1083,8 +1088,12 @@ struct retro_vfs_interface_info enum retro_hw_render_interface_type { - RETRO_HW_RENDER_INTERFACE_VULKAN = 0, - RETRO_HW_RENDER_INTERFACE_DUMMY = INT_MAX + RETRO_HW_RENDER_INTERFACE_VULKAN = 0, + RETRO_HW_RENDER_INTERFACE_D3D9 = 1, + RETRO_HW_RENDER_INTERFACE_D3D10 = 2, + RETRO_HW_RENDER_INTERFACE_D3D11 = 3, + RETRO_HW_RENDER_INTERFACE_D3D12 = 4, + RETRO_HW_RENDER_INTERFACE_DUMMY = INT_MAX }; /* Base struct. All retro_hw_render_interface_* types @@ -1094,6 +1103,62 @@ struct retro_hw_render_interface enum retro_hw_render_interface_type interface_type; unsigned interface_version; }; + + +#define RETRO_ENVIRONMENT_GET_LED_INTERFACE (46 | RETRO_ENVIRONMENT_EXPERIMENTAL) + /* struct retro_led_interface * -- + * Gets an interface which is used by a libretro core to set + * state of LEDs. + */ + +typedef void (RETRO_CALLCONV *retro_set_led_state_t)(int led, int state); +struct retro_led_interface +{ + retro_set_led_state_t set_led_state; +}; + +#define RETRO_ENVIRONMENT_GET_AUDIO_VIDEO_ENABLE (47 | RETRO_ENVIRONMENT_EXPERIMENTAL) + /* int * -- + * Tells the core if the frontend wants audio or video. + * If disabled, the frontend will discard the audio or video, + * so the core may decide to skip generating a frame or generating audio. + * This is mainly used for increasing performance. + * Bit 0 (value 1): Enable Video + * Bit 1 (value 2): Enable Audio + * Bit 2 (value 4): Use Fast Savestates. + * Bit 3 (value 8): Hard Disable Audio + * Other bits are reserved for future use and will default to zero. + * If video is disabled: + * * The frontend wants the core to not generate any video, + * including presenting frames via hardware acceleration. + * * The frontend's video frame callback will do nothing. + * * After running the frame, the video output of the next frame should be + * no different than if video was enabled, and saving and loading state + * should have no issues. + * If audio is disabled: + * * The frontend wants the core to not generate any audio. + * * The frontend's audio callbacks will do nothing. + * * After running the frame, the audio output of the next frame should be + * no different than if audio was enabled, and saving and loading state + * should have no issues. + * Fast Savestates: + * * Guaranteed to be created by the same binary that will load them. + * * Will not be written to or read from the disk. + * * Suggest that the core assumes loading state will succeed. + * * Suggest that the core updates its memory buffers in-place if possible. + * * Suggest that the core skips clearing memory. + * * Suggest that the core skips resetting the system. + * * Suggest that the core may skip validation steps. + * Hard Disable Audio: + * * Used for a secondary core when running ahead. + * * Indicates that the frontend will never need audio from the core. + * * Suggests that the core may stop synthesizing audio, but this should not + * compromise emulation accuracy. + * * Audio output for the next frame does not matter, and the frontend will + * never need an accurate audio state in the future. + * * State will never be saved when using Hard Disable Audio. + */ + #define RETRO_ENVIRONMENT_GET_HW_RENDER_INTERFACE (41 | RETRO_ENVIRONMENT_EXPERIMENTAL) /* const struct retro_hw_render_interface ** -- * Returns an API specific rendering interface for accessing API specific data. @@ -1822,6 +1887,10 @@ enum retro_hw_context_type /* Vulkan, see RETRO_ENVIRONMENT_GET_HW_RENDER_INTERFACE. */ RETRO_HW_CONTEXT_VULKAN = 6, + /* Direct3D, set version_major to select the type of interface + * returned by RETRO_ENVIRONMENT_GET_HW_RENDER_INTERFACE */ + RETRO_HW_CONTEXT_DIRECT3D = 7, + RETRO_HW_CONTEXT_DUMMY = INT_MAX }; diff --git a/src/drivers/libretro/libretro-common/include/retro_common.h b/src/drivers/libretro/libretro-common/include/retro_common.h index 3385723..5938bea 100644 --- a/src/drivers/libretro/libretro-common/include/retro_common.h +++ b/src/drivers/libretro/libretro-common/include/retro_common.h @@ -26,7 +26,7 @@ /* This file is designed to normalize the libretro-common compiling environment. It is not to be used in public API headers, as they should be designed as leanly as possible. -Nonetheless.. in the meantime, if you do something like use ssize_t, which is not fully portable, +Nonetheless.. in the meantime, if you do something like use ssize_t, which is not fully portable, in a public API, you may need this. */ diff --git a/src/drivers/libretro/libretro-common/include/retro_common_api.h b/src/drivers/libretro/libretro-common/include/retro_common_api.h index 38b6773..ff38f98 100644 --- a/src/drivers/libretro/libretro-common/include/retro_common_api.h +++ b/src/drivers/libretro/libretro-common/include/retro_common_api.h @@ -25,14 +25,14 @@ /* This file is designed to normalize the libretro-common compiling environment -for public API headers. This should be leaner than a normal 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 +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. @@ -75,19 +75,29 @@ typedef int ssize_t; #include #endif -#ifdef _WIN32 -#define STRING_REP_INT64 "%I64u" -#define STRING_REP_UINT64 "%I64u" -#define STRING_REP_ULONG "%Iu" -#elif defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L && !defined(VITA) && !defined(WIIU) -#define STRING_REP_INT64 "%llu" -#define STRING_REP_UINT64 "%llu" -#define STRING_REP_ULONG "%zu" +#ifdef _MSC_VER +#if _MSC_VER >= 1800 +#include #else -#define STRING_REP_INT64 "%llu" -#define STRING_REP_UINT64 "%llu" -#define STRING_REP_ULONG "%lu" +#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 */ +#define __STDC_FORMAT_MACROS +#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 /* I would like to see retro_inline.h moved in here; possibly boolean too. diff --git a/src/drivers/libretro/libretro-common/include/streams/memory_stream.h b/src/drivers/libretro/libretro-common/include/streams/memory_stream.h index dca8e7a..fba8783 100644 --- a/src/drivers/libretro/libretro-common/include/streams/memory_stream.h +++ b/src/drivers/libretro/libretro-common/include/streams/memory_stream.h @@ -36,9 +36,9 @@ memstream_t *memstream_open(unsigned writing); void memstream_close(memstream_t *stream); -size_t memstream_read(memstream_t *stream, void *data, size_t bytes); +uint64_t memstream_read(memstream_t *stream, void *data, uint64_t bytes); -size_t memstream_write(memstream_t *stream, const void *data, size_t bytes); +uint64_t memstream_write(memstream_t *stream, const void *data, uint64_t bytes); int memstream_getc(memstream_t *stream); @@ -46,15 +46,15 @@ void memstream_putc(memstream_t *stream, int c); char *memstream_gets(memstream_t *stream, char *buffer, size_t len); -size_t memstream_pos(memstream_t *stream); +uint64_t memstream_pos(memstream_t *stream); void memstream_rewind(memstream_t *stream); -int memstream_seek(memstream_t *stream, int offset, int whence); +int64_t memstream_seek(memstream_t *stream, int64_t offset, int whence); -void memstream_set_buffer(uint8_t *buffer, size_t size); +void memstream_set_buffer(uint8_t *buffer, uint64_t size); -size_t memstream_get_last_size(void); +uint64_t memstream_get_last_size(void); RETRO_END_DECLS diff --git a/src/drivers/libretro/libretro-common/streams/memory_stream.c b/src/drivers/libretro/libretro-common/streams/memory_stream.c index 0141012..784d0fe 100644 --- a/src/drivers/libretro/libretro-common/streams/memory_stream.c +++ b/src/drivers/libretro/libretro-common/streams/memory_stream.c @@ -26,16 +26,16 @@ #include -static uint8_t* g_buffer = NULL; -static size_t g_size = 0; -static size_t last_file_size = 0; +static uint8_t* g_buffer = NULL; +static uint64_t g_size = 0; +static uint64_t last_file_size = 0; struct memstream { uint8_t *buf; - size_t size; - size_t ptr; - size_t max_ptr; + uint64_t size; + uint64_t ptr; + uint64_t max_ptr; unsigned writing; }; @@ -45,19 +45,19 @@ static void memstream_update_pos(memstream_t *stream) stream->max_ptr = stream->ptr; } -void memstream_set_buffer(uint8_t *buffer, size_t size) +void memstream_set_buffer(uint8_t *buffer, uint64_t size) { g_buffer = buffer; g_size = size; } -size_t memstream_get_last_size(void) +uint64_t memstream_get_last_size(void) { return last_file_size; } static void memstream_init(memstream_t *stream, - uint8_t *buffer, size_t max_size, unsigned writing) + uint8_t *buffer, uint64_t max_size, unsigned writing) { if (!stream) return; @@ -92,9 +92,9 @@ void memstream_close(memstream_t *stream) free(stream); } -size_t memstream_read(memstream_t *stream, void *data, size_t bytes) +uint64_t memstream_read(memstream_t *stream, void *data, uint64_t bytes) { - size_t avail = 0; + uint64_t avail = 0; if (!stream) return 0; @@ -103,15 +103,15 @@ size_t memstream_read(memstream_t *stream, void *data, size_t bytes) if (bytes > avail) bytes = avail; - memcpy(data, stream->buf + stream->ptr, bytes); + memcpy(data, stream->buf + stream->ptr, (size_t)bytes); stream->ptr += bytes; memstream_update_pos(stream); return bytes; } -size_t memstream_write(memstream_t *stream, const void *data, size_t bytes) +uint64_t memstream_write(memstream_t *stream, const void *data, uint64_t bytes) { - size_t avail = 0; + uint64_t avail = 0; if (!stream) return 0; @@ -120,15 +120,15 @@ size_t memstream_write(memstream_t *stream, const void *data, size_t bytes) if (bytes > avail) bytes = avail; - memcpy(stream->buf + stream->ptr, data, bytes); + memcpy(stream->buf + stream->ptr, data, (size_t)bytes); stream->ptr += bytes; memstream_update_pos(stream); return bytes; } -int memstream_seek(memstream_t *stream, int offset, int whence) +int64_t memstream_seek(memstream_t *stream, int64_t offset, int whence) { - size_t ptr; + uint64_t ptr; switch (whence) { @@ -159,7 +159,7 @@ void memstream_rewind(memstream_t *stream) memstream_seek(stream, 0L, SEEK_SET); } -size_t memstream_pos(memstream_t *stream) +uint64_t memstream_pos(memstream_t *stream) { return stream->ptr; }