diff --git a/common/Assertions.cpp b/common/Assertions.cpp index 7799f0ad5c..b6115ca9c9 100644 --- a/common/Assertions.cpp +++ b/common/Assertions.cpp @@ -1,10 +1,10 @@ // SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team // SPDX-License-Identifier: LGPL-3.0+ -#include "Threading.h" -#include "General.h" #include "Assertions.h" #include "CrashHandler.h" +#include "HostSys.h" +#include "Threading.h" #include #include "fmt/core.h" diff --git a/common/BitUtils.h b/common/BitUtils.h index 129d5a2ba1..74265477d3 100644 --- a/common/BitUtils.h +++ b/common/BitUtils.h @@ -6,6 +6,7 @@ #include "common/Pcsx2Defs.h" #include +#include #ifdef _MSC_VER @@ -84,3 +85,16 @@ namespace Common return std::countl_zero(static_cast(n)); } } // namespace Common + +template +[[maybe_unused]] __fi static T GetBufferT(u8* buffer, u32 offset) +{ + T value; + std::memcpy(&value, buffer + offset, sizeof(value)); + return value; +} + +[[maybe_unused]] __fi static u8 GetBufferU8(u8* buffer, u32 offset) { return GetBufferT(buffer, offset); } +[[maybe_unused]] __fi static u16 GetBufferU16(u8* buffer, u32 offset) { return GetBufferT(buffer, offset); } +[[maybe_unused]] __fi static u32 GetBufferU32(u8* buffer, u32 offset) { return GetBufferT(buffer, offset); } +[[maybe_unused]] __fi static u64 GetBufferU64(u8* buffer, u32 offset) { return GetBufferT(buffer, offset); } diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 7928cc22fa..a096a8d1c8 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -17,11 +17,10 @@ target_sources(common PRIVATE Error.cpp FastJmp.cpp FileSystem.cpp - General.cpp + HostSys.cpp Image.cpp HTTPDownloader.cpp MemorySettingsInterface.cpp - Misc.cpp MD5Digest.cpp PrecompiledHeader.cpp Perf.cpp @@ -72,8 +71,8 @@ target_sources(common PRIVATE FPControl.h FastJmp.h FileSystem.h - General.h HashCombine.h + HostSys.h HeterogeneousContainers.h Image.h LRUCache.h diff --git a/common/CocoaTools.mm b/common/CocoaTools.mm index fb94ca5d5e..2b68f0bc7f 100644 --- a/common/CocoaTools.mm +++ b/common/CocoaTools.mm @@ -7,7 +7,7 @@ #include "CocoaTools.h" #include "Console.h" -#include "General.h" +#include "HostSys.h" #include "WindowInfo.h" #include #include diff --git a/common/Darwin/DarwinMisc.cpp b/common/Darwin/DarwinMisc.cpp index df596f57f5..8663ee4f1e 100644 --- a/common/Darwin/DarwinMisc.cpp +++ b/common/Darwin/DarwinMisc.cpp @@ -16,7 +16,7 @@ #include "common/Pcsx2Types.h" #include "common/Console.h" -#include "common/General.h" +#include "common/HostSys.h" #include "common/Threading.h" #include "common/WindowInfo.h" diff --git a/common/General.cpp b/common/General.cpp deleted file mode 100644 index bd1f006a9c..0000000000 --- a/common/General.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team -// SPDX-License-Identifier: LGPL-3.0+ - -#include "General.h" - -// -------------------------------------------------------------------------------------- -// PageProtectionMode (implementations) -// -------------------------------------------------------------------------------------- -std::string PageProtectionMode::ToString() const -{ - std::string modeStr; - - if (m_read) - modeStr += "Read"; - if (m_write) - modeStr += "Write"; - if (m_exec) - modeStr += "Exec"; - - if (modeStr.empty()) - return "NoAccess"; - if (modeStr.length() <= 5) - modeStr += "Only"; - - return modeStr; -} diff --git a/common/Misc.cpp b/common/HostSys.cpp similarity index 99% rename from common/Misc.cpp rename to common/HostSys.cpp index ae8c3f9baf..ee043949a4 100644 --- a/common/Misc.cpp +++ b/common/HostSys.cpp @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team // SPDX-License-Identifier: LGPL-3.0+ -#include "General.h" +#include "HostSys.h" #include "Console.h" #include "VectorIntrin.h" diff --git a/common/General.h b/common/HostSys.h similarity index 81% rename from common/General.h rename to common/HostSys.h index e95da15376..988429c49c 100644 --- a/common/General.h +++ b/common/HostSys.h @@ -9,20 +9,6 @@ #include #include #include -#include - -template -[[maybe_unused]] __fi static T GetBufferT(u8* buffer, u32 offset) -{ - T value; - std::memcpy(&value, buffer + offset, sizeof(value)); - return value; -} - -[[maybe_unused]] __fi static u8 GetBufferU8(u8* buffer, u32 offset) { return GetBufferT(buffer, offset); } -[[maybe_unused]] __fi static u16 GetBufferU16(u8* buffer, u32 offset) { return GetBufferT(buffer, offset); } -[[maybe_unused]] __fi static u32 GetBufferU32(u8* buffer, u32 offset) { return GetBufferT(buffer, offset); } -[[maybe_unused]] __fi static u64 GetBufferU64(u8* buffer, u32 offset) { return GetBufferT(buffer, offset); } // -------------------------------------------------------------------------------------- // PageProtectionMode @@ -30,46 +16,41 @@ template class PageProtectionMode { protected: - bool m_read; - bool m_write; - bool m_exec; + bool m_read = false; + bool m_write = false; + bool m_exec = false; public: - PageProtectionMode() - { - All(false); - } + __fi constexpr PageProtectionMode() = default; - PageProtectionMode& Read(bool allow = true) + __fi constexpr PageProtectionMode& Read(bool allow = true) { m_read = allow; return *this; } - PageProtectionMode& Write(bool allow = true) + __fi constexpr PageProtectionMode& Write(bool allow = true) { m_write = allow; return *this; } - PageProtectionMode& Execute(bool allow = true) + __fi constexpr PageProtectionMode& Execute(bool allow = true) { m_exec = allow; return *this; } - PageProtectionMode& All(bool allow = true) + __fi constexpr PageProtectionMode& All(bool allow = true) { m_read = m_write = m_exec = allow; return *this; } - bool CanRead() const { return m_read; } - bool CanWrite() const { return m_write; } - bool CanExecute() const { return m_exec && m_read; } - bool IsNone() const { return !m_read && !m_write; } - - std::string ToString() const; + __fi constexpr bool CanRead() const { return m_read; } + __fi constexpr bool CanWrite() const { return m_write; } + __fi constexpr bool CanExecute() const { return m_exec && m_read; } + __fi constexpr bool IsNone() const { return !m_read && !m_write; } }; static __fi PageProtectionMode PageAccess_None() diff --git a/common/Linux/LnxHostSys.cpp b/common/Linux/LnxHostSys.cpp index 9a8efa483d..a01ce9b998 100644 --- a/common/Linux/LnxHostSys.cpp +++ b/common/Linux/LnxHostSys.cpp @@ -20,7 +20,7 @@ #include "common/BitUtils.h" #include "common/Assertions.h" #include "common/Console.h" -#include "common/General.h" +#include "common/HostSys.h" // Apple uses the MAP_ANON define instead of MAP_ANONYMOUS, but they mean // the same thing. diff --git a/common/Linux/LnxMisc.cpp b/common/Linux/LnxMisc.cpp index 6ffd078566..2919e0edfd 100644 --- a/common/Linux/LnxMisc.cpp +++ b/common/Linux/LnxMisc.cpp @@ -4,7 +4,7 @@ #if !defined(_WIN32) && !defined(__APPLE__) #include "common/Pcsx2Types.h" -#include "common/General.h" +#include "common/HostSys.h" #include "common/ScopedGuard.h" #include "common/StringUtil.h" #include "common/Threading.h" diff --git a/common/Semaphore.cpp b/common/Semaphore.cpp index e44c17ed40..63f53dc25f 100644 --- a/common/Semaphore.cpp +++ b/common/Semaphore.cpp @@ -3,6 +3,7 @@ #include "common/Threading.h" #include "common/Assertions.h" +#include "common/HostSys.h" #ifdef _WIN32 #include "common/RedtapeWindows.h" diff --git a/common/Threading.h b/common/Threading.h index 3a4f42ad23..4e46f9ba2b 100644 --- a/common/Threading.h +++ b/common/Threading.h @@ -4,7 +4,6 @@ #pragma once #include "common/Pcsx2Defs.h" -#include "common/General.h" #if defined(__APPLE__) #include diff --git a/common/Windows/WinHostSys.cpp b/common/Windows/WinHostSys.cpp index c9828661a5..f66d3e2d0c 100644 --- a/common/Windows/WinHostSys.cpp +++ b/common/Windows/WinHostSys.cpp @@ -6,7 +6,7 @@ #include "common/BitUtils.h" #include "common/RedtapeWindows.h" #include "common/Console.h" -#include "common/General.h" +#include "common/HostSys.h" #include "common/StringUtil.h" #include "common/AlignedMalloc.h" #include "common/Assertions.h" diff --git a/common/Windows/WinMisc.cpp b/common/Windows/WinMisc.cpp index e328db0dc8..3e34a8760c 100644 --- a/common/Windows/WinMisc.cpp +++ b/common/Windows/WinMisc.cpp @@ -3,11 +3,10 @@ #if defined(_WIN32) -#include "common/Pcsx2Defs.h" +#include "common/HostSys.h" #include "common/RedtapeWindows.h" #include "common/StringUtil.h" #include "common/Threading.h" -#include "common/General.h" #include "common/WindowInfo.h" #include "fmt/core.h" diff --git a/common/common.vcxproj b/common/common.vcxproj index 1353ed22cc..30a2aca5a8 100644 --- a/common/common.vcxproj +++ b/common/common.vcxproj @@ -55,7 +55,6 @@ true - @@ -84,7 +83,7 @@ - + @@ -135,7 +134,7 @@ - + diff --git a/common/common.vcxproj.filters b/common/common.vcxproj.filters index 416e15b660..42869b1c19 100644 --- a/common/common.vcxproj.filters +++ b/common/common.vcxproj.filters @@ -40,7 +40,7 @@ Source Files - + Source Files @@ -124,9 +124,6 @@ Source Files - - Source Files - Source Files @@ -159,7 +156,7 @@ Header Files - + Header Files diff --git a/pcsx2/Achievements.cpp b/pcsx2/Achievements.cpp index 38c8feb2de..e2c2bbda6f 100644 --- a/pcsx2/Achievements.cpp +++ b/pcsx2/Achievements.cpp @@ -22,7 +22,6 @@ #include "common/Console.h" #include "common/Error.h" #include "common/FileSystem.h" -#include "common/General.h" #include "common/HTTPDownloader.h" #include "common/MD5Digest.h" #include "common/Path.h" diff --git a/pcsx2/CDVD/CDVD.cpp b/pcsx2/CDVD/CDVD.cpp index e76b70607b..f60e6693ff 100644 --- a/pcsx2/CDVD/CDVD.cpp +++ b/pcsx2/CDVD/CDVD.cpp @@ -17,6 +17,7 @@ #include "IopDma.h" #include "VMManager.h" +#include "common/BitUtils.h" #include "common/Error.h" #include "common/FileSystem.h" #include "common/Path.h" diff --git a/pcsx2/Config.h b/pcsx2/Config.h index 602cc5537c..b84fdb1c4d 100644 --- a/pcsx2/Config.h +++ b/pcsx2/Config.h @@ -3,7 +3,7 @@ #pragma once -#include "common/General.h" +#include "common/Pcsx2Defs.h" #include "common/FPControl.h" #include #include diff --git a/pcsx2/GS/GSJobQueue.h b/pcsx2/GS/GSJobQueue.h index 87940ac2dd..d5984e8517 100644 --- a/pcsx2/GS/GSJobQueue.h +++ b/pcsx2/GS/GSJobQueue.h @@ -6,7 +6,6 @@ #include "GS.h" #include "common/boost_spsc_queue.hpp" #include "common/Assertions.h" -#include "common/General.h" #include "common/Threading.h" #include #include diff --git a/pcsx2/GS/GSPerfMon.cpp b/pcsx2/GS/GSPerfMon.cpp index 0e0cbde1f8..d5af3f9fb1 100644 --- a/pcsx2/GS/GSPerfMon.cpp +++ b/pcsx2/GS/GSPerfMon.cpp @@ -4,6 +4,8 @@ #include "GSPerfMon.h" #include "GS.h" +#include + GSPerfMon g_perfmon; GSPerfMon::GSPerfMon() = default; diff --git a/pcsx2/GS/Renderers/Common/GSFunctionMap.h b/pcsx2/GS/Renderers/Common/GSFunctionMap.h index 54b8743649..a5fccce22e 100644 --- a/pcsx2/GS/Renderers/Common/GSFunctionMap.h +++ b/pcsx2/GS/Renderers/Common/GSFunctionMap.h @@ -6,6 +6,8 @@ #include "GS/GSExtra.h" #include "GS/Renderers/SW/GSScanlineEnvironment.h" +#include "common/HostSys.h" + template class GSFunctionMap { diff --git a/pcsx2/GS/Renderers/DX12/GSDevice12.cpp b/pcsx2/GS/Renderers/DX12/GSDevice12.cpp index 2b5bdc11a8..012e95378b 100644 --- a/pcsx2/GS/Renderers/DX12/GSDevice12.cpp +++ b/pcsx2/GS/Renderers/DX12/GSDevice12.cpp @@ -14,6 +14,7 @@ #include "common/Console.h" #include "common/BitUtils.h" +#include "common/HostSys.h" #include "common/ScopedGuard.h" #include "common/StringUtil.h" diff --git a/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm b/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm index 5a120a971a..15c5211a96 100644 --- a/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm +++ b/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm @@ -8,6 +8,7 @@ #include "GS/GSPerfMon.h" #include "common/Console.h" +#include "common/HostSys.h" #include "imgui.h" diff --git a/pcsx2/GS/Renderers/Metal/GSTextureMTL.mm b/pcsx2/GS/Renderers/Metal/GSTextureMTL.mm index 8f8cf6ae91..89c56e08e6 100644 --- a/pcsx2/GS/Renderers/Metal/GSTextureMTL.mm +++ b/pcsx2/GS/Renderers/Metal/GSTextureMTL.mm @@ -6,6 +6,7 @@ #include "GS/GSPerfMon.h" #include "common/BitUtils.h" #include "common/Console.h" +#include "common/HostSys.h" #ifdef __APPLE__ diff --git a/pcsx2/GS/Renderers/SW/GSRasterizer.cpp b/pcsx2/GS/Renderers/SW/GSRasterizer.cpp index 61b9c56d20..61ab3e9af9 100644 --- a/pcsx2/GS/Renderers/SW/GSRasterizer.cpp +++ b/pcsx2/GS/Renderers/SW/GSRasterizer.cpp @@ -11,7 +11,6 @@ #include "common/AlignedMalloc.h" #include "common/Console.h" -#include "common/General.h" #include "common/StringUtil.h" #define ENABLE_DRAW_STATS 0 diff --git a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp index 47912c388b..7a70971b76 100644 --- a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp +++ b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp @@ -14,6 +14,7 @@ #include "common/Console.h" #include "common/BitUtils.h" +#include "common/HostSys.h" #include "common/Path.h" #include "common/ScopedGuard.h" diff --git a/pcsx2/GameDatabase.h b/pcsx2/GameDatabase.h index f2f4f9af42..8b24b20587 100644 --- a/pcsx2/GameDatabase.h +++ b/pcsx2/GameDatabase.h @@ -8,6 +8,7 @@ #include "common/FPControl.h" +#include #include #include #include diff --git a/pcsx2/IPU/IPU_MultiISA.cpp b/pcsx2/IPU/IPU_MultiISA.cpp index 26d762256d..194a2b0172 100644 --- a/pcsx2/IPU/IPU_MultiISA.cpp +++ b/pcsx2/IPU/IPU_MultiISA.cpp @@ -14,8 +14,6 @@ #include "IPU/yuv2rgb.h" #include "IPU/IPU_MultiISA.h" -#include "common/General.h" - // the IPU is fixed to 16 byte strides (128-bit / QWC resolution): static const uint decoder_stride = 16; diff --git a/pcsx2/Input/InputManager.cpp b/pcsx2/Input/InputManager.cpp index 2b4e0409f0..7c925017e1 100644 --- a/pcsx2/Input/InputManager.cpp +++ b/pcsx2/Input/InputManager.cpp @@ -19,6 +19,7 @@ #include "fmt/core.h" #include +#include #include #include #include diff --git a/pcsx2/SIO/Memcard/MemoryCardProtocol.cpp b/pcsx2/SIO/Memcard/MemoryCardProtocol.cpp index 2a63100642..e9c4ea42eb 100644 --- a/pcsx2/SIO/Memcard/MemoryCardProtocol.cpp +++ b/pcsx2/SIO/Memcard/MemoryCardProtocol.cpp @@ -10,6 +10,8 @@ #include "common/Assertions.h" #include "common/Console.h" +#include + #define MC_LOG_ENABLE 0 #define MC_LOG if (MC_LOG_ENABLE) DevCon diff --git a/pcsx2/SIO/Sio.cpp b/pcsx2/SIO/Sio.cpp index 02412971ec..c1bfc3f32f 100644 --- a/pcsx2/SIO/Sio.cpp +++ b/pcsx2/SIO/Sio.cpp @@ -9,6 +9,8 @@ #include "Host.h" #include "IconsFontAwesome5.h" +#include + _mcd mcds[2][4]; _mcd *mcd; diff --git a/pcsx2/SPU2/spu2freeze.cpp b/pcsx2/SPU2/spu2freeze.cpp index 9eec55297c..6587f0eccf 100644 --- a/pcsx2/SPU2/spu2freeze.cpp +++ b/pcsx2/SPU2/spu2freeze.cpp @@ -5,6 +5,8 @@ #include "SPU2/spu2.h" // hopefully temporary, until I resolve lClocks depdendency #include "IopMem.h" +#include + namespace SPU2Savestate { // Arbitrary ID to identify SPU2 saves. diff --git a/pcsx2/vtlb.cpp b/pcsx2/vtlb.cpp index 0fe5ccbe87..e5c5b4aad0 100644 --- a/pcsx2/vtlb.cpp +++ b/pcsx2/vtlb.cpp @@ -1023,7 +1023,7 @@ bool vtlb_GetGuestAddress(uptr host_addr, u32* guest_addr) return true; } -void vtlb_UpdateFastmemProtection(u32 paddr, u32 size, const PageProtectionMode& prot) +void vtlb_UpdateFastmemProtection(u32 paddr, u32 size, PageProtectionMode prot) { if (!CHECK_FASTMEM) return; diff --git a/pcsx2/vtlb.h b/pcsx2/vtlb.h index 66a5bfdd49..12384e2a19 100644 --- a/pcsx2/vtlb.h +++ b/pcsx2/vtlb.h @@ -5,7 +5,7 @@ #include "MemoryTypes.h" -#include "common/General.h" +#include "common/HostSys.h" #include "common/SingleRegisterTypes.h" static const uptr VTLB_AllocUpperBounds = _1gb * 2; @@ -73,7 +73,7 @@ extern void vtlb_VMapBuffer(u32 vaddr,void* buffer,u32 sz); extern void vtlb_VMapUnmap(u32 vaddr,u32 sz); extern bool vtlb_ResolveFastmemMapping(uptr* addr); extern bool vtlb_GetGuestAddress(uptr host_addr, u32* guest_addr); -extern void vtlb_UpdateFastmemProtection(u32 paddr, u32 size, const PageProtectionMode& prot); +extern void vtlb_UpdateFastmemProtection(u32 paddr, u32 size, PageProtectionMode prot); extern bool vtlb_BackpatchLoadStore(uptr code_address, uptr fault_address); extern void vtlb_ClearLoadStoreInfo();