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 <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>
[[maybe_unused]] __fi static T GetBufferT(u8* buffer, u32 offset)
{

View File

@ -10,6 +10,20 @@
#include <optional>
#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 SettingsWrapper;
@ -389,20 +403,10 @@ struct TraceFiltersEE
m_EnableEvents : 1; // Enables logging of event-driven activity -- counters, DMAs, etc.
BITFIELD_END
TraceFiltersEE()
{
bitset = 0;
}
TraceFiltersEE();
bool operator==(const TraceFiltersEE& right) const
{
return OpEqu(bitset);
}
bool operator!=(const TraceFiltersEE& right) const
{
return !this->operator==(right);
}
bool operator==(const TraceFiltersEE& right) const;
bool operator!=(const TraceFiltersEE& right) const;
};
// --------------------------------------------------------------------------------------
@ -418,20 +422,10 @@ struct TraceFiltersIOP
m_EnableEvents : 1; // Enables logging of event-driven activity -- counters, DMAs, etc.
BITFIELD_END
TraceFiltersIOP()
{
bitset = 0;
}
TraceFiltersIOP();
bool operator==(const TraceFiltersIOP& right) const
{
return OpEqu(bitset);
}
bool operator!=(const TraceFiltersIOP& right) const
{
return !this->operator==(right);
}
bool operator==(const TraceFiltersIOP& right) const;
bool operator!=(const TraceFiltersIOP& right) const;
};
// --------------------------------------------------------------------------------------
@ -450,22 +444,12 @@ struct TraceLogFilters
TraceFiltersEE EE;
TraceFiltersIOP IOP;
TraceLogFilters()
{
Enabled = false;
}
TraceLogFilters();
void LoadSave(SettingsWrapper& ini);
bool operator==(const TraceLogFilters& right) const
{
return OpEqu(Enabled) && OpEqu(EE) && OpEqu(IOP);
}
bool operator!=(const TraceLogFilters& right) const
{
return !this->operator==(right);
}
bool operator==(const TraceLogFilters& right) const;
bool operator!=(const TraceLogFilters& right) const;
};
// --------------------------------------------------------------------------------------
@ -493,21 +477,11 @@ struct Pcsx2Config
BITFIELD_END
// Default is Disabled, with all recs enabled underneath.
ProfilerOptions()
: bitset(0xfffffffe)
{
}
ProfilerOptions();
void LoadSave(SettingsWrapper& wrap);
bool operator==(const ProfilerOptions& right) const
{
return OpEqu(bitset);
}
bool operator!=(const ProfilerOptions& right) const
{
return !OpEqu(bitset);
}
bool operator==(const ProfilerOptions& right) const;
bool operator!=(const ProfilerOptions& right) const;
};
// ------------------------------------------------------------------------
@ -550,32 +524,13 @@ struct Pcsx2Config
void LoadSave(SettingsWrapper& wrap);
bool operator==(const RecompilerOptions& right) const
{
return OpEqu(bitset);
}
bool operator==(const RecompilerOptions& right) const;
bool operator!=(const RecompilerOptions& right) const;
bool operator!=(const RecompilerOptions& right) const
{
return !OpEqu(bitset);
}
u32 GetEEClampMode() const;
void SetEEClampMode(u32 value);
u32 GetEEClampMode() 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));
}
u32 GetVUClampMode() const;
};
// ------------------------------------------------------------------------
@ -595,15 +550,8 @@ struct Pcsx2Config
bool CpusChanged(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);
}
bool operator==(const CpuOptions& right) const;
bool operator!=(const CpuOptions& right) const;
};
// ------------------------------------------------------------------------
@ -876,31 +824,8 @@ struct Pcsx2Config
void LoadSave(SettingsWrapper& wrap);
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);
}
bool operator==(const SPU2Options& right) const;
bool operator!=(const SPU2Options& right) const;
};
struct DEV9Options
@ -930,18 +855,8 @@ struct Pcsx2Config
u8 Address[4]{};
bool Enabled;
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 operator==(const HostEntry& right) const;
bool operator!=(const HostEntry& right) const;
};
bool EthEnable{false};
@ -969,34 +884,8 @@ struct Pcsx2Config
void LoadSave(SettingsWrapper& wrap);
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);
}
bool operator==(const DEV9Options& right) const;
bool operator!=(const DEV9Options& right) const;
protected:
static void LoadIPHelper(u8* field, const std::string& setting);
@ -1040,15 +929,8 @@ struct Pcsx2Config
void Set(GamefixId id, bool enabled = true);
void Clear(GamefixId id) { Set(id, false); }
bool operator==(const GamefixOptions& right) const
{
return OpEqu(bitset);
}
bool operator!=(const GamefixOptions& right) const
{
return !OpEqu(bitset);
}
bool operator==(const GamefixOptions& right) const;
bool operator!=(const GamefixOptions& right) const;
};
// ------------------------------------------------------------------------
@ -1102,15 +984,8 @@ struct Pcsx2Config
DebugOptions();
void LoadSave(SettingsWrapper& wrap);
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);
}
bool operator==(const DebugOptions& right) const;
bool operator!=(const DebugOptions& right) const;
};
// ------------------------------------------------------------------------
@ -1142,15 +1017,8 @@ struct Pcsx2Config
FilenameOptions();
void LoadSave(SettingsWrapper& wrap);
bool operator==(const FilenameOptions& right) const
{
return OpEqu(Bios);
}
bool operator!=(const FilenameOptions& right) const
{
return !this->operator==(right);
}
bool operator==(const FilenameOptions& right) const;
bool operator!=(const FilenameOptions& right) const;
};
// ------------------------------------------------------------------------
@ -1448,3 +1316,6 @@ namespace EmuFolders
// Change to 1 for console logs of SIF, GPU (PS1 mode) and MDEC (PS1 mode).
// These do spam a lot though!
#define PSX_EXTRALOGS 0
#undef BITFIELD32
#undef BITFIELD_END

