From e691ec126fbb1e987b7d8910694347b2d38dfca7 Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Fri, 6 Oct 2017 12:32:24 +0000 Subject: [PATCH 1/2] ActionReplay: Fix implementation of memory-copy zero codes This fixes the implementation of the non-standard size-3 zero codes to conform to kenobi's specification. --- Source/Core/Core/ActionReplay.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Source/Core/Core/ActionReplay.cpp b/Source/Core/Core/ActionReplay.cpp index c36beba268..aedfc3e609 100644 --- a/Source/Core/Core/ActionReplay.cpp +++ b/Source/Core/Core/ActionReplay.cpp @@ -586,10 +586,12 @@ static bool ZeroCode_FillAndSlide(const u32 val_last, const ARAddr& addr, const return true; } -// Looks like this is new?? - untested +// kenobi's "memory copy" Z-code. Requires an additional master code +// on a real AR device. Documented here: +// https://github.com/dolphin-emu/dolphin/wiki/GameCube-Action-Replay-Code-Types#type-z4-size-3--memory-copy static bool ZeroCode_MemoryCopy(const u32 val_last, const ARAddr& addr, const u32 data) { - const u32 addr_dest = val_last | 0x06000000; + const u32 addr_dest = val_last & ~0x06000000; const u32 addr_src = addr.GCAddress(); const u8 num_bytes = data & 0x7FFF; @@ -598,16 +600,20 @@ static bool ZeroCode_MemoryCopy(const u32 val_last, const ARAddr& addr, const u3 LogInfo("Src Address: %08x", addr_src); LogInfo("Size: %08x", num_bytes); - if ((data & ~0x7FFF) == 0x0000) + if ((data & 0xFF0000) == 0) { if ((data >> 24) != 0x0) { // Memory Copy With Pointers Support LogInfo("Memory Copy With Pointers Support"); LogInfo("--------"); - for (int i = 0; i < 138; ++i) + const u32 ptr_dest = PowerPC::HostRead_U32(addr_dest); + LogInfo("Resolved Dest Address to: %08x", ptr_dest); + const u32 ptr_src = PowerPC::HostRead_U32(addr_src); + LogInfo("Resolved Src Address to: %08x", ptr_src); + for (int i = 0; i < num_bytes; ++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); + 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("--------"); } From 187a599b366efb624c8d5322fa7003bea0120a73 Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Fri, 6 Oct 2017 13:17:15 +0000 Subject: [PATCH 2/2] ActionReplay: Fix logging in Subtype_AddCode The addition was being repeated (for logging) after it was committed to memory, thus causing bogus values to appear in the log. --- Source/Core/Core/ActionReplay.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Source/Core/Core/ActionReplay.cpp b/Source/Core/Core/ActionReplay.cpp index aedfc3e609..6055a7057c 100644 --- a/Source/Core/Core/ActionReplay.cpp +++ b/Source/Core/Core/ActionReplay.cpp @@ -448,7 +448,7 @@ static bool Subtype_AddCode(const ARAddr& addr, const u32 data) LogInfo("8-bit Add"); LogInfo("--------"); PowerPC::HostWrite_U8(PowerPC::HostRead_U8(new_addr) + data, new_addr); - LogInfo("Wrote %08x to address %08x", PowerPC::HostRead_U8(new_addr) + (data & 0xFF), new_addr); + LogInfo("Wrote %02x to address %08x", PowerPC::HostRead_U8(new_addr), new_addr); LogInfo("--------"); break; @@ -456,8 +456,7 @@ static bool Subtype_AddCode(const ARAddr& addr, const u32 data) LogInfo("16-bit Add"); LogInfo("--------"); PowerPC::HostWrite_U16(PowerPC::HostRead_U16(new_addr) + data, new_addr); - LogInfo("Wrote %08x to address %08x", PowerPC::HostRead_U16(new_addr) + (data & 0xFFFF), - new_addr); + LogInfo("Wrote %04x to address %08x", PowerPC::HostRead_U16(new_addr), new_addr); LogInfo("--------"); break; @@ -465,7 +464,7 @@ static bool Subtype_AddCode(const ARAddr& addr, const u32 data) LogInfo("32-bit Add"); LogInfo("--------"); PowerPC::HostWrite_U32(PowerPC::HostRead_U32(new_addr) + data, new_addr); - LogInfo("Wrote %08x to address %08x", PowerPC::HostRead_U32(new_addr) + data, new_addr); + LogInfo("Wrote %08x to address %08x", PowerPC::HostRead_U32(new_addr), new_addr); LogInfo("--------"); break;