Common: Move janky macros to Config.h

This commit is contained in:
Stenzek 2023-12-26 21:21:37 +10:00 committed by Connor McLaughlin
parent 9d49015c0c
commit 911d7f6533
3 changed files with 247 additions and 194 deletions

View File

@ -11,23 +11,6 @@
#include <string> #include <string>
#include <cstring> #include <cstring>
// This macro is actually useful for about any and every possible application of C++
// equality operators.
#define OpEqu(field) (field == right.field)
// Macro used for removing some of the redtape involved in defining bitfield/union helpers.
//
#define BITFIELD32() \
union \
{ \
u32 bitset; \
struct \
{
#define BITFIELD_END \
}; \
};
template <typename T> template <typename T>
[[maybe_unused]] __fi static T GetBufferT(u8* buffer, u32 offset) [[maybe_unused]] __fi static T GetBufferT(u8* buffer, u32 offset)
{ {

View File

@ -10,6 +10,20 @@
#include <optional> #include <optional>
#include <vector> #include <vector>
// Macro used for removing some of the redtape involved in defining bitfield/union helpers.
//
#define BITFIELD32() \
union \
{ \
u32 bitset; \
struct \
{
#define BITFIELD_END \
} \
; \
} \
;
class SettingsInterface; class SettingsInterface;
class SettingsWrapper; class SettingsWrapper;
@ -389,20 +403,10 @@ struct TraceFiltersEE
m_EnableEvents : 1; // Enables logging of event-driven activity -- counters, DMAs, etc. m_EnableEvents : 1; // Enables logging of event-driven activity -- counters, DMAs, etc.
BITFIELD_END BITFIELD_END
TraceFiltersEE() TraceFiltersEE();
{
bitset = 0;
}
bool operator==(const TraceFiltersEE& right) const bool operator==(const TraceFiltersEE& right) const;
{ bool operator!=(const TraceFiltersEE& right) const;
return OpEqu(bitset);
}
bool operator!=(const TraceFiltersEE& right) const
{
return !this->operator==(right);
}
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -418,20 +422,10 @@ struct TraceFiltersIOP
m_EnableEvents : 1; // Enables logging of event-driven activity -- counters, DMAs, etc. m_EnableEvents : 1; // Enables logging of event-driven activity -- counters, DMAs, etc.
BITFIELD_END BITFIELD_END
TraceFiltersIOP() TraceFiltersIOP();
{
bitset = 0;
}
bool operator==(const TraceFiltersIOP& right) const bool operator==(const TraceFiltersIOP& right) const;
{ bool operator!=(const TraceFiltersIOP& right) const;
return OpEqu(bitset);
}
bool operator!=(const TraceFiltersIOP& right) const
{
return !this->operator==(right);
}
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -450,22 +444,12 @@ struct TraceLogFilters
TraceFiltersEE EE; TraceFiltersEE EE;
TraceFiltersIOP IOP; TraceFiltersIOP IOP;
TraceLogFilters() TraceLogFilters();
{
Enabled = false;
}
void LoadSave(SettingsWrapper& ini); void LoadSave(SettingsWrapper& ini);
bool operator==(const TraceLogFilters& right) const bool operator==(const TraceLogFilters& right) const;
{ bool operator!=(const TraceLogFilters& right) const;
return OpEqu(Enabled) && OpEqu(EE) && OpEqu(IOP);
}
bool operator!=(const TraceLogFilters& right) const
{
return !this->operator==(right);
}
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -493,21 +477,11 @@ struct Pcsx2Config
BITFIELD_END BITFIELD_END
// Default is Disabled, with all recs enabled underneath. // Default is Disabled, with all recs enabled underneath.
ProfilerOptions() ProfilerOptions();
: bitset(0xfffffffe)
{
}
void LoadSave(SettingsWrapper& wrap); void LoadSave(SettingsWrapper& wrap);
bool operator==(const ProfilerOptions& right) const bool operator==(const ProfilerOptions& right) const;
{ bool operator!=(const ProfilerOptions& right) const;
return OpEqu(bitset);
}
bool operator!=(const ProfilerOptions& right) const
{
return !OpEqu(bitset);
}
}; };
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -550,32 +524,13 @@ struct Pcsx2Config
void LoadSave(SettingsWrapper& wrap); void LoadSave(SettingsWrapper& wrap);
bool operator==(const RecompilerOptions& right) const bool operator==(const RecompilerOptions& right) const;
{ bool operator!=(const RecompilerOptions& right) const;
return OpEqu(bitset);
}
bool operator!=(const RecompilerOptions& right) const u32 GetEEClampMode() const;
{ void SetEEClampMode(u32 value);
return !OpEqu(bitset);
}
u32 GetEEClampMode() const u32 GetVUClampMode() const;
{
return fpuFullMode ? 3 : (fpuExtraOverflow ? 2 : (fpuOverflow ? 1 : 0));
}
void SetEEClampMode(u32 value)
{
fpuOverflow = (value >= 1);
fpuExtraOverflow = (value >= 2);
fpuFullMode = (value >= 3);
}
u32 GetVUClampMode() const
{
return vu0SignOverflow ? 3 : (vu0ExtraOverflow ? 2 : (vu0Overflow ? 1 : 0));
}
}; };
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -595,15 +550,8 @@ struct Pcsx2Config
bool CpusChanged(const CpuOptions& right) const; bool CpusChanged(const CpuOptions& right) const;
bool operator==(const CpuOptions& right) const bool operator==(const CpuOptions& right) const;
{ bool operator!=(const CpuOptions& right) const;
return OpEqu(FPUFPCR) && OpEqu(VU0FPCR) && OpEqu(VU1FPCR) && OpEqu(AffinityControlMode) && OpEqu(Recompiler);
}
bool operator!=(const CpuOptions& right) const
{
return !this->operator==(right);
}
}; };
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -876,31 +824,8 @@ struct Pcsx2Config
void LoadSave(SettingsWrapper& wrap); void LoadSave(SettingsWrapper& wrap);
bool operator==(const SPU2Options& right) const bool operator==(const SPU2Options& right) const;
{ bool operator!=(const SPU2Options& right) const;
return OpEqu(bitset) &&
OpEqu(SynchMode) &&
OpEqu(FinalVolume) &&
OpEqu(Latency) &&
OpEqu(OutputLatency) &&
OpEqu(SpeakerConfiguration) &&
OpEqu(DplDecodingLevel) &&
OpEqu(SequenceLenMS) &&
OpEqu(SeekWindowMS) &&
OpEqu(OverlapMS) &&
OpEqu(OutputModule) &&
OpEqu(BackendName) &&
OpEqu(DeviceName);
}
bool operator!=(const SPU2Options& right) const
{
return !this->operator==(right);
}
}; };
struct DEV9Options struct DEV9Options
@ -930,18 +855,8 @@ struct Pcsx2Config
u8 Address[4]{}; u8 Address[4]{};
bool Enabled; bool Enabled;
bool operator==(const HostEntry& right) const bool operator==(const HostEntry& right) const;
{ bool operator!=(const HostEntry& right) const;
return OpEqu(Url) &&
OpEqu(Desc) &&
(*(int*)Address == *(int*)right.Address) &&
OpEqu(Enabled);
}
bool operator!=(const HostEntry& right) const
{
return !this->operator==(right);
}
}; };
bool EthEnable{false}; bool EthEnable{false};
@ -969,34 +884,8 @@ struct Pcsx2Config
void LoadSave(SettingsWrapper& wrap); void LoadSave(SettingsWrapper& wrap);
bool operator==(const DEV9Options& right) const bool operator==(const DEV9Options& right) const;
{ bool operator!=(const DEV9Options& right) const;
return OpEqu(EthEnable) &&
OpEqu(EthApi) &&
OpEqu(EthDevice) &&
OpEqu(EthLogDNS) &&
OpEqu(InterceptDHCP) &&
(*(int*)PS2IP == *(int*)right.PS2IP) &&
(*(int*)Gateway == *(int*)right.Gateway) &&
(*(int*)DNS1 == *(int*)right.DNS1) &&
(*(int*)DNS2 == *(int*)right.DNS2) &&
OpEqu(AutoMask) &&
OpEqu(AutoGateway) &&
OpEqu(ModeDNS1) &&
OpEqu(ModeDNS2) &&
OpEqu(EthHosts) &&
OpEqu(HddEnable) &&
OpEqu(HddFile);
}
bool operator!=(const DEV9Options& right) const
{
return !this->operator==(right);
}
protected: protected:
static void LoadIPHelper(u8* field, const std::string& setting); static void LoadIPHelper(u8* field, const std::string& setting);
@ -1040,15 +929,8 @@ struct Pcsx2Config
void Set(GamefixId id, bool enabled = true); void Set(GamefixId id, bool enabled = true);
void Clear(GamefixId id) { Set(id, false); } void Clear(GamefixId id) { Set(id, false); }
bool operator==(const GamefixOptions& right) const bool operator==(const GamefixOptions& right) const;
{ bool operator!=(const GamefixOptions& right) const;
return OpEqu(bitset);
}
bool operator!=(const GamefixOptions& right) const
{
return !OpEqu(bitset);
}
}; };
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -1102,15 +984,8 @@ struct Pcsx2Config
DebugOptions(); DebugOptions();
void LoadSave(SettingsWrapper& wrap); void LoadSave(SettingsWrapper& wrap);
bool operator==(const DebugOptions& right) const bool operator==(const DebugOptions& right) const;
{ bool operator!=(const DebugOptions& right) const;
return OpEqu(bitset) && OpEqu(FontWidth) && OpEqu(FontHeight) && OpEqu(WindowWidth) && OpEqu(WindowHeight) && OpEqu(MemoryViewBytesPerRow);
}
bool operator!=(const DebugOptions& right) const
{
return !this->operator==(right);
}
}; };
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -1142,15 +1017,8 @@ struct Pcsx2Config
FilenameOptions(); FilenameOptions();
void LoadSave(SettingsWrapper& wrap); void LoadSave(SettingsWrapper& wrap);
bool operator==(const FilenameOptions& right) const bool operator==(const FilenameOptions& right) const;
{ bool operator!=(const FilenameOptions& right) const;
return OpEqu(Bios);
}
bool operator!=(const FilenameOptions& right) const
{
return !this->operator==(right);
}
}; };
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -1448,3 +1316,6 @@ namespace EmuFolders
// Change to 1 for console logs of SIF, GPU (PS1 mode) and MDEC (PS1 mode). // Change to 1 for console logs of SIF, GPU (PS1 mode) and MDEC (PS1 mode).
// These do spam a lot though! // These do spam a lot though!
#define PSX_EXTRALOGS 0 #define PSX_EXTRALOGS 0
#undef BITFIELD32
#undef BITFIELD_END

