From 54e13015d87c23e32176235b3a2fde707ae60155 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 28 Sep 2020 20:24:58 +1000 Subject: [PATCH] Cheats: Implement C2/memory copy instruction --- src/core/cheats.cpp | 26 ++++++++++++++++++++++++++ src/core/cheats.h | 3 ++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/core/cheats.cpp b/src/core/cheats.cpp index c031e041b..f73594aad 100644 --- a/src/core/cheats.cpp +++ b/src/core/cheats.cpp @@ -579,6 +579,32 @@ void CheatCode::Apply() const } break; + case InstructionCode::MemoryCopy: + { + if ((index + 1) >= instructions.size()) + { + Log_ErrorPrintf("Incomplete memory copy instruction"); + return; + } + + const Instruction& inst2 = instructions[index + 1]; + const u32 byte_count = inst.value16; + u32 src_address = inst.address; + u32 dst_address = inst2.address; + + for (u32 i = 0; i < byte_count; i++) + { + u8 value = 0; + CPU::SafeReadMemoryByte(src_address, &value); + CPU::SafeWriteMemoryByte(dst_address, value); + src_address++; + dst_address++; + } + + index += 2; + } + break; + default: { Log_ErrorPrintf("Unhandled instruction code 0x%02X (%08X %08X)", static_cast(inst.code.GetValue()), diff --git a/src/core/cheats.h b/src/core/cheats.h index a4f7091a0..6447eb64d 100644 --- a/src/core/cheats.h +++ b/src/core/cheats.h @@ -24,7 +24,8 @@ struct CheatCode CompareNotEqual8 = 0xE1, CompareLess8 = 0xE2, CompareGreater8 = 0xE3, - Slide = 0x50 + Slide = 0x50, + MemoryCopy = 0xC2 }; union Instruction