From 40176b498fd8d5068760e64b371effed4d7a5ae8 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 7 Sep 2017 16:35:02 +0200 Subject: [PATCH] Updates for NT 3.51 --- compat/compat_snprintf.c | 10 ++++++++++ encodings/encoding_crc32.c | 1 + features/features_cpu.c | 8 ++++++-- file/file_path.c | 6 ++++-- hash/rhash.c | 4 ++-- include/compat/msvc.h | 32 ++++++++++++++++++++++++++++++-- include/compat/msvc/stdint.h | 6 +++++- include/encodings/crc32.h | 1 - include/retro_endianness.h | 16 ++++++++++++++-- include/streams/file_stream.h | 2 +- rthreads/rthreads.c | 10 ++++++++-- streams/file_stream.c | 4 ++-- 12 files changed, 83 insertions(+), 17 deletions(-) diff --git a/compat/compat_snprintf.c b/compat/compat_snprintf.c index 8baa56a..49867de 100644 --- a/compat/compat_snprintf.c +++ b/compat/compat_snprintf.c @@ -57,4 +57,14 @@ int c99_snprintf_retro__(char *outBuf, size_t size, const char *format, ...) return count; } + +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 diff --git a/encodings/encoding_crc32.c b/encodings/encoding_crc32.c index aa10d1a..0c1895a 100644 --- a/encodings/encoding_crc32.c +++ b/encodings/encoding_crc32.c @@ -22,6 +22,7 @@ #include #include +#include static const uint32_t crc32_table[256] = { 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, diff --git a/features/features_cpu.c b/features/features_cpu.c index 4b976f6..94bf644 100644 --- a/features/features_cpu.c +++ b/features/features_cpu.c @@ -136,8 +136,12 @@ retro_perf_tick_t cpu_features_get_perf_counter(void) { retro_perf_tick_t time_ticks = 0; #if defined(_WIN32) - long tv_sec, tv_usec; - static const unsigned __int64 epoch = 11644473600000000ULL; + long tv_sec, tv_usec; +#if defined(_MSC_VER) && _MSC_VER <= 1200 + static const unsigned __int64 epoch = 11644473600000000; +#else + static const unsigned __int64 epoch = 11644473600000000ULL; +#endif FILETIME file_time; SYSTEMTIME system_time; ULARGE_INTEGER ularge; diff --git a/file/file_path.c b/file/file_path.c index e19b13d..fcb3fd6 100644 --- a/file/file_path.c +++ b/file/file_path.c @@ -362,11 +362,13 @@ bool path_is_compressed_file(const char* path) * Returns: true (1) if file already exists, otherwise false (0). */ bool path_file_exists(const char *path) -{ +{ + FILE *dummy; + if (!path || !*path) return false; - FILE *dummy = fopen(path, "rb"); + dummy = fopen(path, "rb"); if (!dummy) return false; diff --git a/hash/rhash.c b/hash/rhash.c index 8eb2bb5..3d4aa1c 100644 --- a/hash/rhash.c +++ b/hash/rhash.c @@ -201,7 +201,7 @@ void sha256_hash(char *s, const uint8_t *in, size_t size) #ifndef HAVE_ZLIB /* Zlib CRC32. */ -static const uint32_t crc32_table[256] = { +static const uint32_t crc32_hash_table[256] = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, @@ -249,7 +249,7 @@ static const uint32_t crc32_table[256] = { uint32_t crc32_adjust(uint32_t checksum, uint8_t input) { - return ((checksum >> 8) & 0x00ffffff) ^ crc32_table[(checksum ^ input) & 0xff]; + return ((checksum >> 8) & 0x00ffffff) ^ crc32_hash_table[(checksum ^ input) & 0xff]; } uint32_t crc32_calculate(const uint8_t *data, size_t length) diff --git a/include/compat/msvc.h b/include/compat/msvc.h index 76bc2e4..8319b5d 100644 --- a/include/compat/msvc.h +++ b/include/compat/msvc.h @@ -28,7 +28,7 @@ #ifdef __cplusplus extern "C" { #endif - + /* Pre-MSVC 2015 compilers don't implement snprintf in a cross-platform manner. */ #if _MSC_VER < 1900 #include @@ -86,10 +86,38 @@ 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 <= 1200 + #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)) + #endif + + #ifndef _vscprintf + #define _vscprintf c89_vscprintf_retro__ + int c89_vscprintf_retro__(const char *format, va_list pargs); + #endif + + #ifndef _strtoui64 + #define _strtoui64(x, y, z) (_atoi64(x)) + #endif + +#endif #ifndef PATH_MAX #define PATH_MAX _MAX_PATH diff --git a/include/compat/msvc/stdint.h b/include/compat/msvc/stdint.h index 403e1f7..fa7a2bf 100644 --- a/include/compat/msvc/stdint.h +++ b/include/compat/msvc/stdint.h @@ -47,7 +47,11 @@ * error C2733: second C linkage of overloaded function 'wmemchr' not allowed */ #ifdef __cplusplus -extern "C" { +#if _MSC_VER <= 1200 +extern "C++" { +#else +extern "C" { +#endif #endif # include #ifdef __cplusplus diff --git a/include/encodings/crc32.h b/include/encodings/crc32.h index d1973e4..0c99476 100644 --- a/include/encodings/crc32.h +++ b/include/encodings/crc32.h @@ -30,7 +30,6 @@ RETRO_BEGIN_DECLS - uint32_t encoding_crc32(uint32_t crc, const uint8_t *buf, size_t len); RETRO_END_DECLS diff --git a/include/retro_endianness.h b/include/retro_endianness.h index baa3eec..2e4e6a2 100644 --- a/include/retro_endianness.h +++ b/include/retro_endianness.h @@ -27,7 +27,7 @@ #include #include -#if defined(_MSC_VER) +#if defined(_MSC_VER) && _MSC_VER > 1200 #define SWAP16 _byteswap_ushort #define SWAP32 _byteswap_ulong #else @@ -42,7 +42,18 @@ (((uint32_t)(x) & 0xff000000) >> 24) \ )) #endif - + +#if defined(_MSC_VER) && _MSC_VER <= 1200 +#define SWAP64(val) \ + ((((uint64_t)(val) & 0x00000000000000ff) << 56) \ + | (((uint64_t)(val) & 0x000000000000ff00) << 40) \ + | (((uint64_t)(val) & 0x0000000000ff0000) << 24) \ + | (((uint64_t)(val) & 0x00000000ff000000) << 8) \ + | (((uint64_t)(val) & 0x000000ff00000000) >> 8) \ + | (((uint64_t)(val) & 0x0000ff0000000000) >> 24) \ + | (((uint64_t)(val) & 0x00ff000000000000) >> 40) \ + | (((uint64_t)(val) & 0xff00000000000000) >> 56)) +#else #define SWAP64(val) \ ((((uint64_t)(val) & 0x00000000000000ffULL) << 56) \ | (((uint64_t)(val) & 0x000000000000ff00ULL) << 40) \ @@ -52,6 +63,7 @@ | (((uint64_t)(val) & 0x0000ff0000000000ULL) >> 24) \ | (((uint64_t)(val) & 0x00ff000000000000ULL) >> 40) \ | (((uint64_t)(val) & 0xff00000000000000ULL) >> 56)) +#endif /** * is_little_endian: diff --git a/include/streams/file_stream.h b/include/streams/file_stream.h index 5e6298d..2226fc3 100644 --- a/include/streams/file_stream.h +++ b/include/streams/file_stream.h @@ -49,7 +49,7 @@ enum RFILE_HINT_MMAP = 1<<9 /* requires RFILE_MODE_READ */ }; -long long int filestream_get_size(RFILE *stream); +int64_t filestream_get_size(RFILE *stream); void filestream_set_size(RFILE *stream); diff --git a/rthreads/rthreads.c b/rthreads/rthreads.c index 20eddc0..93f7425 100644 --- a/rthreads/rthreads.c +++ b/rthreads/rthreads.c @@ -159,7 +159,9 @@ sthread_t *sthread_create(void (*thread_func)(void*), void *userdata) bool thread_created = false; struct thread_data *data = NULL; sthread_t *thread = (sthread_t*)calloc(1, sizeof(*thread)); - +#if defined(_WIN32_WINNT) && _WIN32_WINNT <= 0x0410 + DWORD thread_id = 0; +#endif if (!thread) return NULL; @@ -171,7 +173,11 @@ sthread_t *sthread_create(void (*thread_func)(void*), void *userdata) data->userdata = userdata; #ifdef USE_WIN32_THREADS - thread->thread = CreateThread(NULL, 0, thread_wrap, data, 0, NULL); +#if defined(_WIN32_WINNT) && _WIN32_WINNT <= 0x0410 + thread->thread = CreateThread(NULL, 0, thread_wrap, data, 0, &thread_id); +#else + thread->thread = CreateThread(NULL, 0, thread_wrap, data, 0, NULL); +#endif thread_created = !!thread->thread; #else #if defined(VITA) diff --git a/streams/file_stream.c b/streams/file_stream.c index c0425f4..7a911bc 100644 --- a/streams/file_stream.c +++ b/streams/file_stream.c @@ -69,7 +69,7 @@ struct RFILE { unsigned hints; char *ext; - long long int size; + int64_t size; #if defined(PSP) SceUID fd; #else @@ -111,7 +111,7 @@ const char *filestream_get_ext(RFILE *stream) return stream->ext; } -long long int filestream_get_size(RFILE *stream) +int64_t filestream_get_size(RFILE *stream) { if (!stream) return 0;