View File

@ -22,6 +22,10 @@
#include <ShlObj.h> #include <ShlObj.h>
#endif #endif
// This macro is actually useful for about any and every possible application of C++ equality operators.
// Stuck here because of legacy code, new code shouldn't rely on it, it's difficult to read.
#define OpEqu(field) (field == right.field)
// Default EE/VU control registers have exceptions off, DaZ/FTZ, and the rounding mode set to Chop/Zero. // Default EE/VU control registers have exceptions off, DaZ/FTZ, and the rounding mode set to Chop/Zero.
static constexpr FPControlRegister DEFAULT_FPU_FP_CONTROL_REGISTER = FPControlRegister::GetDefault() static constexpr FPControlRegister DEFAULT_FPU_FP_CONTROL_REGISTER = FPControlRegister::GetDefault()
.DisableExceptions() .DisableExceptions()
@ -168,6 +172,41 @@ namespace EmuFolders
static void SetDataDirectory(); static void SetDataDirectory();
} // namespace EmuFolders } // namespace EmuFolders
TraceFiltersEE::TraceFiltersEE()
{
bitset = 0;
}
bool TraceFiltersEE::operator==(const TraceFiltersEE& right) const
{
return OpEqu(bitset);
}
bool TraceFiltersEE::operator!=(const TraceFiltersEE& right) const
{
return !this->operator==(right);
}
TraceFiltersIOP::TraceFiltersIOP()
{
bitset = 0;
}
bool TraceFiltersIOP::operator==(const TraceFiltersIOP& right) const
{
return OpEqu(bitset);
}
bool TraceFiltersIOP::operator!=(const TraceFiltersIOP& right) const
{
return !this->operator==(right);
}
TraceLogFilters::TraceLogFilters()
{
Enabled = false;
}
void TraceLogFilters::LoadSave(SettingsWrapper& wrap) void TraceLogFilters::LoadSave(SettingsWrapper& wrap)
{ {
SettingsWrapSection("EmuCore/TraceLog"); SettingsWrapSection("EmuCore/TraceLog");
@ -181,6 +220,16 @@ void TraceLogFilters::LoadSave(SettingsWrapper& wrap)
SettingsWrapEntry(IOP.bitset); SettingsWrapEntry(IOP.bitset);
} }
bool TraceLogFilters::operator==(const TraceLogFilters& right) const
{
return OpEqu(Enabled) && OpEqu(EE) && OpEqu(IOP);
}
bool TraceLogFilters::operator!=(const TraceLogFilters& right) const
{
return !this->operator==(right);
}
static constexpr const char* s_speed_hack_names[] = { static constexpr const char* s_speed_hack_names[] = {
"mvuFlag", "mvuFlag",
"instantVU1", "instantVU1",
@ -274,6 +323,11 @@ void Pcsx2Config::SpeedhackOptions::LoadSave(SettingsWrapper& wrap)
EECycleSkip = std::min(EECycleSkip, MAX_EE_CYCLE_SKIP); EECycleSkip = std::min(EECycleSkip, MAX_EE_CYCLE_SKIP);
} }
Pcsx2Config::ProfilerOptions::ProfilerOptions()
: bitset(0xfffffffe)
{
}
void Pcsx2Config::ProfilerOptions::LoadSave(SettingsWrapper& wrap) void Pcsx2Config::ProfilerOptions::LoadSave(SettingsWrapper& wrap)
{ {
SettingsWrapSection("EmuCore/Profiler"); SettingsWrapSection("EmuCore/Profiler");
@ -285,6 +339,16 @@ void Pcsx2Config::ProfilerOptions::LoadSave(SettingsWrapper& wrap)
SettingsWrapBitBool(RecBlocks_VU1); SettingsWrapBitBool(RecBlocks_VU1);
} }
bool Pcsx2Config::ProfilerOptions::operator!=(const ProfilerOptions& right) const
{
return !OpEqu(bitset);
}
bool Pcsx2Config::ProfilerOptions::operator==(const ProfilerOptions& right) const
{
return OpEqu(bitset);
}
Pcsx2Config::RecompilerOptions::RecompilerOptions() Pcsx2Config::RecompilerOptions::RecompilerOptions()
{ {
bitset = 0; bitset = 0;
@ -394,6 +458,33 @@ void Pcsx2Config::RecompilerOptions::LoadSave(SettingsWrapper& wrap)
SettingsWrapBitBool(fpuFullMode); SettingsWrapBitBool(fpuFullMode);
} }
u32 Pcsx2Config::RecompilerOptions::GetEEClampMode() const
{
return fpuFullMode ? 3 : (fpuExtraOverflow ? 2 : (fpuOverflow ? 1 : 0));
}
void Pcsx2Config::RecompilerOptions::SetEEClampMode(u32 value)
{
fpuOverflow = (value >= 1);
fpuExtraOverflow = (value >= 2);
fpuFullMode = (value >= 3);
}
u32 Pcsx2Config::RecompilerOptions::GetVUClampMode() const
{
return vu0SignOverflow ? 3 : (vu0ExtraOverflow ? 2 : (vu0Overflow ? 1 : 0));
}
bool Pcsx2Config::RecompilerOptions::operator!=(const RecompilerOptions& right) const
{
return !OpEqu(bitset);
}
bool Pcsx2Config::RecompilerOptions::operator==(const RecompilerOptions& right) const
{
return OpEqu(bitset);
}
bool Pcsx2Config::CpuOptions::CpusChanged(const CpuOptions& right) const bool Pcsx2Config::CpuOptions::CpusChanged(const CpuOptions& right) const
{ {
return (Recompiler.EnableEE != right.Recompiler.EnableEE || return (Recompiler.EnableEE != right.Recompiler.EnableEE ||
@ -402,6 +493,16 @@ bool Pcsx2Config::CpuOptions::CpusChanged(const CpuOptions& right) const
Recompiler.EnableVU1 != right.Recompiler.EnableVU1); Recompiler.EnableVU1 != right.Recompiler.EnableVU1);
} }
bool Pcsx2Config::CpuOptions::operator!=(const CpuOptions& right) const
{
return !this->operator==(right);
}
bool Pcsx2Config::CpuOptions::operator==(const CpuOptions& right) const
{
return OpEqu(FPUFPCR) && OpEqu(VU0FPCR) && OpEqu(VU1FPCR) && OpEqu(AffinityControlMode) && OpEqu(Recompiler);
}
Pcsx2Config::CpuOptions::CpuOptions() Pcsx2Config::CpuOptions::CpuOptions()
{ {
FPUFPCR = DEFAULT_FPU_FP_CONTROL_REGISTER; FPUFPCR = DEFAULT_FPU_FP_CONTROL_REGISTER;
@ -991,6 +1092,32 @@ void Pcsx2Config::SPU2Options::LoadSave(SettingsWrapper& wrap)
// clampy clamp // clampy clamp
} }
bool Pcsx2Config::SPU2Options::operator!=(const SPU2Options& right) const
{
return !this->operator==(right);
}
bool Pcsx2Config::SPU2Options::operator==(const SPU2Options& right) const
{
return OpEqu(bitset) &&
OpEqu(SynchMode) &&
OpEqu(FinalVolume) &&
OpEqu(Latency) &&
OpEqu(OutputLatency) &&
OpEqu(SpeakerConfiguration) &&
OpEqu(DplDecodingLevel) &&
OpEqu(SequenceLenMS) &&
OpEqu(SeekWindowMS) &&
OpEqu(OverlapMS) &&
OpEqu(OutputModule) &&
OpEqu(BackendName) &&
OpEqu(DeviceName);
}
const char* Pcsx2Config::DEV9Options::NetApiNames[] = { const char* Pcsx2Config::DEV9Options::NetApiNames[] = {
"Unset", "Unset",
"PCAP Bridged", "PCAP Bridged",
@ -1100,6 +1227,35 @@ void Pcsx2Config::DEV9Options::LoadSave(SettingsWrapper& wrap)
} }
} }
bool Pcsx2Config::DEV9Options::operator!=(const DEV9Options& right) const
{
return !this->operator==(right);
}
bool Pcsx2Config::DEV9Options::operator==(const DEV9Options& right) const
{
return OpEqu(EthEnable) &&
OpEqu(EthApi) &&
OpEqu(EthDevice) &&
OpEqu(EthLogDNS) &&
OpEqu(InterceptDHCP) &&
(*(int*)PS2IP == *(int*)right.PS2IP) &&
(*(int*)Gateway == *(int*)right.Gateway) &&
(*(int*)DNS1 == *(int*)right.DNS1) &&
(*(int*)DNS2 == *(int*)right.DNS2) &&
OpEqu(AutoMask) &&
OpEqu(AutoGateway) &&
OpEqu(ModeDNS1) &&
OpEqu(ModeDNS2) &&
OpEqu(EthHosts) &&
OpEqu(HddEnable) &&
OpEqu(HddFile);
}
void Pcsx2Config::DEV9Options::LoadIPHelper(u8* field, const std::string& setting) void Pcsx2Config::DEV9Options::LoadIPHelper(u8* field, const std::string& setting)
{ {
if (4 == sscanf(setting.c_str(), "%hhu.%hhu.%hhu.%hhu", &field[0], &field[1], &field[2], &field[3])) if (4 == sscanf(setting.c_str(), "%hhu.%hhu.%hhu.%hhu", &field[0], &field[1], &field[2], &field[3]))
@ -1112,6 +1268,19 @@ std::string Pcsx2Config::DEV9Options::SaveIPHelper(u8* field)
return StringUtil::StdStringFromFormat("%u.%u.%u.%u", field[0], field[1], field[2], field[3]); return StringUtil::StdStringFromFormat("%u.%u.%u.%u", field[0], field[1], field[2], field[3]);
} }
bool Pcsx2Config::DEV9Options::HostEntry::operator==(const HostEntry& right) const
{
return OpEqu(Url) &&
OpEqu(Desc) &&
(*(int*)Address == *(int*)right.Address) &&
OpEqu(Enabled);
}
bool Pcsx2Config::DEV9Options::HostEntry::operator!=(const HostEntry& right) const
{
return !this->operator==(right);
}
static const char* const tbl_GamefixNames[] = static const char* const tbl_GamefixNames[] =
{ {
"FpuMul", "FpuMul",
@ -1181,6 +1350,16 @@ void Pcsx2Config::GamefixOptions::Set(GamefixId id, bool enabled)
} }
} }
bool Pcsx2Config::GamefixOptions::operator!=(const GamefixOptions& right) const
{
return !OpEqu(bitset);
}
bool Pcsx2Config::GamefixOptions::operator==(const GamefixOptions& right) const
{
return OpEqu(bitset);
}
bool Pcsx2Config::GamefixOptions::Get(GamefixId id) const bool Pcsx2Config::GamefixOptions::Get(GamefixId id) const
{ {
switch (id) switch (id)
@ -1261,6 +1440,16 @@ void Pcsx2Config::DebugOptions::LoadSave(SettingsWrapper& wrap)
SettingsWrapBitfield(MemoryViewBytesPerRow); SettingsWrapBitfield(MemoryViewBytesPerRow);
} }
bool Pcsx2Config::DebugOptions::operator!=(const DebugOptions& right) const
{
return !this->operator==(right);
}
bool Pcsx2Config::DebugOptions::operator==(const DebugOptions& right) const
{
return OpEqu(bitset) && OpEqu(FontWidth) && OpEqu(FontHeight) && OpEqu(WindowWidth) && OpEqu(WindowHeight) && OpEqu(MemoryViewBytesPerRow);
}
Pcsx2Config::FilenameOptions::FilenameOptions() Pcsx2Config::FilenameOptions::FilenameOptions()
{ {
} }
@ -1272,6 +1461,16 @@ void Pcsx2Config::FilenameOptions::LoadSave(SettingsWrapper& wrap)
wrap.Entry(CURRENT_SETTINGS_SECTION, "BIOS", Bios, Bios); wrap.Entry(CURRENT_SETTINGS_SECTION, "BIOS", Bios, Bios);
} }
bool Pcsx2Config::FilenameOptions::operator!=(const FilenameOptions& right) const
{
return !this->operator==(right);
}
bool Pcsx2Config::FilenameOptions::operator==(const FilenameOptions& right) const
{
return OpEqu(Bios);
}
Pcsx2Config::EmulationSpeedOptions::EmulationSpeedOptions() Pcsx2Config::EmulationSpeedOptions::EmulationSpeedOptions()
{ {
bitset = 0; bitset = 0;