From d2c98639a8a1169a0ed8fa6390998b6ec8aba966 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 17 Dec 2020 23:33:00 +1000 Subject: [PATCH] Cheats: Add extension 32-bit instructions variants --- src/core/cheats.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++++ src/core/cheats.h | 14 ++++++++- 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/src/core/cheats.cpp b/src/core/cheats.cpp index 8fe7cccf5..c9a17933c 100644 --- a/src/core/cheats.cpp +++ b/src/core/cheats.cpp @@ -880,6 +880,13 @@ void CheatCode::Apply() const } break; + case InstructionCode::ExtConstantWrite32: + { + DoMemoryWrite(inst.address, inst.value32); + index++; + } + break; + case InstructionCode::ScratchpadWrite16: { DoMemoryWrite(CPU::DCACHE_LOCATION | (inst.address & CPU::DCACHE_OFFSET_MASK), inst.value16); @@ -887,6 +894,29 @@ void CheatCode::Apply() const } break; + case InstructionCode::ExtScratchpadWrite32: + { + DoMemoryWrite(CPU::DCACHE_LOCATION | (inst.address & CPU::DCACHE_OFFSET_MASK), inst.value32); + index++; + } + break; + + case InstructionCode::ExtIncrement32: + { + const u32 value = DoMemoryRead(inst.address); + DoMemoryWrite(inst.address, value + inst.value32); + index++; + } + break; + + case InstructionCode::ExtDecrement32: + { + const u32 value = DoMemoryRead(inst.address); + DoMemoryWrite(inst.address, value - inst.value32); + index++; + } + break; + case InstructionCode::Increment16: { const u16 value = DoMemoryRead(inst.address); @@ -919,6 +949,46 @@ void CheatCode::Apply() const } break; + case InstructionCode::ExtCompareEqual32: + { + const u32 value = DoMemoryRead(inst.address); + if (value == inst.value32) + index++; + else + index = GetNextNonConditionalInstruction(index); + } + break; + + case InstructionCode::ExtCompareNotEqual32: + { + const u32 value = DoMemoryRead(inst.address); + if (value != inst.value32) + index++; + else + index = GetNextNonConditionalInstruction(index); + } + break; + + case InstructionCode::ExtCompareLess32: + { + const u32 value = DoMemoryRead(inst.address); + if (value < inst.value32) + index++; + else + index = GetNextNonConditionalInstruction(index); + } + break; + + case InstructionCode::ExtCompareGreater32: + { + const u32 value = DoMemoryRead(inst.address); + if (value > inst.value32) + index++; + else + index = GetNextNonConditionalInstruction(index); + } + break; + case InstructionCode::CompareEqual16: { const u16 value = DoMemoryRead(inst.address); @@ -1009,6 +1079,7 @@ void CheatCode::Apply() const break; case InstructionCode::SkipIfNotEqual16: // C0 + case InstructionCode::ExtSkipIfNotEqual32: // A4 case InstructionCode::SkipIfButtonsNotEqual: // D5 case InstructionCode::SkipIfButtonsEqual: // D6 { @@ -1020,6 +1091,9 @@ void CheatCode::Apply() const case InstructionCode::SkipIfNotEqual16: // C0 activate_codes = (DoMemoryRead(inst.address) == inst.value16); break; + case InstructionCode::ExtSkipIfNotEqual32: // A4 + activate_codes = (DoMemoryRead(inst.address) == inst.value32); + break; case InstructionCode::SkipIfButtonsNotEqual: // D5 activate_codes = (GetControllerButtonBits() == inst.value16); break; diff --git a/src/core/cheats.h b/src/core/cheats.h index 200c05fa9..b6d69e4b1 100644 --- a/src/core/cheats.h +++ b/src/core/cheats.h @@ -44,7 +44,18 @@ struct CheatCode CompareLess8 = 0xE2, CompareGreater8 = 0xE3, Slide = 0x50, - MemoryCopy = 0xC2 + MemoryCopy = 0xC2, + + // Extension opcodes, not present on original GameShark. + ExtConstantWrite32 = 0x90, + ExtScratchpadWrite32 = 0xA5, + ExtCompareEqual32 = 0xA0, + ExtCompareNotEqual32 = 0xA1, + ExtCompareLess32 = 0xA2, + ExtCompareGreater32 = 0xA3, + ExtSkipIfNotEqual32 = 0xA4, + ExtIncrement32 = 0x60, + ExtDecrement32 = 0x61, }; union Instruction @@ -59,6 +70,7 @@ struct CheatCode BitField code; BitField address; + BitField value32; BitField value16; BitField value8; };