mirror of
https://github.com/PCSX2/pcsx2.git
synced 2026-10-12 02:08:45 +00:00
IR3000A: Use SmallString with Zydis formatter
This commit is contained in:
+21
-18
@@ -101,56 +101,59 @@ static void iopRecError(int err);
|
||||
static ZydisFormatterFunc s_old_print_address;
|
||||
static ZydisFormatterFunc s_old_print_disp;
|
||||
|
||||
static int Address2Symbol(u64 address, char* buf)
|
||||
static bool Address2Symbol(u64 address, SmallString &buf)
|
||||
{
|
||||
u32 len = 0;
|
||||
|
||||
#define A(x) ((u64)(x))
|
||||
|
||||
if (address >= A(iopMem->Main) && address < A(iopMem->P))
|
||||
{
|
||||
len = sprintf(buf, "iopMem+0x%08X", static_cast<u32>(address - A(iopMem->Main)));
|
||||
buf.append_format("iopMem+0x{:08X}", static_cast<u32>(address - A(iopMem->Main)));
|
||||
}
|
||||
else if (address >= A(&psxRegs.GPR) && address < A(&psxRegs.CP0))
|
||||
{
|
||||
len = sprintf(buf, "psxRegs.GPR.%s", R3000A::disRNameGPR[static_cast<u32>(address - A(&psxRegs)) / 4u]);
|
||||
buf.append_format("psxRegs.GPR.{}", R3000A::disRNameGPR[static_cast<u32>(address - A(&psxRegs)) / 4u]);
|
||||
}
|
||||
else if (address == A(&psxRegs.pc))
|
||||
{
|
||||
len = sprintf(buf, "psxRegs.pc");
|
||||
buf.append("psxRegs.pc");
|
||||
}
|
||||
else if (address == A(&psxRegs.cycle))
|
||||
{
|
||||
len = sprintf(buf, "psxRegs.cycle");
|
||||
buf.append("psxRegs.cycle");
|
||||
}
|
||||
else if (address == A(&psxRegs.iopNextEventCycle))
|
||||
{
|
||||
len = sprintf(buf, "psxRegs.iopNextEventCycle");
|
||||
buf.append("psxRegs.iopNextEventCycle");
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#undef A
|
||||
|
||||
return len;
|
||||
return true;
|
||||
}
|
||||
|
||||
static ZyanStatus ZydisFormatterPrintDisplacement(const ZydisFormatter* formatter,
|
||||
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context)
|
||||
{
|
||||
char buf[128];
|
||||
u32 len = 0;
|
||||
u64 address = (u64)R3000A_TEXTPTR + context->operand->mem.disp.value;
|
||||
bool did_print = false;
|
||||
SmallString buf;
|
||||
|
||||
// hardcoded RTEXTPTR
|
||||
if (context->operand->mem.base == ZYDIS_REGISTER_RBX) {
|
||||
len = Address2Symbol(address, buf);
|
||||
did_print = Address2Symbol(address, buf);
|
||||
}
|
||||
|
||||
if (len > 0)
|
||||
if (did_print)
|
||||
{
|
||||
ZYAN_CHECK(ZydisFormatterBufferAppend(buffer, ZYDIS_TOKEN_SYMBOL));
|
||||
ZyanString* string;
|
||||
ZYAN_CHECK(ZydisFormatterBufferGetString(buffer, &string));
|
||||
return ZyanStringAppendFormat(string, "-%s+&%s", "R3000A_TEXTPTR", buf);
|
||||
return ZyanStringAppendFormat(string, "-%s+&%s", "R3000A_TEXTPTR", buf.c_str());
|
||||
}
|
||||
|
||||
return s_old_print_disp(formatter, buffer, context);
|
||||
@@ -163,17 +166,17 @@ static ZyanStatus ZydisFormatterPrintAddressAbsolute(const ZydisFormatter* forma
|
||||
ZYAN_CHECK(ZydisCalcAbsoluteAddress(context->instruction, context->operand,
|
||||
context->runtime_address, &address));
|
||||
|
||||
char buf[128];
|
||||
u32 len = 0;
|
||||
SmallString buf;
|
||||
bool did_print = false;
|
||||
|
||||
len = Address2Symbol(address, buf);
|
||||
did_print = Address2Symbol(address, buf);
|
||||
|
||||
if (len > 0)
|
||||
if (did_print)
|
||||
{
|
||||
ZYAN_CHECK(ZydisFormatterBufferAppend(buffer, ZYDIS_TOKEN_SYMBOL));
|
||||
ZyanString* string;
|
||||
ZYAN_CHECK(ZydisFormatterBufferGetString(buffer, &string));
|
||||
return ZyanStringAppendFormat(string, "&%s", buf);
|
||||
return ZyanStringAppendFormat(string, "&%s", buf.c_str());
|
||||
}
|
||||
|
||||
return s_old_print_address(formatter, buffer, context);
|
||||
|
||||
Reference in New Issue
Block a user