all repos — mgba @ 6519c4e465f42d58c297fc92e497766bfbbd5e0a

mGBA Game Boy Advance Emulator

GB Cheats: Add check byte to GameGenie codes
Jeffrey Pfau jeffrey@endrift.com
Thu, 01 Sep 2016 02:34:04 -0700
commit

6519c4e465f42d58c297fc92e497766bfbbd5e0a

parent

d05f513a17098d4128caa6581aff9af49aaf0d05

2 files changed, 27 insertions(+), 2 deletions(-)

jump to
M src/gb/cheats.csrc/gb/cheats.c

@@ -21,7 +21,13 @@ struct GBCheatPatch* patch = GBCheatPatchListGetPointer(&cheats->romPatches, i);

if (patch->applied) { continue; } - // TODO: Byte check + if (patch->checkByte) { + // TODO: All segments + int8_t value = GBView8(device->p->cpu, patch->address, 0); + if (value != patch->oldValue) { + continue; + } + } GBPatch8(device->p->cpu, patch->address, patch->newValue, &patch->oldValue); patch->applied = true; }

@@ -37,7 +43,7 @@ struct GBCheatPatch* patch = GBCheatPatchListGetPointer(&cheats->romPatches, i);

if (!patch->applied) { continue; } - GBPatch8(device->p->cpu, patch->address, patch->oldValue, NULL); + GBPatch8(device->p->cpu, patch->address, patch->oldValue, &patch->newValue); patch->applied = false; } }

@@ -120,6 +126,7 @@

static bool GBCheatAddGameGenieLine(struct GBCheatSet* cheats, const char* line) { uint16_t op1; uint16_t op2; + uint16_t op3 = 0x1000; const char* lineNext = hex12(line, &op1); if (!lineNext || lineNext[0] != '-') { return false;

@@ -129,6 +136,13 @@ lineNext = hex12(lineNext, &op2);

if (!lineNext) { return false; } + if (lineNext[0] == '-') { + ++lineNext; + lineNext = hex12(lineNext, &op3); + } + if (!lineNext || lineNext[0]) { + return false; + } uint16_t address = (op1 & 0xF) << 8; address |= (op2 >> 4) & 0xFF; address |= ((op2 & 0xF) ^ 0xF) << 12;

@@ -136,6 +150,16 @@ struct GBCheatPatch* patch = GBCheatPatchListAppend(&cheats->romPatches);

patch->address = address; patch->newValue = op1 >> 4; patch->applied = false; + if (op3 < 0x1000) { + uint32_t value = ((op3 & 0xF00) << 20) | (op3 & 0xF); + value = ROR(value, 2); + value |= value >> 24; + value ^= 0xBA; + patch->oldValue = value; + patch->checkByte = true; + } else { + patch->checkByte = false; + } return true; }
M src/gb/cheats.hsrc/gb/cheats.h

@@ -23,6 +23,7 @@ uint16_t address;

int8_t newValue; int8_t oldValue; bool applied; + bool checkByte; }; DECLARE_VECTOR(GBCheatPatchList, struct GBCheatPatch);