Cheats: Add extension 32-bit instructions variants

This commit is contained in:
Connor McLaughlin 2020-12-17 23:33:00 +10:00
parent 412b5073db
commit d2c98639a8
2 changed files with 87 additions and 1 deletions

View File

@ -880,6 +880,13 @@ void CheatCode::Apply() const
} }
break; break;
case InstructionCode::ExtConstantWrite32:
{
DoMemoryWrite<u32>(inst.address, inst.value32);
index++;
}
break;
case InstructionCode::ScratchpadWrite16: case InstructionCode::ScratchpadWrite16:
{ {
DoMemoryWrite<u16>(CPU::DCACHE_LOCATION | (inst.address & CPU::DCACHE_OFFSET_MASK), inst.value16); DoMemoryWrite<u16>(CPU::DCACHE_LOCATION | (inst.address & CPU::DCACHE_OFFSET_MASK), inst.value16);
@ -887,6 +894,29 @@ void CheatCode::Apply() const
} }
break; break;
case InstructionCode::ExtScratchpadWrite32:
{
DoMemoryWrite<u32>(CPU::DCACHE_LOCATION | (inst.address & CPU::DCACHE_OFFSET_MASK), inst.value32);
index++;
}
break;
case InstructionCode::ExtIncrement32:
{
const u32 value = DoMemoryRead<u32>(inst.address);
DoMemoryWrite<u32>(inst.address, value + inst.value32);
index++;
}
break;
case InstructionCode::ExtDecrement32:
{
const u32 value = DoMemoryRead<u32>(inst.address);
DoMemoryWrite<u32>(inst.address, value - inst.value32);
index++;
}
break;
case InstructionCode::Increment16: case InstructionCode::Increment16:
{ {
const u16 value = DoMemoryRead<u16>(inst.address); const u16 value = DoMemoryRead<u16>(inst.address);
@ -919,6 +949,46 @@ void CheatCode::Apply() const
} }
break; break;
case InstructionCode::ExtCompareEqual32:
{
const u32 value = DoMemoryRead<u32>(inst.address);
if (value == inst.value32)
index++;
else
index = GetNextNonConditionalInstruction(index);
}
break;
case InstructionCode::ExtCompareNotEqual32:
{
const u32 value = DoMemoryRead<u32>(inst.address);
if (value != inst.value32)
index++;
else
index = GetNextNonConditionalInstruction(index);
}
break;
case InstructionCode::ExtCompareLess32:
{
const u32 value = DoMemoryRead<u32>(inst.address);
if (value < inst.value32)
index++;
else
index = GetNextNonConditionalInstruction(index);
}
break;
case InstructionCode::ExtCompareGreater32:
{
const u32 value = DoMemoryRead<u32>(inst.address);
if (value > inst.value32)
index++;
else
index = GetNextNonConditionalInstruction(index);
}
break;
case InstructionCode::CompareEqual16: case InstructionCode::CompareEqual16:
{ {
const u16 value = DoMemoryRead<u16>(inst.address); const u16 value = DoMemoryRead<u16>(inst.address);
@ -1009,6 +1079,7 @@ void CheatCode::Apply() const
break; break;
case InstructionCode::SkipIfNotEqual16: // C0 case InstructionCode::SkipIfNotEqual16: // C0
case InstructionCode::ExtSkipIfNotEqual32: // A4
case InstructionCode::SkipIfButtonsNotEqual: // D5 case InstructionCode::SkipIfButtonsNotEqual: // D5
case InstructionCode::SkipIfButtonsEqual: // D6 case InstructionCode::SkipIfButtonsEqual: // D6
{ {
@ -1020,6 +1091,9 @@ void CheatCode::Apply() const
case InstructionCode::SkipIfNotEqual16: // C0 case InstructionCode::SkipIfNotEqual16: // C0
activate_codes = (DoMemoryRead<u16>(inst.address) == inst.value16); activate_codes = (DoMemoryRead<u16>(inst.address) == inst.value16);
break; break;
case InstructionCode::ExtSkipIfNotEqual32: // A4
activate_codes = (DoMemoryRead<u32>(inst.address) == inst.value32);
break;
case InstructionCode::SkipIfButtonsNotEqual: // D5 case InstructionCode::SkipIfButtonsNotEqual: // D5
activate_codes = (GetControllerButtonBits() == inst.value16); activate_codes = (GetControllerButtonBits() == inst.value16);
break; break;

View File

@ -44,7 +44,18 @@ struct CheatCode
CompareLess8 = 0xE2, CompareLess8 = 0xE2,
CompareGreater8 = 0xE3, CompareGreater8 = 0xE3,
Slide = 0x50, 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 union Instruction
@ -59,6 +70,7 @@ struct CheatCode
BitField<u64, InstructionCode, 32 + 24, 8> code; BitField<u64, InstructionCode, 32 + 24, 8> code;
BitField<u64, u32, 32, 24> address; BitField<u64, u32, 32, 24> address;
BitField<u64, u32, 0, 32> value32;
BitField<u64, u16, 0, 16> value16; BitField<u64, u16, 0, 16> value16;
BitField<u64, u8, 0, 8> value8; BitField<u64, u8, 0, 8> value8;
}; };