ActionReplay: Make use of fmt where applicable

Converts the ActionReplay logging over to using fmt instead of
StringFromFormat.
This commit is contained in:
Lioncash 2019-08-21 17:53:23 -04:00
parent c7fc9126aa
commit f414d926c1
1 changed files with 69 additions and 65 deletions

View File

@ -23,7 +23,6 @@
#include <algorithm> #include <algorithm>
#include <atomic> #include <atomic>
#include <cstdarg>
#include <iterator> #include <iterator>
#include <mutex> #include <mutex>
#include <string> #include <string>
@ -31,12 +30,13 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <fmt/format.h>
#include "Common/BitUtils.h" #include "Common/BitUtils.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/IniFile.h" #include "Common/IniFile.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/MsgHandler.h" #include "Common/MsgHandler.h"
#include "Common/StringUtil.h"
#include "Core/ARDecrypt.h" #include "Core/ARDecrypt.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
@ -298,7 +298,7 @@ void SaveCodes(IniFile* local_ini, const std::vector<ARCode>& codes)
lines.emplace_back("$" + code.name); lines.emplace_back("$" + code.name);
for (const ActionReplay::AREntry& op : code.ops) for (const ActionReplay::AREntry& op : code.ops)
{ {
lines.emplace_back(StringFromFormat("%08X %08X", op.cmd_addr, op.value)); lines.emplace_back(fmt::format("{:08X} {:08X}", op.cmd_addr, op.value));
} }
} }
} }
@ -306,18 +306,16 @@ void SaveCodes(IniFile* local_ini, const std::vector<ARCode>& codes)
local_ini->SetLines("ActionReplay", lines); local_ini->SetLines("ActionReplay", lines);
} }
static void LogInfo(const char* format, ...) static void VLogInfo(std::string_view format, fmt::format_args args)
{ {
if (s_disable_logging) if (s_disable_logging)
return; return;
bool use_internal_log = s_use_internal_log.load(std::memory_order_relaxed);
const bool use_internal_log = s_use_internal_log.load(std::memory_order_relaxed);
if (MAX_LOGLEVEL < LogTypes::LINFO && !use_internal_log) if (MAX_LOGLEVEL < LogTypes::LINFO && !use_internal_log)
return; return;
va_list args; std::string text = fmt::vformat(format, args);
va_start(args, format);
std::string text = StringFromFormatV(format, args);
va_end(args);
INFO_LOG(ACTIONREPLAY, "%s", text.c_str()); INFO_LOG(ACTIONREPLAY, "%s", text.c_str());
if (use_internal_log) if (use_internal_log)
@ -327,6 +325,12 @@ static void LogInfo(const char* format, ...)
} }
} }
template <typename... Args>
static void LogInfo(std::string_view format, const Args&... args)
{
VLogInfo(format, fmt::make_format_args(args...));
}
void EnableSelfLogging(bool enable) void EnableSelfLogging(bool enable)
{ {
s_use_internal_log.store(enable, std::memory_order_relaxed); s_use_internal_log.store(enable, std::memory_order_relaxed);
@ -355,8 +359,8 @@ static bool Subtype_RamWriteAndFill(const ARAddr& addr, const u32 data)
{ {
const u32 new_addr = addr.GCAddress(); const u32 new_addr = addr.GCAddress();
LogInfo("Hardware Address: %08x", new_addr); LogInfo("Hardware Address: {:08x}", new_addr);
LogInfo("Size: %08x", addr.size); LogInfo("Size: {:08x}", addr.size);
switch (addr.size) switch (addr.size)
{ {
@ -364,11 +368,11 @@ static bool Subtype_RamWriteAndFill(const ARAddr& addr, const u32 data)
{ {
LogInfo("8-bit Write"); LogInfo("8-bit Write");
LogInfo("--------"); LogInfo("--------");
u32 repeat = data >> 8; const u32 repeat = data >> 8;
for (u32 i = 0; i <= repeat; ++i) for (u32 i = 0; i <= repeat; ++i)
{ {
PowerPC::HostWrite_U8(data & 0xFF, new_addr + i); PowerPC::HostWrite_U8(data & 0xFF, new_addr + i);
LogInfo("Wrote %08x to address %08x", data & 0xFF, new_addr + i); LogInfo("Wrote {:08x} to address {:08x}", data & 0xFF, new_addr + i);
} }
LogInfo("--------"); LogInfo("--------");
break; break;
@ -378,11 +382,11 @@ static bool Subtype_RamWriteAndFill(const ARAddr& addr, const u32 data)
{ {
LogInfo("16-bit Write"); LogInfo("16-bit Write");
LogInfo("--------"); LogInfo("--------");
u32 repeat = data >> 16; const u32 repeat = data >> 16;
for (u32 i = 0; i <= repeat; ++i) for (u32 i = 0; i <= repeat; ++i)
{ {
PowerPC::HostWrite_U16(data & 0xFFFF, new_addr + i * 2); PowerPC::HostWrite_U16(data & 0xFFFF, new_addr + i * 2);
LogInfo("Wrote %08x to address %08x", data & 0xFFFF, new_addr + i * 2); LogInfo("Wrote {:08x} to address {:08x}", data & 0xFFFF, new_addr + i * 2);
} }
LogInfo("--------"); LogInfo("--------");
break; break;
@ -393,7 +397,7 @@ static bool Subtype_RamWriteAndFill(const ARAddr& addr, const u32 data)
LogInfo("32-bit Write"); LogInfo("32-bit Write");
LogInfo("--------"); LogInfo("--------");
PowerPC::HostWrite_U32(data, new_addr); PowerPC::HostWrite_U32(data, new_addr);
LogInfo("Wrote %08x to address %08x", data, new_addr); LogInfo("Wrote {:08x} to address {:08x}", data, new_addr);
LogInfo("--------"); LogInfo("--------");
break; break;
@ -413,8 +417,8 @@ static bool Subtype_WriteToPointer(const ARAddr& addr, const u32 data)
const u32 new_addr = addr.GCAddress(); const u32 new_addr = addr.GCAddress();
const u32 ptr = PowerPC::HostRead_U32(new_addr); const u32 ptr = PowerPC::HostRead_U32(new_addr);
LogInfo("Hardware Address: %08x", new_addr); LogInfo("Hardware Address: {:08x}", new_addr);
LogInfo("Size: %08x", addr.size); LogInfo("Size: {:08x}", addr.size);
switch (addr.size) switch (addr.size)
{ {
@ -424,11 +428,11 @@ static bool Subtype_WriteToPointer(const ARAddr& addr, const u32 data)
LogInfo("--------"); LogInfo("--------");
const u8 thebyte = data & 0xFF; const u8 thebyte = data & 0xFF;
const u32 offset = data >> 8; const u32 offset = data >> 8;
LogInfo("Pointer: %08x", ptr); LogInfo("Pointer: {:08x}", ptr);
LogInfo("Byte: %08x", thebyte); LogInfo("Byte: {:08x}", thebyte);
LogInfo("Offset: %08x", offset); LogInfo("Offset: {:08x}", offset);
PowerPC::HostWrite_U8(thebyte, ptr + offset); PowerPC::HostWrite_U8(thebyte, ptr + offset);
LogInfo("Wrote %08x to address %08x", thebyte, ptr + offset); LogInfo("Wrote {:08x} to address {:08x}", thebyte, ptr + offset);
LogInfo("--------"); LogInfo("--------");
break; break;
} }
@ -439,11 +443,11 @@ static bool Subtype_WriteToPointer(const ARAddr& addr, const u32 data)
LogInfo("--------"); LogInfo("--------");
const u16 theshort = data & 0xFFFF; const u16 theshort = data & 0xFFFF;
const u32 offset = (data >> 16) << 1; const u32 offset = (data >> 16) << 1;
LogInfo("Pointer: %08x", ptr); LogInfo("Pointer: {:08x}", ptr);
LogInfo("Byte: %08x", theshort); LogInfo("Byte: {:08x}", theshort);
LogInfo("Offset: %08x", offset); LogInfo("Offset: {:08x}", offset);
PowerPC::HostWrite_U16(theshort, ptr + offset); PowerPC::HostWrite_U16(theshort, ptr + offset);
LogInfo("Wrote %08x to address %08x", theshort, ptr + offset); LogInfo("Wrote {:08x} to address {:08x}", theshort, ptr + offset);
LogInfo("--------"); LogInfo("--------");
break; break;
} }
@ -453,7 +457,7 @@ static bool Subtype_WriteToPointer(const ARAddr& addr, const u32 data)
LogInfo("Write 32-bit to pointer"); LogInfo("Write 32-bit to pointer");
LogInfo("--------"); LogInfo("--------");
PowerPC::HostWrite_U32(data, ptr); PowerPC::HostWrite_U32(data, ptr);
LogInfo("Wrote %08x to address %08x", data, ptr); LogInfo("Wrote {:08x} to address {:08x}", data, ptr);
LogInfo("--------"); LogInfo("--------");
break; break;
@ -472,8 +476,8 @@ static bool Subtype_AddCode(const ARAddr& addr, const u32 data)
// Used to increment/decrement a value in memory // Used to increment/decrement a value in memory
const u32 new_addr = addr.GCAddress(); const u32 new_addr = addr.GCAddress();
LogInfo("Hardware Address: %08x", new_addr); LogInfo("Hardware Address: {:08x}", new_addr);
LogInfo("Size: %08x", addr.size); LogInfo("Size: {:08x}", addr.size);
switch (addr.size) switch (addr.size)
{ {
@ -481,7 +485,7 @@ static bool Subtype_AddCode(const ARAddr& addr, const u32 data)
LogInfo("8-bit Add"); LogInfo("8-bit Add");
LogInfo("--------"); LogInfo("--------");
PowerPC::HostWrite_U8(PowerPC::HostRead_U8(new_addr) + data, new_addr); PowerPC::HostWrite_U8(PowerPC::HostRead_U8(new_addr) + data, new_addr);
LogInfo("Wrote %02x to address %08x", PowerPC::HostRead_U8(new_addr), new_addr); LogInfo("Wrote {:02x} to address {:08x}", PowerPC::HostRead_U8(new_addr), new_addr);
LogInfo("--------"); LogInfo("--------");
break; break;
@ -489,7 +493,7 @@ static bool Subtype_AddCode(const ARAddr& addr, const u32 data)
LogInfo("16-bit Add"); LogInfo("16-bit Add");
LogInfo("--------"); LogInfo("--------");
PowerPC::HostWrite_U16(PowerPC::HostRead_U16(new_addr) + data, new_addr); PowerPC::HostWrite_U16(PowerPC::HostRead_U16(new_addr) + data, new_addr);
LogInfo("Wrote %04x to address %08x", PowerPC::HostRead_U16(new_addr), new_addr); LogInfo("Wrote {:04x} to address {:08x}", PowerPC::HostRead_U16(new_addr), new_addr);
LogInfo("--------"); LogInfo("--------");
break; break;
@ -497,7 +501,7 @@ static bool Subtype_AddCode(const ARAddr& addr, const u32 data)
LogInfo("32-bit Add"); LogInfo("32-bit Add");
LogInfo("--------"); LogInfo("--------");
PowerPC::HostWrite_U32(PowerPC::HostRead_U32(new_addr) + data, new_addr); PowerPC::HostWrite_U32(PowerPC::HostRead_U32(new_addr) + data, new_addr);
LogInfo("Wrote %08x to address %08x", PowerPC::HostRead_U32(new_addr), new_addr); LogInfo("Wrote {:08x} to address {:08x}", PowerPC::HostRead_U32(new_addr), new_addr);
LogInfo("--------"); LogInfo("--------");
break; break;
@ -512,9 +516,9 @@ static bool Subtype_AddCode(const ARAddr& addr, const u32 data)
const float fread = read_float + static_cast<float>(data); const float fread = read_float + static_cast<float>(data);
const u32 newval = Common::BitCast<u32>(fread); const u32 newval = Common::BitCast<u32>(fread);
PowerPC::HostWrite_U32(newval, new_addr); PowerPC::HostWrite_U32(newval, new_addr);
LogInfo("Old Value %08x", read); LogInfo("Old Value {:08x}", read);
LogInfo("Increment %08x", data); LogInfo("Increment {:08x}", data);
LogInfo("New value %08x", newval); LogInfo("New value {:08x}", newval);
LogInfo("--------"); LogInfo("--------");
break; break;
} }
@ -555,11 +559,11 @@ static bool ZeroCode_FillAndSlide(const u32 val_last, const ARAddr& addr, const
u32 val = addr; u32 val = addr;
u32 curr_addr = new_addr; u32 curr_addr = new_addr;
LogInfo("Current Hardware Address: %08x", new_addr); LogInfo("Current Hardware Address: {:08x}", new_addr);
LogInfo("Size: %08x", addr.size); LogInfo("Size: {:08x}", addr.size);
LogInfo("Write Num: %08x", write_num); LogInfo("Write Num: {:08x}", write_num);
LogInfo("Address Increment: %i", addr_incr); LogInfo("Address Increment: {}", addr_incr);
LogInfo("Value Increment: %i", val_incr); LogInfo("Value Increment: {}", s32{val_incr});
switch (size) switch (size)
{ {
@ -571,10 +575,10 @@ static bool ZeroCode_FillAndSlide(const u32 val_last, const ARAddr& addr, const
PowerPC::HostWrite_U8(val & 0xFF, curr_addr); PowerPC::HostWrite_U8(val & 0xFF, curr_addr);
curr_addr += addr_incr; curr_addr += addr_incr;
val += val_incr; val += val_incr;
LogInfo("Write %08x to address %08x", val & 0xFF, curr_addr); LogInfo("Write {:08x} to address {:08x}", val & 0xFF, curr_addr);
LogInfo("Value Update: %08x", val); LogInfo("Value Update: {:08x}", val);
LogInfo("Current Hardware Address Update: %08x", curr_addr); LogInfo("Current Hardware Address Update: {:08x}", curr_addr);
} }
LogInfo("--------"); LogInfo("--------");
break; break;
@ -585,11 +589,11 @@ static bool ZeroCode_FillAndSlide(const u32 val_last, const ARAddr& addr, const
for (int i = 0; i < write_num; ++i) for (int i = 0; i < write_num; ++i)
{ {
PowerPC::HostWrite_U16(val & 0xFFFF, curr_addr); PowerPC::HostWrite_U16(val & 0xFFFF, curr_addr);
LogInfo("Write %08x to address %08x", val & 0xFFFF, curr_addr); LogInfo("Write {:08x} to address {:08x}", val & 0xFFFF, curr_addr);
curr_addr += addr_incr * 2; curr_addr += addr_incr * 2;
val += val_incr; val += val_incr;
LogInfo("Value Update: %08x", val); LogInfo("Value Update: {:08x}", val);
LogInfo("Current Hardware Address Update: %08x", curr_addr); LogInfo("Current Hardware Address Update: {:08x}", curr_addr);
} }
LogInfo("--------"); LogInfo("--------");
break; break;
@ -600,11 +604,11 @@ static bool ZeroCode_FillAndSlide(const u32 val_last, const ARAddr& addr, const
for (int i = 0; i < write_num; ++i) for (int i = 0; i < write_num; ++i)
{ {
PowerPC::HostWrite_U32(val, curr_addr); PowerPC::HostWrite_U32(val, curr_addr);
LogInfo("Write %08x to address %08x", val, curr_addr); LogInfo("Write {:08x} to address {:08x}", val, curr_addr);
curr_addr += addr_incr * 4; curr_addr += addr_incr * 4;
val += val_incr; val += val_incr;
LogInfo("Value Update: %08x", val); LogInfo("Value Update: {:08x}", val);
LogInfo("Current Hardware Address Update: %08x", curr_addr); LogInfo("Current Hardware Address Update: {:08x}", curr_addr);
} }
LogInfo("--------"); LogInfo("--------");
break; break;
@ -628,9 +632,9 @@ static bool ZeroCode_MemoryCopy(const u32 val_last, const ARAddr& addr, const u3
const u8 num_bytes = data & 0x7FFF; const u8 num_bytes = data & 0x7FFF;
LogInfo("Dest Address: %08x", addr_dest); LogInfo("Dest Address: {:08x}", addr_dest);
LogInfo("Src Address: %08x", addr_src); LogInfo("Src Address: {:08x}", addr_src);
LogInfo("Size: %08x", num_bytes); LogInfo("Size: {:08x}", num_bytes);
if ((data & 0xFF0000) == 0) if ((data & 0xFF0000) == 0)
{ {
@ -639,13 +643,13 @@ static bool ZeroCode_MemoryCopy(const u32 val_last, const ARAddr& addr, const u3
LogInfo("Memory Copy With Pointers Support"); LogInfo("Memory Copy With Pointers Support");
LogInfo("--------"); LogInfo("--------");
const u32 ptr_dest = PowerPC::HostRead_U32(addr_dest); const u32 ptr_dest = PowerPC::HostRead_U32(addr_dest);
LogInfo("Resolved Dest Address to: %08x", ptr_dest); LogInfo("Resolved Dest Address to: {:08x}", ptr_dest);
const u32 ptr_src = PowerPC::HostRead_U32(addr_src); const u32 ptr_src = PowerPC::HostRead_U32(addr_src);
LogInfo("Resolved Src Address to: %08x", ptr_src); LogInfo("Resolved Src Address to: {:08x}", ptr_src);
for (int i = 0; i < num_bytes; ++i) for (int i = 0; i < num_bytes; ++i)
{ {
PowerPC::HostWrite_U8(PowerPC::HostRead_U8(ptr_src + i), ptr_dest + i); PowerPC::HostWrite_U8(PowerPC::HostRead_U8(ptr_src + i), ptr_dest + i);
LogInfo("Wrote %08x to address %08x", PowerPC::HostRead_U8(ptr_src + i), ptr_dest + i); LogInfo("Wrote {:08x} to address {:08x}", PowerPC::HostRead_U8(ptr_src + i), ptr_dest + i);
} }
LogInfo("--------"); LogInfo("--------");
} }
@ -656,7 +660,8 @@ static bool ZeroCode_MemoryCopy(const u32 val_last, const ARAddr& addr, const u3
for (int i = 0; i < num_bytes; ++i) for (int i = 0; i < num_bytes; ++i)
{ {
PowerPC::HostWrite_U8(PowerPC::HostRead_U8(addr_src + i), addr_dest + i); PowerPC::HostWrite_U8(PowerPC::HostRead_U8(addr_src + i), addr_dest + i);
LogInfo("Wrote %08x to address %08x", PowerPC::HostRead_U8(addr_src + i), addr_dest + i); LogInfo("Wrote {:08x} to address {:08x}", PowerPC::HostRead_U8(addr_src + i),
addr_dest + i);
} }
LogInfo("--------"); LogInfo("--------");
return true; return true;
@ -754,8 +759,8 @@ static bool ConditionalCode(const ARAddr& addr, const u32 data, int* const pSkip
{ {
const u32 new_addr = addr.GCAddress(); const u32 new_addr = addr.GCAddress();
LogInfo("Size: %08x", addr.size); LogInfo("Size: {:08x}", addr.size);
LogInfo("Hardware Address: %08x", new_addr); LogInfo("Hardware Address: {:08x}", new_addr);
bool result = true; bool result = true;
@ -824,8 +829,8 @@ static bool RunCodeLocked(const ARCode& arcode)
s_current_code = &arcode; s_current_code = &arcode;
LogInfo("Code Name: %s", arcode.name.c_str()); LogInfo("Code Name: {}", arcode.name);
LogInfo("Number of codes: %zu", arcode.ops.size()); LogInfo("Number of codes: {}", arcode.ops.size());
for (const AREntry& entry : arcode.ops) for (const AREntry& entry : arcode.ops)
{ {
@ -857,8 +862,7 @@ static bool RunCodeLocked(const ARCode& arcode)
continue; continue;
} }
LogInfo("--- Running Code: %08x %08x ---", addr.address, data); LogInfo("--- Running Code: {:08x} {:08x} ---", addr.address, data);
// LogInfo("Command: %08x", cmd);
// Do Fill & Slide // Do Fill & Slide
if (do_fill_and_slide) if (do_fill_and_slide)
@ -900,7 +904,7 @@ static bool RunCodeLocked(const ARCode& arcode)
{ {
const u8 zcode = data >> 29; const u8 zcode = data >> 29;
LogInfo("Doing Zero Code %08x", zcode); LogInfo("Doing Zero Code {:08x}", zcode);
switch (zcode) switch (zcode)
{ {
@ -948,8 +952,8 @@ static bool RunCodeLocked(const ARCode& arcode)
} }
// Normal codes // Normal codes
LogInfo("Doing Normal Code %08x", addr.type); LogInfo("Doing Normal Code {:08x}", addr.type);
LogInfo("Subtype: %08x", addr.subtype); LogInfo("Subtype: {:08x}", addr.subtype);
switch (addr.type) switch (addr.type)
{ {