View File

@ -22,6 +22,10 @@
#include <ShlObj.h>
#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.
static constexpr FPControlRegister DEFAULT_FPU_FP_CONTROL_REGISTER = FPControlRegister::GetDefault()
.DisableExceptions()
@ -168,6 +172,41 @@ namespace EmuFolders
static void SetDataDirectory();
} // 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)
{
SettingsWrapSection("EmuCore/TraceLog");
@ -181,6 +220,16 @@ void TraceLogFilters::LoadSave(SettingsWrapper& wrap)
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[] = {
"mvuFlag",
"instantVU1",
@ -274,6 +323,11 @@ void Pcsx2Config::SpeedhackOptions::LoadSave(SettingsWrapper& wrap)
EECycleSkip = std::min(EECycleSkip, MAX_EE_CYCLE_SKIP);
}
Pcsx2Config::ProfilerOptions::ProfilerOptions()
: bitset(0xfffffffe)
{
}
void Pcsx2Config::ProfilerOptions::LoadSave(SettingsWrapper& wrap)
{
SettingsWrapSection("EmuCore/Profiler");
@ -285,6 +339,16 @@ void Pcsx2Config::ProfilerOptions::LoadSave(SettingsWrapper& wrap)
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()
{
bitset = 0;
@ -394,6 +458,33 @@ void Pcsx2Config::RecompilerOptions::LoadSave(SettingsWrapper& wrap)
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
{
return (Recompiler.EnableEE != right.Recompiler.EnableEE ||
@ -402,6 +493,16 @@ bool Pcsx2Config::CpuOptions::CpusChanged(const CpuOptions& right) const
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()
{
FPUFPCR = DEFAULT_FPU_FP_CONTROL_REGISTER;
@ -991,6 +1092,32 @@ void Pcsx2Config::SPU2Options::LoadSave(SettingsWrapper& wrap)
// 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[] = {
"Unset",
"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)
{
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]);
}
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[] =
{
"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
{
switch (id)
@ -1261,6 +1440,16 @@ void Pcsx2Config::DebugOptions::LoadSave(SettingsWrapper& wrap)
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()
{
}
@ -1272,6 +1461,16 @@ void Pcsx2Config::FilenameOptions::LoadSave(SettingsWrapper& wrap)
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()
{
bitset = 0;