From 974edaa649287b7d03ba60d211b72c6a75a056af Mon Sep 17 00:00:00 2001 From: Marcin Chojnacki Date: Fri, 26 Aug 2022 04:03:26 +0200 Subject: [PATCH] Initial macOS port bringup (#52) --- src/CMakeLists.txt | 6 +++-- src/Cafe/CafeSystem.cpp | 2 +- src/Cafe/Filesystem/FST/FST.cpp | 2 +- src/Cafe/HW/Espresso/Debugger/Debugger.cpp | 4 ++-- src/Cafe/HW/Espresso/PPCTimer.cpp | 8 +++---- .../HW/Espresso/Recompiler/PPCRecompiler.cpp | 2 +- src/Cafe/HW/Latte/Core/LatteIndices.cpp | 12 +++++----- src/Cafe/HW/Latte/Core/LatteShaderCache.cpp | 6 ++--- src/Cafe/HW/Latte/Core/LatteTextureCache.cpp | 2 +- .../Latte/LatteAddrLib/LatteAddrLib_Coord.cpp | 2 +- .../Latte/Renderer/OpenGL/OpenGLRenderer.cpp | 15 ++++++++---- .../HW/Latte/Renderer/Vulkan/VulkanAPI.cpp | 2 +- .../Latte/Renderer/Vulkan/VulkanRenderer.cpp | 9 ++++--- src/Cafe/HW/MMU/MMU.h | 3 +++ src/Cafe/OS/libs/coreinit/coreinit_Init.cpp | 2 +- src/Cafe/OS/libs/coreinit/coreinit_MCP.cpp | 2 +- .../OS/libs/coreinit/coreinit_MEM_FrmHeap.cpp | 3 ++- src/Cafe/OS/libs/nlibcurl/nlibcurl.cpp | 2 +- src/Cafe/OS/libs/nn_save/nn_save.cpp | 2 +- src/Cafe/OS/libs/nsyshid/nsyshid.cpp | 2 +- src/Cafe/OS/libs/nsysnet/nsysnet.cpp | 4 ++-- src/Cafe/OS/libs/nsysnet/nsysnet.h | 2 +- src/Cemu/ExpressionParser/ExpressionParser.h | 2 +- src/Cemu/Logging/CemuLogging.cpp | 4 ++-- src/Cemu/PPCAssembler/ppcAssembler.cpp | 2 +- src/Cemu/nex/nex.cpp | 2 +- src/Cemu/nex/prudp.cpp | 2 +- src/Common/CMakeLists.txt | 4 ++-- .../ExceptionHandler/ExceptionHandler.cpp | 2 +- src/Common/platform.h | 15 ++++++------ src/Common/precompiled.h | 16 ++++++++++--- src/Common/socket.h | 2 +- src/Common/{linux => unix}/date.h | 0 src/Common/{linux => unix}/fast_float.h | 0 src/Common/{linux => unix}/platform.cpp | 0 src/Common/{linux => unix}/platform.h | 3 --- src/asm/CMakeLists.txt | 8 +++++++ src/audio/IAudioAPI.cpp | 4 ++-- src/audio/IAudioAPI.h | 4 ++-- src/config/XMLConfig.h | 2 +- src/gui/CemuApp.cpp | 6 ++--- src/gui/CemuUpdateWindow.cpp | 2 +- src/gui/GameProfileWindow.cpp | 4 ++-- src/gui/GeneralSettings2.cpp | 12 +++++----- src/gui/GettingStartedDialog.cpp | 4 ++-- src/gui/GraphicPacksWindow2.cpp | 4 ++-- src/gui/MainWindow.cpp | 10 ++++---- src/gui/PadViewFrame.cpp | 4 ++-- src/gui/TitleManager.cpp | 4 ++-- src/gui/debugger/DebuggerWindow2.cpp | 2 +- src/gui/guiWrapper.cpp | 4 ++-- src/gui/guiWrapper.h | 2 +- src/gui/input/InputSettings2.cpp | 2 +- src/main.cpp | 24 ++++++++++--------- src/resource/CMakeLists.txt | 4 ++-- .../{linux => embedded}/DEBUGGER_BP.hpng | 0 .../{linux => embedded}/DEBUGGER_BP_RED.hpng | 0 .../{linux => embedded}/DEBUGGER_GOTO.hpng | 0 .../{linux => embedded}/DEBUGGER_PAUSE.hpng | 0 .../{linux => embedded}/DEBUGGER_PLAY.hpng | 0 .../DEBUGGER_STEP_INTO.hpng | 0 .../DEBUGGER_STEP_OUT.hpng | 0 .../DEBUGGER_STEP_OVER.hpng | 0 .../{linux => embedded}/INPUT_CONNECTED.hpng | 0 .../INPUT_DISCONNECTED.hpng | 0 .../INPUT_LOW_BATTERY.hpng | 0 .../{linux => embedded}/M_WND_ICON128.xpm | 0 .../{linux => embedded}/PNG_HELP.hpng | 0 .../{linux => embedded}/PNG_REFRESH.hpng | 0 src/resource/{linux => embedded}/X_BOX.xpm | 0 .../{linux => embedded}/X_GAME_PROFILE.xpm | 0 .../{linux => embedded}/X_SETTINGS.xpm | 0 .../icons8-checkmark-yes-32.hpng | 0 .../{linux => embedded}/icons8-error-32.hpng | 0 .../{linux => embedded}/resources.cpp | 0 src/resource/{linux => embedded}/resources.h | 0 src/util/Fiber/Fiber.h | 2 +- src/util/Fiber/FiberUnix.cpp | 3 ++- src/util/MemMapper/MemMapperUnix.cpp | 2 +- src/util/MemMapper/MemMapperWin.cpp | 2 +- src/util/helpers/helpers.cpp | 10 ++++---- src/util/helpers/helpers.h | 2 +- src/util/libusbWrapper/libusbWrapper.cpp | 2 +- src/util/libusbWrapper/libusbWrapper.h | 2 +- 84 files changed, 157 insertions(+), 122 deletions(-) rename src/Common/{linux => unix}/date.h (100%) rename src/Common/{linux => unix}/fast_float.h (100%) rename src/Common/{linux => unix}/platform.cpp (100%) rename src/Common/{linux => unix}/platform.h (94%) rename src/resource/{linux => embedded}/DEBUGGER_BP.hpng (100%) rename src/resource/{linux => embedded}/DEBUGGER_BP_RED.hpng (100%) rename src/resource/{linux => embedded}/DEBUGGER_GOTO.hpng (100%) rename src/resource/{linux => embedded}/DEBUGGER_PAUSE.hpng (100%) rename src/resource/{linux => embedded}/DEBUGGER_PLAY.hpng (100%) rename src/resource/{linux => embedded}/DEBUGGER_STEP_INTO.hpng (100%) rename src/resource/{linux => embedded}/DEBUGGER_STEP_OUT.hpng (100%) rename src/resource/{linux => embedded}/DEBUGGER_STEP_OVER.hpng (100%) rename src/resource/{linux => embedded}/INPUT_CONNECTED.hpng (100%) rename src/resource/{linux => embedded}/INPUT_DISCONNECTED.hpng (100%) rename src/resource/{linux => embedded}/INPUT_LOW_BATTERY.hpng (100%) rename src/resource/{linux => embedded}/M_WND_ICON128.xpm (100%) rename src/resource/{linux => embedded}/PNG_HELP.hpng (100%) rename src/resource/{linux => embedded}/PNG_REFRESH.hpng (100%) rename src/resource/{linux => embedded}/X_BOX.xpm (100%) rename src/resource/{linux => embedded}/X_GAME_PROFILE.xpm (100%) rename src/resource/{linux => embedded}/X_SETTINGS.xpm (100%) rename src/resource/{linux => embedded}/icons8-checkmark-yes-32.hpng (100%) rename src/resource/{linux => embedded}/icons8-error-32.hpng (100%) rename src/resource/{linux => embedded}/resources.cpp (100%) rename src/resource/{linux => embedded}/resources.h (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 005cfa2a..70db09a5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,11 +20,13 @@ if(MSVC) # _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING # _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS elseif(UNIX) + if(NOT APPLE) + add_definitions(-DVK_USE_PLATFORM_XLIB_KHR) # legacy. Do we need to support XLIB surfaces? + add_definitions(-DVK_USE_PLATFORM_XCB_KHR) + endif() add_definitions(-fms-extensions) add_definitions(-fms-compatibility-version=19.14) add_definitions(-fdelayed-template-parsing) - add_definitions(-DVK_USE_PLATFORM_XLIB_KHR) # legacy. Do we need to support XLIB surfaces? - add_definitions(-DVK_USE_PLATFORM_XCB_KHR) add_definitions(-maes) # warnings add_compile_options(-Wno-switch -Wno-ignored-attributes -Wno-deprecated-enum-enum-conversion -Wno-ambiguous-reversed-operator) diff --git a/src/Cafe/CafeSystem.cpp b/src/Cafe/CafeSystem.cpp index 53a9ec6a..f8bce458 100644 --- a/src/Cafe/CafeSystem.cpp +++ b/src/Cafe/CafeSystem.cpp @@ -364,7 +364,7 @@ void cemu_initForGame() time_t theTime = (time(NULL) - 946684800); { tm* lt = localtime(&theTime); -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS theTime = _mkgmtime(lt); #else theTime = timegm(lt); diff --git a/src/Cafe/Filesystem/FST/FST.cpp b/src/Cafe/Filesystem/FST/FST.cpp index b9b511f1..a230a3a6 100644 --- a/src/Cafe/Filesystem/FST/FST.cpp +++ b/src/Cafe/Filesystem/FST/FST.cpp @@ -1029,7 +1029,7 @@ bool FSTVerifier::VerifyContentFile(FileStream* fileContent, const NCrypto::AesK SHA256_Init(&sha256Ctx); while (remainingBytes > 0) { - uint32 bytesToRead = (uint32)std::min(remainingBytes, buffer.size()); + uint32 bytesToRead = (uint32)std::min(remainingBytes, (uint64)buffer.size()); uint32 bytesToReadPadded = ((bytesToRead + 0xF) & ~0xF); uint32 bytesRead = fileContent->readData(buffer.data(), bytesToReadPadded); if (bytesRead != bytesToReadPadded) diff --git a/src/Cafe/HW/Espresso/Debugger/Debugger.cpp b/src/Cafe/HW/Espresso/Debugger/Debugger.cpp index 51417633..fc015285 100644 --- a/src/Cafe/HW/Espresso/Debugger/Debugger.cpp +++ b/src/Cafe/HW/Espresso/Debugger/Debugger.cpp @@ -8,7 +8,7 @@ #include "Cafe/OS/libs/coreinit/coreinit.h" -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS #include #endif @@ -158,7 +158,7 @@ void debugger_updateMemoryBreakpoint(DebuggerBreakpoint* bp) { std::vector schedulerThreadHandles = coreinit::OSGetSchedulerThreads(); -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS debuggerState.activeMemoryBreakpoint = bp; for (auto& hThreadNH : schedulerThreadHandles) { diff --git a/src/Cafe/HW/Espresso/PPCTimer.cpp b/src/Cafe/HW/Espresso/PPCTimer.cpp index 160b776a..cf0b60ef 100644 --- a/src/Cafe/HW/Espresso/PPCTimer.cpp +++ b/src/Cafe/HW/Espresso/PPCTimer.cpp @@ -5,7 +5,7 @@ #include "util/helpers/fspinlock.h" #include "util/highresolutiontimer/HighResolutionTimer.h" -#if BOOST_OS_LINUX > 0 +#if BOOST_OS_LINUX || BOOST_OS_MACOS static __inline__ unsigned __int64 _umul128(unsigned __int64, unsigned __int64, @@ -113,7 +113,7 @@ uint64 PPCTimer_microsecondsToTsc(uint64 us) uint64 PPCTimer_tscToMicroseconds(uint64 us) { uint128_t r{}; - #if BOOST_OS_WINDOWS > 0 + #if BOOST_OS_WINDOWS r.low = _umul128(us, 1000000ULL, &r.high); #else r.low = _umul128(us, 1000000ULL, (unsigned long long*)&r.high); @@ -153,7 +153,7 @@ uint64 PPCTimer_getFromRDTSC() rdtscDif = rdtscDif & ~(uint64)((sint64)rdtscDif >> 63); uint128_t diff{}; -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS diff.low = _umul128(rdtscDif, Espresso::CORE_CLOCK, &diff.high); #else diff.low = _umul128(rdtscDif, Espresso::CORE_CLOCK, (unsigned long long*)&diff.high); @@ -163,7 +163,7 @@ uint64 PPCTimer_getFromRDTSC() _rdtscLastMeasure = rdtscCurrentMeasure; // only travel forward in time uint8 c = 0; - #if BOOST_OS_WINDOWS > 0 + #if BOOST_OS_WINDOWS c = _addcarry_u64(c, _rdtscAcc.low, diff.low, &_rdtscAcc.low); _addcarry_u64(c, _rdtscAcc.high, diff.high, &_rdtscAcc.high); #else diff --git a/src/Cafe/HW/Espresso/Recompiler/PPCRecompiler.cpp b/src/Cafe/HW/Espresso/Recompiler/PPCRecompiler.cpp index 75adee35..e98e410a 100644 --- a/src/Cafe/HW/Espresso/Recompiler/PPCRecompiler.cpp +++ b/src/Cafe/HW/Espresso/Recompiler/PPCRecompiler.cpp @@ -72,7 +72,7 @@ void PPCRecompiler_recompileIfUnvisited(uint32 enterAddress) void PPCRecompiler_enter(PPCInterpreter_t* hCPU, PPCREC_JUMP_ENTRY funcPtr) { -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS uint32 prevState = _controlfp(0, 0); _controlfp(_RC_NEAR, _MCW_RC); PPCRecompiler_enterRecompilerCode((uint64)funcPtr, (uint64)hCPU); diff --git a/src/Cafe/HW/Latte/Core/LatteIndices.cpp b/src/Cafe/HW/Latte/Core/LatteIndices.cpp index 2ffd1d0a..7edaad00 100644 --- a/src/Cafe/HW/Latte/Core/LatteIndices.cpp +++ b/src/Cafe/HW/Latte/Core/LatteIndices.cpp @@ -284,7 +284,7 @@ void LatteIndices_generateAutoLineLoopIndices(void* indexDataOutput, uint32 coun indexMax = std::max(count, 1u) - 1; } -#if BOOST_OS_LINUX +#if BOOST_OS_LINUX || BOOST_OS_MACOS #pragma clang attribute push (__attribute__((target("avx2"))), apply_to=function) #endif @@ -352,11 +352,11 @@ void LatteIndices_fastConvertU16_AVX2(const void* indexDataInput, void* indexDat indexMin = std::min(indexMin, _minIndex); } -#if BOOST_OS_LINUX +#if BOOST_OS_LINUX || BOOST_OS_MACOS #pragma clang attribute pop #endif -#if BOOST_OS_LINUX +#if BOOST_OS_LINUX || BOOST_OS_MACOS #pragma clang attribute push (__attribute__((target("avx2"))), apply_to=function) #endif @@ -423,11 +423,11 @@ void LatteIndices_fastConvertU16_SSE41(const void* indexDataInput, void* indexDa indexMin = std::min(indexMin, _minIndex); } -#if BOOST_OS_LINUX +#if BOOST_OS_LINUX || BOOST_OS_MACOS #pragma clang attribute pop #endif -#if BOOST_OS_LINUX +#if BOOST_OS_LINUX || BOOST_OS_MACOS #pragma clang attribute push (__attribute__((target("avx2"))), apply_to=function) #endif @@ -497,7 +497,7 @@ void LatteIndices_fastConvertU32_AVX2(const void* indexDataInput, void* indexDat indexMin = std::min(indexMin, _minIndex); } -#if BOOST_OS_LINUX +#if BOOST_OS_LINUX || BOOST_OS_MACOS #pragma clang attribute pop #endif diff --git a/src/Cafe/HW/Latte/Core/LatteShaderCache.cpp b/src/Cafe/HW/Latte/Core/LatteShaderCache.cpp index b7aedad1..fe1388f0 100644 --- a/src/Cafe/HW/Latte/Core/LatteShaderCache.cpp +++ b/src/Cafe/HW/Latte/Core/LatteShaderCache.cpp @@ -27,7 +27,7 @@ #include -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS #include #endif @@ -189,7 +189,7 @@ void LatteShaderCache_load() const auto timeLoadStart = now_cached(); // remember current amount of committed memory -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS PROCESS_MEMORY_COUNTERS pmc1; GetProcessMemoryInfo(GetCurrentProcess(), &pmc1, sizeof(PROCESS_MEMORY_COUNTERS)); LONGLONG totalMem1 = pmc1.PagefileUsage; @@ -285,7 +285,7 @@ void LatteShaderCache_load() LatteShaderCache_updateCompileQueue(0); // write load time and RAM usage to log file (in dev build) -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS const auto timeLoadEnd = now_cached(); const auto timeLoad = std::chrono::duration_cast(timeLoadEnd - timeLoadStart).count(); PROCESS_MEMORY_COUNTERS pmc2; diff --git a/src/Cafe/HW/Latte/Core/LatteTextureCache.cpp b/src/Cafe/HW/Latte/Core/LatteTextureCache.cpp index ae7ac4d0..b2f6ec5a 100644 --- a/src/Cafe/HW/Latte/Core/LatteTextureCache.cpp +++ b/src/Cafe/HW/Latte/Core/LatteTextureCache.cpp @@ -145,7 +145,7 @@ uint32 LatteTexture_CalculateTextureDataHash(LatteTexture* hostTexture) bool isCompressedFormat = hostTexture->IsCompressedFormat(); if( isCompressedFormat == false ) { - #if BOOST_OS_WINDOWS > 0 + #if BOOST_OS_WINDOWS if (_cpuExtension_AVX2) { __m256i h256 = { 0 }; diff --git a/src/Cafe/HW/Latte/LatteAddrLib/LatteAddrLib_Coord.cpp b/src/Cafe/HW/Latte/LatteAddrLib/LatteAddrLib_Coord.cpp index 8dc69b57..bc43202a 100644 --- a/src/Cafe/HW/Latte/LatteAddrLib/LatteAddrLib_Coord.cpp +++ b/src/Cafe/HW/Latte/LatteAddrLib/LatteAddrLib_Coord.cpp @@ -7,7 +7,7 @@ using namespace Latte; namespace LatteAddrLib { -#if BOOST_OS_LINUX +#if BOOST_OS_LINUX || BOOST_OS_MACOS unsigned char _BitScanReverse(uint32* _Index, uint32 _Mask) { if (!_Mask) diff --git a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp index d89cbcac..509193bb 100644 --- a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp @@ -95,7 +95,7 @@ OpenGLRenderer::OpenGLRenderer() glRendererState.uploadIndex = 0; } -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS try { m_dxgi_wrapper = std::make_unique(); @@ -191,7 +191,7 @@ void OpenGLRenderer::DeleteFontTextures() typedef void(*GL_IMPORT)(); -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS GL_IMPORT _GetOpenGLFunction(HMODULE hLib, const char* name) { GL_IMPORT r = (GL_IMPORT)wglGetProcAddress(name); @@ -207,7 +207,7 @@ void LoadOpenGLImports() #include "Common/GLInclude/glFunctions.h" #undef GLFUNC } -#else +#elif BOOST_OS_LINUX GL_IMPORT _GetOpenGLFunction(void* hLib, PFNGLXGETPROCADDRESSPROC func, const char* name) { GL_IMPORT r = (GL_IMPORT)func((const GLubyte*)name); @@ -233,6 +233,11 @@ void LoadOpenGLImports() #include "Common/GLInclude/glFunctions.h" #undef GLFUNC } +#elif BOOST_OS_MACOS +void LoadOpenGLImports() +{ + cemu_assert_unimplemented(); +} #endif void OpenGLRenderer::Initialize() @@ -244,7 +249,7 @@ void OpenGLRenderer::Initialize() LoadOpenGLImports(); GetVendorInformation(); -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS if (wglSwapIntervalEXT) wglSwapIntervalEXT(0); // disable V-Sync per default #endif @@ -349,7 +354,7 @@ void OpenGLRenderer::NotifyLatteCommandProcessorIdle() void OpenGLRenderer::EnableVSync(int state) { -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS if(wglSwapIntervalEXT) wglSwapIntervalEXT(state); // 1 = enabled, 0 = disabled #else diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanAPI.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanAPI.cpp index c657cba7..a60720d1 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanAPI.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanAPI.cpp @@ -2,7 +2,7 @@ #define VKFUNC_DEFINE #include "Cafe/HW/Latte/Renderer/Vulkan/VulkanAPI.h" -#if BOOST_OS_LINUX +#if BOOST_OS_LINUX || BOOST_OS_MACOS #include #endif diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp index a792fc69..383c0fd8 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp @@ -104,7 +104,7 @@ std::vector VulkanRenderer::GetDevices() requiredExtensions.emplace_back(VK_KHR_SURFACE_EXTENSION_NAME); #if BOOST_OS_WINDOWS requiredExtensions.emplace_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); - #else + #elif BOOST_OS_LINUX requiredExtensions.emplace_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME); #endif @@ -1143,7 +1143,7 @@ std::vector VulkanRenderer::CheckInstanceExtensionSupport(FeatureCo requiredInstanceExtensions.emplace_back(VK_KHR_SURFACE_EXTENSION_NAME); #if BOOST_OS_WINDOWS requiredInstanceExtensions.emplace_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); - #else + #elif BOOST_OS_LINUX requiredInstanceExtensions.emplace_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME); #endif if (cafeLog_isLoggingFlagEnabled(LOG_TYPE_VULKAN_VALIDATION)) @@ -1319,8 +1319,11 @@ VkSurfaceKHR VulkanRenderer::CreateFramebufferSurface(VkInstance instance, struc { #if BOOST_OS_WINDOWS return CreateWinSurface(instance, windowInfo.hwnd); -#else +#elif BOOST_OS_LINUX return CreateXlibSurface(instance, windowInfo.xlib_display, windowInfo.xlib_window); +#elif BOOST_OS_MACOS + cemu_assert_unimplemented(); + return nullptr; #endif } diff --git a/src/Cafe/HW/MMU/MMU.h b/src/Cafe/HW/MMU/MMU.h index 5169ef7e..67c14ba3 100644 --- a/src/Cafe/HW/MMU/MMU.h +++ b/src/Cafe/HW/MMU/MMU.h @@ -201,6 +201,9 @@ static uint16 CPU_swapEndianU16(uint16 v) #elif BOOST_OS_LINUX #define CPU_swapEndianU64(_v) bswap_64((uint64)(_v)) #define CPU_swapEndianU32(_v) bswap_32((uint32)(_v)) +#elif BOOST_OS_MACOS +#define CPU_swapEndianU64(_v) OSSwapInt64((uint64)(_v)) +#define CPU_swapEndianU32(_v) OSSwapInt32((uint32)(_v)) #endif // direct memory access (no hardware interface access) diff --git a/src/Cafe/OS/libs/coreinit/coreinit_Init.cpp b/src/Cafe/OS/libs/coreinit/coreinit_Init.cpp index 4cedc7fb..9bb49741 100644 --- a/src/Cafe/OS/libs/coreinit/coreinit_Init.cpp +++ b/src/Cafe/OS/libs/coreinit/coreinit_Init.cpp @@ -78,7 +78,7 @@ void CafeInit() rpxPathStart = 0; } - std::string_view rpxFileName = std::basic_string_view(_pathToExecutable.data() + rpxPathStart, _pathToExecutable.data() + _pathToExecutable.size()); + std::string_view rpxFileName(_pathToExecutable.data() + rpxPathStart, _pathToExecutable.size() - rpxPathStart); argStorageIndex = 0; _coreinitInfo->argc = 0; diff --git a/src/Cafe/OS/libs/coreinit/coreinit_MCP.cpp b/src/Cafe/OS/libs/coreinit/coreinit_MCP.cpp index fbc42683..f4080a23 100644 --- a/src/Cafe/OS/libs/coreinit/coreinit_MCP.cpp +++ b/src/Cafe/OS/libs/coreinit/coreinit_MCP.cpp @@ -424,7 +424,7 @@ typedef struct static_assert(sizeof(UCParamStruct_t) == 0x54); // unsure -#if BOOST_OS_LINUX +#if BOOST_OS_LINUX || BOOST_OS_MACOS #define _strcmpi strcasecmp #endif diff --git a/src/Cafe/OS/libs/coreinit/coreinit_MEM_FrmHeap.cpp b/src/Cafe/OS/libs/coreinit/coreinit_MEM_FrmHeap.cpp index 88c52901..b33feb4b 100644 --- a/src/Cafe/OS/libs/coreinit/coreinit_MEM_FrmHeap.cpp +++ b/src/Cafe/OS/libs/coreinit/coreinit_MEM_FrmHeap.cpp @@ -63,7 +63,8 @@ namespace coreinit bool negativeAlignment = alignment < 0; if (negativeAlignment) alignment = -alignment; - if (!std::has_single_bit((uint32)alignment)) + uint32 bits = (uint32)alignment; + if (bits == 0 || (bits & (bits - 1)) != 0) { cemuLog_log(LogType::APIErrors, "MEMGetAllocatableSizeForFrmHeapEx(): Invalid alignment"); return 0; diff --git a/src/Cafe/OS/libs/nlibcurl/nlibcurl.cpp b/src/Cafe/OS/libs/nlibcurl/nlibcurl.cpp index 4208c1ff..f4451ce5 100644 --- a/src/Cafe/OS/libs/nlibcurl/nlibcurl.cpp +++ b/src/Cafe/OS/libs/nlibcurl/nlibcurl.cpp @@ -455,7 +455,7 @@ void export_curl_multi_fdset(PPCInterpreter_t* hCPU) ppcDefineParamMEMPTR(exceptionFd, wu_fd_set, 3); ppcDefineParamU32BEPtr(maxFd, 4); -#if BOOST_OS_LINUX > 0 +#if BOOST_OS_LINUX || BOOST_OS_MACOS cemuLog_log(LogType::Force, "curl_multi_fdset(...) - todo"); osLib_returnFromFunction(hCPU, 0); diff --git a/src/Cafe/OS/libs/nn_save/nn_save.cpp b/src/Cafe/OS/libs/nn_save/nn_save.cpp index 64bbdc2f..a0a8ff7b 100644 --- a/src/Cafe/OS/libs/nn_save/nn_save.cpp +++ b/src/Cafe/OS/libs/nn_save/nn_save.cpp @@ -242,7 +242,7 @@ namespace save } catch (const std::exception& ex) { -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS std::wstringstream errorMsg; errorMsg << L"Couldn't move your save files!" << std::endl << std::endl; errorMsg << L"Error: " << ex.what() << std::endl << std::endl; diff --git a/src/Cafe/OS/libs/nsyshid/nsyshid.cpp b/src/Cafe/OS/libs/nsyshid/nsyshid.cpp index 4789d3e4..d43b486e 100644 --- a/src/Cafe/OS/libs/nsyshid/nsyshid.cpp +++ b/src/Cafe/OS/libs/nsyshid/nsyshid.cpp @@ -3,7 +3,7 @@ #include #include "nsyshid.h" -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS #include #include diff --git a/src/Cafe/OS/libs/nsysnet/nsysnet.cpp b/src/Cafe/OS/libs/nsysnet/nsysnet.cpp index 0a01ca3e..b49d2e80 100644 --- a/src/Cafe/OS/libs/nsysnet/nsysnet.cpp +++ b/src/Cafe/OS/libs/nsysnet/nsysnet.cpp @@ -6,7 +6,7 @@ #include "Common/socket.h" -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS #define WU_AF_INET 2 @@ -2085,7 +2085,7 @@ void nsysnet_load() osLib_addFunction("nsysnet", "NSSLExportInternalClientCertificate", nsysnet::export_NSSLExportInternalClientCertificate); } -#if BOOST_OS_LINUX +#if BOOST_OS_LINUX || BOOST_OS_MACOS void nsysnet_notifyCloseSharedSocket(SOCKET existingSocket) { diff --git a/src/Cafe/OS/libs/nsysnet/nsysnet.h b/src/Cafe/OS/libs/nsysnet/nsysnet.h index bb0ad2b0..fa2f2ca4 100644 --- a/src/Cafe/OS/libs/nsysnet/nsysnet.h +++ b/src/Cafe/OS/libs/nsysnet/nsysnet.h @@ -2,7 +2,7 @@ #include #include -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS #include #else #include diff --git a/src/Cemu/ExpressionParser/ExpressionParser.h b/src/Cemu/ExpressionParser/ExpressionParser.h index 5f7bf406..ab14dc5d 100644 --- a/src/Cemu/ExpressionParser/ExpressionParser.h +++ b/src/Cemu/ExpressionParser/ExpressionParser.h @@ -12,7 +12,7 @@ #include #ifdef __clang__ -#include "Common/linux/fast_float.h" +#include "Common/unix/fast_float.h" #define _EP_FROM_CHARS_DBL(...) _convFastFloatResult(fast_float::from_chars(__VA_ARGS__)) inline std::from_chars_result _convFastFloatResult(fast_float::from_chars_result r) diff --git a/src/Cemu/Logging/CemuLogging.cpp b/src/Cemu/Logging/CemuLogging.cpp index c22ad30e..6684ee9d 100644 --- a/src/Cemu/Logging/CemuLogging.cpp +++ b/src/Cemu/Logging/CemuLogging.cpp @@ -200,7 +200,7 @@ void cafeLog_log(uint32 type, const char* format, ...) char logTempStr[2048]; va_list(args); va_start(args, format); -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS vsprintf_s(logTempStr, format, args); #else vsprintf(logTempStr, format, args); @@ -226,7 +226,7 @@ void cafeLog_logW(uint32 type, const wchar_t* format, ...) wchar_t logTempStr[2048]; va_list(args); va_start(args, format); -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS vswprintf_s(logTempStr, format, args); #else vswprintf(logTempStr, 2048, format, args); diff --git a/src/Cemu/PPCAssembler/ppcAssembler.cpp b/src/Cemu/PPCAssembler/ppcAssembler.cpp index 647d683d..c8c28191 100644 --- a/src/Cemu/PPCAssembler/ppcAssembler.cpp +++ b/src/Cemu/PPCAssembler/ppcAssembler.cpp @@ -628,7 +628,7 @@ public: ppcAssembler_setError(assemblerCtx->ctx, fmt::format("\'{}\' does not end with valid memory register syntax. Memory operand must have the form offset(gpr). Example: 0x20(r3)", svOpText)); return false; } - std::string_view svExpressionPart(startPtr, endPtr); + std::string_view svExpressionPart(startPtr, endPtr - startPtr); std::string_view svRegPart(memoryRegBegin, memoryRegEnd - memoryRegBegin); sint32 memGpr = _parseRegIndex(svRegPart, "r"); //if (_ppcAssembler_parseRegister(svRegPart, "r", memGpr) == false || (memGpr < 0 || memGpr >= 32)) diff --git a/src/Cemu/nex/nex.cpp b/src/Cemu/nex/nex.cpp index 8779043c..147d37da 100644 --- a/src/Cemu/nex/nex.cpp +++ b/src/Cemu/nex/nex.cpp @@ -5,7 +5,7 @@ #include "util/crypto/md5.h" // for inet_pton: -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS #include #else #include diff --git a/src/Cemu/nex/prudp.cpp b/src/Cemu/nex/prudp.cpp index c60e4cc6..d3dddda5 100644 --- a/src/Cemu/nex/prudp.cpp +++ b/src/Cemu/nex/prudp.cpp @@ -529,7 +529,7 @@ prudpClient::prudpClient(uint32 dstIp, uint16 dstPort, const char* key) : prudpC break; } // set socket to non-blocking mode -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS u_long nonBlockingMode = 1; // 1 to enable non-blocking socket ioctlsocket(socketUdp, FIONBIO, &nonBlockingMode); #else diff --git a/src/Common/CMakeLists.txt b/src/Common/CMakeLists.txt index 5af5898e..bee159cd 100644 --- a/src/Common/CMakeLists.txt +++ b/src/Common/CMakeLists.txt @@ -17,8 +17,8 @@ PRIVATE else() target_sources(CemuCommon PRIVATE - linux/platform.cpp - linux/platform.h + unix/platform.cpp + unix/platform.h ) endif() diff --git a/src/Common/ExceptionHandler/ExceptionHandler.cpp b/src/Common/ExceptionHandler/ExceptionHandler.cpp index 6824a5a7..4e9fc36e 100644 --- a/src/Common/ExceptionHandler/ExceptionHandler.cpp +++ b/src/Common/ExceptionHandler/ExceptionHandler.cpp @@ -1,7 +1,7 @@ #include "Common/precompiled.h" #include "Cafe/CafeSystem.h" -#if BOOST_OS_LINUX +#if BOOST_OS_LINUX || BOOST_OS_MACOS #include #include #endif diff --git a/src/Common/platform.h b/src/Common/platform.h index d47bcf74..901bfda8 100644 --- a/src/Common/platform.h +++ b/src/Common/platform.h @@ -6,11 +6,12 @@ #if BOOST_OS_WINDOWS #include "Common/windows/platform.h" #elif BOOST_OS_LINUX -#include "byteswap.h" -//#include -// #include -#include "Common/linux/platform.h" - +#include +#include +#include +#include +#include "Common/unix/platform.h" #elif BOOST_OS_MACOS - -#endif \ No newline at end of file +#include +#include "Common/unix/platform.h" +#endif diff --git a/src/Common/precompiled.h b/src/Common/precompiled.h index de9c8837..4ced91a4 100644 --- a/src/Common/precompiled.h +++ b/src/Common/precompiled.h @@ -144,22 +144,32 @@ inline sint16 _swapEndianS16(sint16 v) { return (sint16)(((uint16)v >> 8) | ((uint16)v << 8)); } -#endif - -#if BOOST_OS_LINUX +#else inline uint64 _swapEndianU64(uint64 v) { +#if BOOST_OS_MACOS + return OSSwapInt64(v); +#else return bswap_64(v); +#endif } inline uint32 _swapEndianU32(uint32 v) { +#if BOOST_OS_MACOS + return OSSwapInt32(v); +#else return bswap_32(v); +#endif } inline sint32 _swapEndianS32(sint32 v) { +#if BOOST_OS_MACOS + return (sint32)OSSwapInt32((uint32)v); +#else return (sint32)bswap_32((uint32)v); +#endif } inline uint16 _swapEndianU16(uint16 v) diff --git a/src/Common/socket.h b/src/Common/socket.h index 2a33d737..37d53c09 100644 --- a/src/Common/socket.h +++ b/src/Common/socket.h @@ -1,6 +1,6 @@ #pragma once -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS #include typedef int socklen_t; diff --git a/src/Common/linux/date.h b/src/Common/unix/date.h similarity index 100% rename from src/Common/linux/date.h rename to src/Common/unix/date.h diff --git a/src/Common/linux/fast_float.h b/src/Common/unix/fast_float.h similarity index 100% rename from src/Common/linux/fast_float.h rename to src/Common/unix/fast_float.h diff --git a/src/Common/linux/platform.cpp b/src/Common/unix/platform.cpp similarity index 100% rename from src/Common/linux/platform.cpp rename to src/Common/unix/platform.cpp diff --git a/src/Common/linux/platform.h b/src/Common/unix/platform.h similarity index 94% rename from src/Common/linux/platform.h rename to src/Common/unix/platform.h index f8aeff56..d7522200 100644 --- a/src/Common/linux/platform.h +++ b/src/Common/unix/platform.h @@ -32,9 +32,6 @@ inline uint32_t GetExceptionError() return errno; } -#include -#include -#include #undef False #undef True #undef None diff --git a/src/asm/CMakeLists.txt b/src/asm/CMakeLists.txt index ab9e701b..527fb1fe 100644 --- a/src/asm/CMakeLists.txt +++ b/src/asm/CMakeLists.txt @@ -12,7 +12,11 @@ set_source_files_properties(x64util_masm.asm PROPERTIES LANGUAGE ASM_MASM) ELSE() # NASM +IF (APPLE) +set(CMAKE_ASM_NASM_COMPILE_OBJECT " -g -Fdwarf -f macho64 --prefix _ -o ") +ELSE() set(CMAKE_ASM_NASM_COMPILE_OBJECT " -g -Fdwarf -f elf64 -o ") +ENDIF() set(CMAKE_ASM_NASM_LINK_EXECUTABLE "ld -fPIC -o ") enable_language(C ASM_NASM) @@ -22,7 +26,11 @@ x64util_nasm.asm ) set_source_files_properties(x64util_nasm.asm PROPERTIES LANGUAGE ASM_NASM) +IF (APPLE) +set_target_properties(CemuAsm PROPERTIES NASM_OBJ_FORMAT macho64) +ELSE() set_target_properties(CemuAsm PROPERTIES NASM_OBJ_FORMAT elf64) +ENDIF() set_target_properties(CemuAsm PROPERTIES LINKER_LANGUAGE C) ENDIF() diff --git a/src/audio/IAudioAPI.cpp b/src/audio/IAudioAPI.cpp index 1bbeac6d..29f74153 100644 --- a/src/audio/IAudioAPI.cpp +++ b/src/audio/IAudioAPI.cpp @@ -1,6 +1,6 @@ #include "IAudioAPI.h" -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS #include "XAudio2API.h" #include "XAudio27API.h" #include "DirectSoundAPI.h" @@ -37,7 +37,7 @@ void IAudioAPI::PrintLogging() void IAudioAPI::InitWFX(sint32 samplerate, sint32 channels, sint32 bits_per_sample) { -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS // move this to Windows-specific audio API implementations and use a cross-platform format here m_wfx.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; m_wfx.Format.nChannels = channels; diff --git a/src/audio/IAudioAPI.h b/src/audio/IAudioAPI.h index 25d416ba..935e3024 100644 --- a/src/audio/IAudioAPI.h +++ b/src/audio/IAudioAPI.h @@ -1,6 +1,6 @@ #pragma once -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS #include #endif @@ -64,7 +64,7 @@ public: static std::vector GetDevices(AudioAPI api); protected: -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS WAVEFORMATEXTENSIBLE m_wfx{}; #endif diff --git a/src/config/XMLConfig.h b/src/config/XMLConfig.h index d626484d..dacfc4d2 100644 --- a/src/config/XMLConfig.h +++ b/src/config/XMLConfig.h @@ -406,7 +406,7 @@ public: } FILE* file = nullptr; -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS file = _wfopen(tmp_name.c_str(), L"wb"); #else file = fopen(boost::nowide::narrow(tmp_name).c_str(), "wb"); diff --git a/src/gui/CemuApp.cpp b/src/gui/CemuApp.cpp index a13ba419..38decc2f 100644 --- a/src/gui/CemuApp.cpp +++ b/src/gui/CemuApp.cpp @@ -150,7 +150,7 @@ bool CemuApp::OnInit() int CemuApp::OnExit() { wxApp::OnExit(); -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS ExitProcess(0); #else exit(0); @@ -306,7 +306,7 @@ void CemuApp::CreateDefaultFiles(bool first_start) std::stringstream errorMsg; errorMsg << fmt::format(_("Couldn't create a required mlc01 subfolder or file!\n\nError: {0}\nTarget path:\n{1}").ToStdString(), ex.what(), boost::nowide::narrow(mlc)); -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS const DWORD lastError = GetLastError(); if (lastError != ERROR_SUCCESS) errorMsg << fmt::format("\n\n{}", GetSystemErrorMessage(lastError)); @@ -332,7 +332,7 @@ void CemuApp::CreateDefaultFiles(bool first_start) std::stringstream errorMsg; errorMsg << fmt::format(_("Couldn't create a required cemu directory or file!\n\nError: {0}").ToStdString(), ex.what()); -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS const DWORD lastError = GetLastError(); if (lastError != ERROR_SUCCESS) errorMsg << fmt::format("\n\n{}", GetSystemErrorMessage(lastError)); diff --git a/src/gui/CemuUpdateWindow.cpp b/src/gui/CemuUpdateWindow.cpp index f9aa3a88..d8b144f5 100644 --- a/src/gui/CemuUpdateWindow.cpp +++ b/src/gui/CemuUpdateWindow.cpp @@ -515,7 +515,7 @@ void CemuUpdateWindow::OnClose(wxCloseEvent& event) { event.Skip(); -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS if (m_restart_required && !m_restart_file.empty() && fs::exists(m_restart_file)) { PROCESS_INFORMATION pi{}; diff --git a/src/gui/GameProfileWindow.cpp b/src/gui/GameProfileWindow.cpp index a807e6cc..5fea17be 100644 --- a/src/gui/GameProfileWindow.cpp +++ b/src/gui/GameProfileWindow.cpp @@ -11,8 +11,8 @@ #include "gui/helpers/wxHelpers.h" #include "input/InputManager.h" -#if BOOST_OS_LINUX -#include "resource/linux/resources.h" +#if BOOST_OS_LINUX || BOOST_OS_MACOS +#include "resource/embedded/resources.h" #endif GameProfileWindow::GameProfileWindow(wxWindow* parent, uint64_t title_id) diff --git a/src/gui/GeneralSettings2.cpp b/src/gui/GeneralSettings2.cpp index 367fc902..012b8557 100644 --- a/src/gui/GeneralSettings2.cpp +++ b/src/gui/GeneralSettings2.cpp @@ -16,7 +16,7 @@ #include "config/CemuConfig.h" #include "audio/IAudioAPI.h" -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS #include "audio/DirectSoundAPI.h" #include "audio/XAudio27API.h" #endif @@ -31,7 +31,7 @@ #include "gui/dialogs/CreateAccount/wxCreateAccountDialog.h" #include "config/PermanentStorage.h" -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS #include #endif @@ -39,8 +39,8 @@ #include "config/ActiveSettings.h" #include "gui/helpers/wxHelpers.h" -#if BOOST_OS_LINUX > 0 -#include "resource/linux/resources.h" +#if BOOST_OS_LINUX || BOOST_OS_MACOS +#include "resource/embedded/resources.h" #endif #include "Cafe/CafeSystem.h" @@ -649,7 +649,7 @@ wxPanel* GeneralSettings2::AddAccountPage(wxNotebook* notebook) { m_account_information = new wxCollapsiblePane(online_panel, wxID_ANY, _("Account information")); - #if BOOST_OS_WINDOWS > 0 + #if BOOST_OS_WINDOWS m_account_information->GetControlWidget()->SetBackgroundColour(*wxWHITE); #endif auto win = m_account_information->GetPane(); @@ -1063,7 +1063,7 @@ void GeneralSettings2::ResetAccountInformation() // refresh pane size m_account_information->InvalidateBestSize(); - #if BOOST_OS_WINDOWS > 0 + #if BOOST_OS_WINDOWS m_account_information->OnStateChange(GetBestSize()); #endif } diff --git a/src/gui/GettingStartedDialog.cpp b/src/gui/GettingStartedDialog.cpp index 13fbfa94..30e5e557 100644 --- a/src/gui/GettingStartedDialog.cpp +++ b/src/gui/GettingStartedDialog.cpp @@ -15,8 +15,8 @@ #include "Cafe/TitleList/TitleList.h" -#if BOOST_OS_LINUX > 0 -#include "resource/linux/resources.h" +#if BOOST_OS_LINUX || BOOST_OS_MACOS +#include "resource/embedded/resources.h" #endif #include "wxHelper.h" diff --git a/src/gui/GraphicPacksWindow2.cpp b/src/gui/GraphicPacksWindow2.cpp index 53a65b69..7281edd1 100644 --- a/src/gui/GraphicPacksWindow2.cpp +++ b/src/gui/GraphicPacksWindow2.cpp @@ -10,8 +10,8 @@ #include "Cafe/CafeSystem.h" #include "Cafe/TitleList/TitleList.h" -#if BOOST_OS_LINUX > 0 -#include "resource/linux/resources.h" +#if BOOST_OS_LINUX || BOOST_OS_MACOS +#include "resource/embedded/resources.h" #endif // main.cpp diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index d84a12e7..877a95ee 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -50,12 +50,12 @@ #include "gui/input/InputSettings2.h" #include "input/InputManager.h" -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS #define exit(__c) ExitProcess(__c) #endif -#if BOOST_OS_LINUX > 0 -#include "resource/linux/resources.h" +#if BOOST_OS_LINUX || BOOST_OS_MACOS +#include "resource/embedded/resources.h" #endif #include "Cafe/TitleList/TitleInfo.h" @@ -296,7 +296,7 @@ MainWindow::MainWindow() SetClientSize(1280, 720); SetIcon(wxICON(M_WND_ICON128)); -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS HICON hWindowIcon = (HICON)LoadImageA(NULL, "M_WND_ICON16", IMAGE_ICON, 16, 16, LR_LOADFROMFILE); SendMessage(this->GetHWND(), WM_SETICON, ICON_SMALL, (LPARAM)hWindowIcon); #endif @@ -650,7 +650,7 @@ void MainWindow::OnInstallUpdate(wxCommandEvent& event) break; if (modalChoice == wxID_OK) { - #if BOOST_OS_LINUX + #if BOOST_OS_LINUX || BOOST_OS_MACOS fs::path dirPath((const char*)(openDirDialog.GetPath().fn_str())); #else fs::path dirPath(openDirDialog.GetPath().fn_str()); diff --git a/src/gui/PadViewFrame.cpp b/src/gui/PadViewFrame.cpp index 8ac016ee..89a85297 100644 --- a/src/gui/PadViewFrame.cpp +++ b/src/gui/PadViewFrame.cpp @@ -13,8 +13,8 @@ #include "gui/helpers/wxHelpers.h" #include "input/InputManager.h" -#if BOOST_OS_LINUX -#include "resource/linux/resources.h" +#if BOOST_OS_LINUX || BOOST_OS_MACOS +#include "resource/embedded/resources.h" #endif #include "wxHelper.h" diff --git a/src/gui/TitleManager.cpp b/src/gui/TitleManager.cpp index ba3cfc19..7ae72131 100644 --- a/src/gui/TitleManager.cpp +++ b/src/gui/TitleManager.cpp @@ -42,8 +42,8 @@ #include "Cafe/TitleList/TitleList.h" -#if BOOST_OS_LINUX -#include "resource/linux/resources.h" +#if BOOST_OS_LINUX || BOOST_OS_MACOS +#include "resource/embedded/resources.h" #endif #include "Cafe/TitleList/SaveList.h" diff --git a/src/gui/debugger/DebuggerWindow2.cpp b/src/gui/debugger/DebuggerWindow2.cpp index a2dee9cf..7465c712 100644 --- a/src/gui/debugger/DebuggerWindow2.cpp +++ b/src/gui/debugger/DebuggerWindow2.cpp @@ -20,7 +20,7 @@ #include "util/helpers/helpers.h" #if BOOST_OS_LINUX -#include "resource/linux/resources.h" +#include "resource/embedded/resources.h" #endif enum diff --git a/src/gui/guiWrapper.cpp b/src/gui/guiWrapper.cpp index eed08425..12b7bb50 100644 --- a/src/gui/guiWrapper.cpp +++ b/src/gui/guiWrapper.cpp @@ -159,9 +159,9 @@ typedef void GdkDisplay; void gui_initHandleContextFromWxWidgetsWindow(WindowHandleInfo& handleInfoOut, class wxWindow* wxw) { -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS handleInfoOut.hwnd = wxw->GetHWND(); -#else +#elif BOOST_OS_LINUX /* dynamically retrieve GTK imports so we dont have to include and link the whole lib */ void (*dyn_gtk_widget_realize)(GtkWidget *widget); dyn_gtk_widget_realize = (void(*)(GtkWidget* widget))dlsym(RTLD_NEXT, "gtk_widget_realize"); diff --git a/src/gui/guiWrapper.h b/src/gui/guiWrapper.h index 1dfb611f..ecea2f6e 100644 --- a/src/gui/guiWrapper.h +++ b/src/gui/guiWrapper.h @@ -2,7 +2,7 @@ #include -#if BOOST_OS_LINUX > 0 +#if BOOST_OS_LINUX #include "xcb/xproto.h" #endif diff --git a/src/gui/input/InputSettings2.cpp b/src/gui/input/InputSettings2.cpp index 556028fa..62a7045a 100644 --- a/src/gui/input/InputSettings2.cpp +++ b/src/gui/input/InputSettings2.cpp @@ -30,7 +30,7 @@ #include "util/EventService.h" #if BOOST_OS_LINUX -#include "resource/linux/resources.h" +#include "resource/embedded/resources.h" #endif bool g_inputConfigWindowHasFocus = false; diff --git a/src/main.cpp b/src/main.cpp index 98f829de..b7944696 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,14 +28,14 @@ #include "Cafe/OS/libs/vpad/vpad.h" #include "audio/IAudioAPI.h" -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS #pragma comment(lib,"Dbghelp.lib") #endif #define SDL_MAIN_HANDLED #include -#if BOOST_OS_LINUX > 0 +#if BOOST_OS_LINUX || BOOST_OS_MACOS #define _putenv(__s) putenv((char*)(__s)) #endif @@ -61,7 +61,7 @@ bool IsCemuhookLoaded() void checkForCemuhook() { - #if BOOST_OS_WINDOWS > 0 + #if BOOST_OS_WINDOWS // check if there is a dbghelp.dll in the current working directory if (!fs::exists(ActiveSettings::GetPath("cemuhook.dll"))) return; @@ -93,7 +93,7 @@ void checkForCemuhook() void logCPUAndMemoryInfo() { - #if BOOST_OS_WINDOWS > 0 + #if BOOST_OS_WINDOWS int CPUInfo[4] = { -1 }; unsigned nExIds, i = 0; char CPUBrandString[0x40]; @@ -129,7 +129,7 @@ bool IsRunningInWine() void checkForWine() { - #if BOOST_OS_WINDOWS > 0 + #if BOOST_OS_WINDOWS const HMODULE hmodule = GetModuleHandleA("ntdll.dll"); if (!hmodule) return; @@ -206,7 +206,7 @@ void reconfigureGLDrivers() std::string nvCacheDirEnvOption("__GL_SHADER_DISK_CACHE_PATH="); nvCacheDirEnvOption.append(_utf8Wrapper(nvCacheDir)); -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS std::wstring tmpW = boost::nowide::widen(nvCacheDirEnvOption); _wputenv(tmpW.c_str()); #else @@ -239,7 +239,7 @@ void mainEmulatorCommonInit() __cpuidex(cpuInfo, 0x7, 0); _cpuExtension_AVX2 = ((cpuInfo[1] >> 5) & 1) != 0; -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS executablePath.resize(4096); int i = GetModuleFileName(NULL, executablePath.data(), executablePath.size()); if(i >= 0) @@ -324,7 +324,7 @@ int mainEmulatorHLE() bool isConsoleConnected = false; void requireConsole() { - #if BOOST_OS_WINDOWS > 0 + #if BOOST_OS_WINDOWS if (isConsoleConnected) return; @@ -345,7 +345,7 @@ void HandlePostUpdate() const auto filename = ActiveSettings::GetFullPath().replace_extension("exe.backup"); if (fs::exists(filename)) { -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS HANDLE lock; do { @@ -374,7 +374,7 @@ void HandlePostUpdate() void ToolShaderCacheMerger(); -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS #ifndef PUBLIC_RELEASE #include @@ -411,7 +411,9 @@ int wWinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ L #else int main(int argc, char *argv[]) { +#if BOOST_OS_LINUX XInitThreads(); +#endif if (!LaunchSettings::HandleCommandline(argc, argv)) return 0; @@ -440,7 +442,7 @@ __declspec(dllexport) uint64 gameMeta_getTitleId() } /* Cemuhook loading */ -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS #pragma init_seg(".CRT$XCT") HANDLE dbgLib; diff --git a/src/resource/CMakeLists.txt b/src/resource/CMakeLists.txt index e0a6e3b2..85084bca 100644 --- a/src/resource/CMakeLists.txt +++ b/src/resource/CMakeLists.txt @@ -7,8 +7,8 @@ target_precompile_headers(CemuResource PRIVATE ../Common/precompiled.h) # icon resources if(UNIX) target_sources(CemuResource PRIVATE - linux/resources.cpp - linux/resources.h + embedded/resources.cpp + embedded/resources.h ) endif() diff --git a/src/resource/linux/DEBUGGER_BP.hpng b/src/resource/embedded/DEBUGGER_BP.hpng similarity index 100% rename from src/resource/linux/DEBUGGER_BP.hpng rename to src/resource/embedded/DEBUGGER_BP.hpng diff --git a/src/resource/linux/DEBUGGER_BP_RED.hpng b/src/resource/embedded/DEBUGGER_BP_RED.hpng similarity index 100% rename from src/resource/linux/DEBUGGER_BP_RED.hpng rename to src/resource/embedded/DEBUGGER_BP_RED.hpng diff --git a/src/resource/linux/DEBUGGER_GOTO.hpng b/src/resource/embedded/DEBUGGER_GOTO.hpng similarity index 100% rename from src/resource/linux/DEBUGGER_GOTO.hpng rename to src/resource/embedded/DEBUGGER_GOTO.hpng diff --git a/src/resource/linux/DEBUGGER_PAUSE.hpng b/src/resource/embedded/DEBUGGER_PAUSE.hpng similarity index 100% rename from src/resource/linux/DEBUGGER_PAUSE.hpng rename to src/resource/embedded/DEBUGGER_PAUSE.hpng diff --git a/src/resource/linux/DEBUGGER_PLAY.hpng b/src/resource/embedded/DEBUGGER_PLAY.hpng similarity index 100% rename from src/resource/linux/DEBUGGER_PLAY.hpng rename to src/resource/embedded/DEBUGGER_PLAY.hpng diff --git a/src/resource/linux/DEBUGGER_STEP_INTO.hpng b/src/resource/embedded/DEBUGGER_STEP_INTO.hpng similarity index 100% rename from src/resource/linux/DEBUGGER_STEP_INTO.hpng rename to src/resource/embedded/DEBUGGER_STEP_INTO.hpng diff --git a/src/resource/linux/DEBUGGER_STEP_OUT.hpng b/src/resource/embedded/DEBUGGER_STEP_OUT.hpng similarity index 100% rename from src/resource/linux/DEBUGGER_STEP_OUT.hpng rename to src/resource/embedded/DEBUGGER_STEP_OUT.hpng diff --git a/src/resource/linux/DEBUGGER_STEP_OVER.hpng b/src/resource/embedded/DEBUGGER_STEP_OVER.hpng similarity index 100% rename from src/resource/linux/DEBUGGER_STEP_OVER.hpng rename to src/resource/embedded/DEBUGGER_STEP_OVER.hpng diff --git a/src/resource/linux/INPUT_CONNECTED.hpng b/src/resource/embedded/INPUT_CONNECTED.hpng similarity index 100% rename from src/resource/linux/INPUT_CONNECTED.hpng rename to src/resource/embedded/INPUT_CONNECTED.hpng diff --git a/src/resource/linux/INPUT_DISCONNECTED.hpng b/src/resource/embedded/INPUT_DISCONNECTED.hpng similarity index 100% rename from src/resource/linux/INPUT_DISCONNECTED.hpng rename to src/resource/embedded/INPUT_DISCONNECTED.hpng diff --git a/src/resource/linux/INPUT_LOW_BATTERY.hpng b/src/resource/embedded/INPUT_LOW_BATTERY.hpng similarity index 100% rename from src/resource/linux/INPUT_LOW_BATTERY.hpng rename to src/resource/embedded/INPUT_LOW_BATTERY.hpng diff --git a/src/resource/linux/M_WND_ICON128.xpm b/src/resource/embedded/M_WND_ICON128.xpm similarity index 100% rename from src/resource/linux/M_WND_ICON128.xpm rename to src/resource/embedded/M_WND_ICON128.xpm diff --git a/src/resource/linux/PNG_HELP.hpng b/src/resource/embedded/PNG_HELP.hpng similarity index 100% rename from src/resource/linux/PNG_HELP.hpng rename to src/resource/embedded/PNG_HELP.hpng diff --git a/src/resource/linux/PNG_REFRESH.hpng b/src/resource/embedded/PNG_REFRESH.hpng similarity index 100% rename from src/resource/linux/PNG_REFRESH.hpng rename to src/resource/embedded/PNG_REFRESH.hpng diff --git a/src/resource/linux/X_BOX.xpm b/src/resource/embedded/X_BOX.xpm similarity index 100% rename from src/resource/linux/X_BOX.xpm rename to src/resource/embedded/X_BOX.xpm diff --git a/src/resource/linux/X_GAME_PROFILE.xpm b/src/resource/embedded/X_GAME_PROFILE.xpm similarity index 100% rename from src/resource/linux/X_GAME_PROFILE.xpm rename to src/resource/embedded/X_GAME_PROFILE.xpm diff --git a/src/resource/linux/X_SETTINGS.xpm b/src/resource/embedded/X_SETTINGS.xpm similarity index 100% rename from src/resource/linux/X_SETTINGS.xpm rename to src/resource/embedded/X_SETTINGS.xpm diff --git a/src/resource/linux/icons8-checkmark-yes-32.hpng b/src/resource/embedded/icons8-checkmark-yes-32.hpng similarity index 100% rename from src/resource/linux/icons8-checkmark-yes-32.hpng rename to src/resource/embedded/icons8-checkmark-yes-32.hpng diff --git a/src/resource/linux/icons8-error-32.hpng b/src/resource/embedded/icons8-error-32.hpng similarity index 100% rename from src/resource/linux/icons8-error-32.hpng rename to src/resource/embedded/icons8-error-32.hpng diff --git a/src/resource/linux/resources.cpp b/src/resource/embedded/resources.cpp similarity index 100% rename from src/resource/linux/resources.cpp rename to src/resource/embedded/resources.cpp diff --git a/src/resource/linux/resources.h b/src/resource/embedded/resources.h similarity index 100% rename from src/resource/linux/resources.h rename to src/resource/embedded/resources.h diff --git a/src/util/Fiber/Fiber.h b/src/util/Fiber/Fiber.h index 75a94d51..c72c62fc 100644 --- a/src/util/Fiber/Fiber.h +++ b/src/util/Fiber/Fiber.h @@ -1,6 +1,6 @@ #pragma once -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS #endif diff --git a/src/util/Fiber/FiberUnix.cpp b/src/util/Fiber/FiberUnix.cpp index e44400b9..9614fc4a 100644 --- a/src/util/Fiber/FiberUnix.cpp +++ b/src/util/Fiber/FiberUnix.cpp @@ -1,5 +1,6 @@ #include "Fiber.h" -#if BOOST_OS_LINUX +#if BOOST_OS_LINUX || BOOST_OS_MACOS +#define _XOPEN_SOURCE #include thread_local Fiber* sCurrentFiber{}; diff --git a/src/util/MemMapper/MemMapperUnix.cpp b/src/util/MemMapper/MemMapperUnix.cpp index 71e5de95..0ea52aa0 100644 --- a/src/util/MemMapper/MemMapperUnix.cpp +++ b/src/util/MemMapper/MemMapperUnix.cpp @@ -1,6 +1,6 @@ #include "util/MemMapper/MemMapper.h" -#if BOOST_OS_LINUX > 0 +#if BOOST_OS_LINUX || BOOST_OS_MACOS #include #include diff --git a/src/util/MemMapper/MemMapperWin.cpp b/src/util/MemMapper/MemMapperWin.cpp index 6606aec4..5c07949f 100644 --- a/src/util/MemMapper/MemMapperWin.cpp +++ b/src/util/MemMapper/MemMapperWin.cpp @@ -1,6 +1,6 @@ #include "util/MemMapper/MemMapper.h" -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS #include diff --git a/src/util/helpers/helpers.cpp b/src/util/helpers/helpers.cpp index 83f2a6c4..dfc36975 100644 --- a/src/util/helpers/helpers.cpp +++ b/src/util/helpers/helpers.cpp @@ -46,7 +46,7 @@ std::string_view& trim(std::string_view& str, const std::string& chars) return ltrim(rtrim(str, chars), chars); } -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS std::wstring GetSystemErrorMessageW() { @@ -120,7 +120,7 @@ std::string GetSystemErrorMessage(const std::error_code& ec) return fmt::format("{}\n{}",msg, ec.message()); } -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS const DWORD MS_VC_EXCEPTION = 0x406D1388; #pragma pack(push,8) typedef struct tagTHREADNAME_INFO @@ -135,7 +135,7 @@ typedef struct tagTHREADNAME_INFO void SetThreadName(const char* name) { -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS #ifndef _PUBLIC_RELEASE THREADNAME_INFO info; @@ -154,12 +154,14 @@ void SetThreadName(const char* name) #endif +#elif BOOST_OS_MACOS + pthread_setname_np(name); #else pthread_setname_np(pthread_self(), name); #endif } -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS std::pair GetWindowsVersion() { using RtlGetVersion_t = LONG(*)(POSVERSIONINFOEXW); diff --git a/src/util/helpers/helpers.h b/src/util/helpers/helpers.h index a672213d..6240d56a 100644 --- a/src/util/helpers/helpers.h +++ b/src/util/helpers/helpers.h @@ -8,7 +8,7 @@ #include "util/math/vector3.h" #ifdef __clang__ -#include "Common/linux/fast_float.h" +#include "Common/unix/fast_float.h" #endif template diff --git a/src/util/libusbWrapper/libusbWrapper.cpp b/src/util/libusbWrapper/libusbWrapper.cpp index 25a73781..e1d72985 100644 --- a/src/util/libusbWrapper/libusbWrapper.cpp +++ b/src/util/libusbWrapper/libusbWrapper.cpp @@ -60,7 +60,7 @@ void libusbWrapper::init() libusbWrapper::~libusbWrapper() { -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS // destroy default context if(p_libusb_exit) p_libusb_exit(nullptr); diff --git a/src/util/libusbWrapper/libusbWrapper.h b/src/util/libusbWrapper/libusbWrapper.h index e79c5b04..ff9b0275 100644 --- a/src/util/libusbWrapper/libusbWrapper.h +++ b/src/util/libusbWrapper/libusbWrapper.h @@ -41,7 +41,7 @@ public: private: -#if BOOST_OS_WINDOWS > 0 +#if BOOST_OS_WINDOWS HMODULE m_module = nullptr; bool m_isInitialized = false; #endif