diff --git a/CMakeLists.txt b/CMakeLists.txt index 8eb679962..efbc4b035 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,14 +22,11 @@ if(NOT LIBMGBA_ONLY) set(BINARY_NAME ${BINARY_NAME} CACHE INTERNAL "Name of output binaries") endif() -set(CMAKE_C_STANDARD 99) +set(CMAKE_C_STANDARD 11) if(NOT MSVC) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_EXTENSIONS OFF) - if(SWITCH OR 3DS) - set(CMAKE_C_STANDARD 11) - set(CMAKE_C_EXTENSIONS ON) - elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "4.3") + if(SWITCH OR 3DS OR (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "4.3")) set(CMAKE_C_EXTENSIONS ON) endif() set(WARNING_FLAGS "-Wall -Wextra -Wno-missing-field-initializers") diff --git a/README.md b/README.md index b836185b8..134c59ee8 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ Controls are configurable in the settings menu. Many game controllers should be Compiling --------- -Compiling requires using CMake 3.1 or newer. GCC and Clang are both known to work to compile mGBA, but Visual Studio 2013 and older are known not to work. Support for Visual Studio 2015 and newer is coming soon. +Compiling requires using CMake 3.1 or newer. GCC, Clang and Visual Studio 2019 known to work to compile mGBA. #### Docker building diff --git a/include/mgba-util/common.h b/include/mgba-util/common.h index d370d67a5..8f14706d3 100644 --- a/include/mgba-util/common.h +++ b/include/mgba-util/common.h @@ -20,6 +20,7 @@ CXX_GUARD_START +#include #include #include #include diff --git a/include/mgba-util/platform/posix/threading.h b/include/mgba-util/platform/posix/threading.h index b27d6f1fd..c8d42ed73 100644 --- a/include/mgba-util/platform/posix/threading.h +++ b/include/mgba-util/platform/posix/threading.h @@ -24,7 +24,6 @@ typedef THREAD_ENTRY (*ThreadEntry)(void*); typedef pthread_t Thread; typedef pthread_mutex_t Mutex; typedef pthread_cond_t Condition; -typedef pthread_key_t ThreadLocal; static inline int MutexInit(Mutex* mutex) { return pthread_mutex_init(mutex, 0); @@ -104,6 +103,9 @@ static inline int ThreadSetName(const char* name) { #endif } +#if (__STDC_VERSION__ < 201112L) || (__STDC_NO_THREADS__ == 1) +typedef pthread_key_t ThreadLocal; + static inline void ThreadLocalInitKey(ThreadLocal* key) { pthread_key_create(key, 0); } @@ -115,6 +117,7 @@ static inline void ThreadLocalSetKey(ThreadLocal key, void* value) { static inline void* ThreadLocalGetValue(ThreadLocal key) { return pthread_getspecific(key); } +#endif CXX_GUARD_END diff --git a/include/mgba-util/platform/windows/threading.h b/include/mgba-util/platform/windows/threading.h index d7a7b5532..9be6fe53a 100644 --- a/include/mgba-util/platform/windows/threading.h +++ b/include/mgba-util/platform/windows/threading.h @@ -16,7 +16,6 @@ typedef THREAD_ENTRY ThreadEntry(LPVOID); typedef HANDLE Thread; typedef CRITICAL_SECTION Mutex; typedef CONDITION_VARIABLE Condition; -typedef DWORD ThreadLocal; static inline int MutexInit(Mutex* mutex) { InitializeCriticalSection(mutex); @@ -89,6 +88,9 @@ static inline int ThreadSetName(const char* name) { return -1; } +#if (__STDC_VERSION__ < 201112L) || (__STDC_NO_THREADS__ == 1) +typedef DWORD ThreadLocal; + static inline void ThreadLocalInitKey(ThreadLocal* key) { *key = TlsAlloc(); } @@ -100,5 +102,6 @@ static inline void ThreadLocalSetKey(ThreadLocal key, void* value) { static inline void* ThreadLocalGetValue(ThreadLocal key) { return TlsGetValue(key); } +#endif #endif diff --git a/include/mgba/internal/gb/serialize.h b/include/mgba/internal/gb/serialize.h index bffdb56f2..2332171ab 100644 --- a/include/mgba/internal/gb/serialize.h +++ b/include/mgba/internal/gb/serialize.h @@ -442,7 +442,7 @@ struct GBSerializedState { int32_t lastSample; uint8_t sampleIndex; uint8_t reserved[3]; - struct mStereoSample currentSamples[32]; + struct mStereoSample currentSamples[GB_MAX_SAMPLES]; } audio2; uint8_t oam[GB_SIZE_OAM]; @@ -473,6 +473,8 @@ struct GBSerializedState { }; #pragma pack(pop) +static_assert(sizeof(struct GBSerializedState) == 0x11800, "GB savestate struct sized wrong"); + bool GBDeserialize(struct GB* gb, const struct GBSerializedState* state); void GBSerialize(struct GB* gb, struct GBSerializedState* state); diff --git a/include/mgba/internal/gba/serialize.h b/include/mgba/internal/gba/serialize.h index 07223ea3f..cb1a3b384 100644 --- a/include/mgba/internal/gba/serialize.h +++ b/include/mgba/internal/gba/serialize.h @@ -402,7 +402,7 @@ struct GBASerializedState { int8_t chB[16]; } samples; - struct mStereoSample currentSamples[16]; + struct mStereoSample currentSamples[GBA_MAX_SAMPLES]; uint32_t reserved[12]; @@ -414,6 +414,8 @@ struct GBASerializedState { uint8_t wram[SIZE_WORKING_RAM]; }; +static_assert(sizeof(struct GBASerializedState) == 0x61000, "GBA savestate struct sized wrong"); + struct VDir; void GBASerialize(struct GBA* gba, struct GBASerializedState* state);