Cheats: Support chaining C0 codes with separator (00000000 FFFF)

This commit is contained in:
Connor McLaughlin 2020-12-05 02:00:37 +10:00
parent af6b0dc189
commit 5575950822
2 changed files with 31 additions and 18 deletions

View file

@ -811,7 +811,7 @@ void CheatCode::Apply() const
case InstructionCode::Increment16: case InstructionCode::Increment16:
{ {
u16 value = DoMemoryRead<u16>(inst.address); const u16 value = DoMemoryRead<u16>(inst.address);
DoMemoryWrite<u16>(inst.address, value + inst.value16); DoMemoryWrite<u16>(inst.address, value + inst.value16);
index++; index++;
} }
@ -819,7 +819,7 @@ void CheatCode::Apply() const
case InstructionCode::Decrement16: case InstructionCode::Decrement16:
{ {
u16 value = DoMemoryRead<u16>(inst.address); const u16 value = DoMemoryRead<u16>(inst.address);
DoMemoryWrite<u16>(inst.address, value - inst.value16); DoMemoryWrite<u16>(inst.address, value - inst.value16);
index++; index++;
} }
@ -827,7 +827,7 @@ void CheatCode::Apply() const
case InstructionCode::Increment8: case InstructionCode::Increment8:
{ {
u8 value = DoMemoryRead<u8>(inst.address); const u8 value = DoMemoryRead<u8>(inst.address);
DoMemoryWrite<u8>(inst.address, value + inst.value8); DoMemoryWrite<u8>(inst.address, value + inst.value8);
index++; index++;
} }
@ -835,7 +835,7 @@ void CheatCode::Apply() const
case InstructionCode::Decrement8: case InstructionCode::Decrement8:
{ {
u8 value = DoMemoryRead<u8>(inst.address); const u8 value = DoMemoryRead<u8>(inst.address);
DoMemoryWrite<u8>(inst.address, value - inst.value8); DoMemoryWrite<u8>(inst.address, value - inst.value8);
index++; index++;
} }
@ -843,7 +843,7 @@ void CheatCode::Apply() const
case InstructionCode::CompareEqual16: case InstructionCode::CompareEqual16:
{ {
u16 value = DoMemoryRead<u16>(inst.address); const u16 value = DoMemoryRead<u16>(inst.address);
if (value == inst.value16) if (value == inst.value16)
index++; index++;
else else
@ -853,7 +853,7 @@ void CheatCode::Apply() const
case InstructionCode::CompareNotEqual16: case InstructionCode::CompareNotEqual16:
{ {
u16 value = DoMemoryRead<u16>(inst.address); const u16 value = DoMemoryRead<u16>(inst.address);
if (value != inst.value16) if (value != inst.value16)
index++; index++;
else else
@ -863,7 +863,7 @@ void CheatCode::Apply() const
case InstructionCode::CompareLess16: case InstructionCode::CompareLess16:
{ {
u16 value = DoMemoryRead<u16>(inst.address); const u16 value = DoMemoryRead<u16>(inst.address);
if (value < inst.value16) if (value < inst.value16)
index++; index++;
else else
@ -873,7 +873,7 @@ void CheatCode::Apply() const
case InstructionCode::CompareGreater16: case InstructionCode::CompareGreater16:
{ {
u16 value = DoMemoryRead<u16>(inst.address); const u16 value = DoMemoryRead<u16>(inst.address);
if (value > inst.value16) if (value > inst.value16)
index++; index++;
else else
@ -883,7 +883,7 @@ void CheatCode::Apply() const
case InstructionCode::CompareEqual8: case InstructionCode::CompareEqual8:
{ {
u8 value = DoMemoryRead<u8>(inst.address); const u8 value = DoMemoryRead<u8>(inst.address);
if (value == inst.value8) if (value == inst.value8)
index++; index++;
else else
@ -893,7 +893,7 @@ void CheatCode::Apply() const
case InstructionCode::CompareNotEqual8: case InstructionCode::CompareNotEqual8:
{ {
u8 value = DoMemoryRead<u8>(inst.address); const u8 value = DoMemoryRead<u8>(inst.address);
if (value != inst.value8) if (value != inst.value8)
index++; index++;
else else
@ -903,7 +903,7 @@ void CheatCode::Apply() const
case InstructionCode::CompareLess8: case InstructionCode::CompareLess8:
{ {
u8 value = DoMemoryRead<u8>(inst.address); const u8 value = DoMemoryRead<u8>(inst.address);
if (value < inst.value8) if (value < inst.value8)
index++; index++;
else else
@ -913,7 +913,7 @@ void CheatCode::Apply() const
case InstructionCode::CompareGreater8: case InstructionCode::CompareGreater8:
{ {
u8 value = DoMemoryRead<u8>(inst.address); const u8 value = DoMemoryRead<u8>(inst.address);
if (value > inst.value8) if (value > inst.value8)
index++; index++;
else else
@ -921,13 +921,26 @@ void CheatCode::Apply() const
} }
break; break;
case InstructionCode::ExitIfNotEqual16: case InstructionCode::SkipIfNotEqual16: // C0
{ {
u16 value = DoMemoryRead<u16>(inst.address); const u16 value = DoMemoryRead<u16>(inst.address);
index++;
if (value == inst.value16) if (value == inst.value16)
index++; {
else // execute following instructions
index = count; continue;
}
// skip to the next separator (00000000 FFFF), or end
constexpr u64 separator_value = UINT64_C(0x000000000000FFFF);
while (index < count)
{
// we don't want to execute the separator instruction
const u64 bits = instructions[index++].bits;
if (bits == separator_value)
break;
}
} }
break; break;

View file

@ -30,7 +30,7 @@ struct CheatCode
Decrement16 = 0x11, Decrement16 = 0x11,
Increment8 = 0x20, Increment8 = 0x20,
Decrement8 = 0x21, Decrement8 = 0x21,
ExitIfNotEqual16 = 0xC0, SkipIfNotEqual16 = 0xC0,
CompareEqual16 = 0xD0, CompareEqual16 = 0xD0,
CompareNotEqual16 = 0xD1, CompareNotEqual16 = 0xD1,
CompareLess16 = 0xD2, CompareLess16 = 0xD2,