Cheats: Support double conditional D0/D1/D2/D3/E0/E1/E2/E3/D4

This commit is contained in:
Connor McLaughlin 2020-12-09 20:22:43 +10:00
parent 770dd5a600
commit 59c338f461
2 changed files with 46 additions and 9 deletions

View file

@ -816,6 +816,41 @@ bool CheatCode::SetInstructionsFromString(const std::string& str)
return true; return true;
} }
static bool IsConditionalInstruction(CheatCode::InstructionCode code)
{
switch (code)
{
case CheatCode::InstructionCode::CompareEqual16: // D0
case CheatCode::InstructionCode::CompareNotEqual16: // D1
case CheatCode::InstructionCode::CompareLess16: // D2
case CheatCode::InstructionCode::CompareGreater16: // D3
case CheatCode::InstructionCode::CompareEqual8: // E0
case CheatCode::InstructionCode::CompareNotEqual8: // E1
case CheatCode::InstructionCode::CompareLess8: // E2
case CheatCode::InstructionCode::CompareGreater8: // E3
case CheatCode::InstructionCode::CompareButtons: // D4
return true;
default:
return false;
}
}
u32 CheatCode::GetNextNonConditionalInstruction(u32 index) const
{
const u32 count = static_cast<u32>(instructions.size());
for (; index < count; index++)
{
if (!IsConditionalInstruction(instructions[index].code))
{
// we've found the first non conditional instruction in the chain, so skip over the instruction following it
return index + 1;
}
}
return index;
}
void CheatCode::Apply() const void CheatCode::Apply() const
{ {
const u32 count = static_cast<u32>(instructions.size()); const u32 count = static_cast<u32>(instructions.size());
@ -890,7 +925,7 @@ void CheatCode::Apply() const
if (value == inst.value16) if (value == inst.value16)
index++; index++;
else else
index += 2; index = GetNextNonConditionalInstruction(index);
} }
break; break;
@ -900,7 +935,7 @@ void CheatCode::Apply() const
if (value != inst.value16) if (value != inst.value16)
index++; index++;
else else
index += 2; index = GetNextNonConditionalInstruction(index);
} }
break; break;
@ -910,7 +945,7 @@ void CheatCode::Apply() const
if (value < inst.value16) if (value < inst.value16)
index++; index++;
else else
index += 2; index = GetNextNonConditionalInstruction(index);
} }
break; break;
@ -920,7 +955,7 @@ void CheatCode::Apply() const
if (value > inst.value16) if (value > inst.value16)
index++; index++;
else else
index += 2; index = GetNextNonConditionalInstruction(index);
} }
break; break;
@ -930,7 +965,7 @@ void CheatCode::Apply() const
if (value == inst.value8) if (value == inst.value8)
index++; index++;
else else
index += 2; index = GetNextNonConditionalInstruction(index);
} }
break; break;
@ -940,7 +975,7 @@ void CheatCode::Apply() const
if (value != inst.value8) if (value != inst.value8)
index++; index++;
else else
index += 2; index = GetNextNonConditionalInstruction(index);
} }
break; break;
@ -950,7 +985,7 @@ void CheatCode::Apply() const
if (value < inst.value8) if (value < inst.value8)
index++; index++;
else else
index += 2; index = GetNextNonConditionalInstruction(index);
} }
break; break;
@ -960,7 +995,7 @@ void CheatCode::Apply() const
if (value > inst.value8) if (value > inst.value8)
index++; index++;
else else
index += 2; index = GetNextNonConditionalInstruction(index);
} }
break; break;
@ -969,7 +1004,7 @@ void CheatCode::Apply() const
if (inst.value16 == GetControllerButtonBits()) if (inst.value16 == GetControllerButtonBits())
index++; index++;
else else
index += 2; index = GetNextNonConditionalInstruction(index);
} }
break; break;

View file

@ -77,6 +77,8 @@ struct CheatCode
std::string GetInstructionsAsString() const; std::string GetInstructionsAsString() const;
bool SetInstructionsFromString(const std::string& str); bool SetInstructionsFromString(const std::string& str);
u32 GetNextNonConditionalInstruction(u32 index) const;
void Apply() const; void Apply() const;
static const char* GetTypeName(Type type); static const char* GetTypeName(Type type);