all repos — mgba @ a71007267d684ff85249be0b6947d6a3e7ce9678

mGBA Game Boy Advance Emulator

GB Cheats: Fix Game Genie codes that apply to ROM banks
Jeffrey Pfau jeffrey@endrift.com
Fri, 16 Sep 2016 19:47:43 -0700
commit

a71007267d684ff85249be0b6947d6a3e7ce9678

parent

50466642ad1c1a0d8724494d8db3bbc6613eb47e

2 files changed, 16 insertions(+), 5 deletions(-)

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

@@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "cheats.h" #include "core/core.h" +#include "gb/gb.h" #include "gb/memory.h" #include "util/string.h"

@@ -21,15 +22,24 @@ struct GBCheatPatch* patch = GBCheatPatchListGetPointer(&cheats->romPatches, i);

if (patch->applied) { continue; } + int segment = 0; if (patch->checkByte) { - // TODO: All segments - int8_t value = GBView8(device->p->cpu, patch->address, 0); - if (value != patch->oldValue) { + struct GB* gb = device->p->board; + int maxSegment = (gb->memory.romSize + GB_SIZE_CART_BANK0 - 1) / GB_SIZE_CART_BANK0; + for (; segment < maxSegment; ++segment) { + int8_t value = GBView8(device->p->cpu, patch->address, segment); + if (value == patch->oldValue) { + break; + } + } + if (segment == maxSegment) { continue; } } - GBPatch8(device->p->cpu, patch->address, patch->newValue, &patch->oldValue, 0); + // TODO: More than one segment + GBPatch8(device->p->cpu, patch->address, patch->newValue, &patch->oldValue, segment); patch->applied = true; + patch->segment = segment; } }

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

if (!patch->applied) { continue; } - GBPatch8(device->p->cpu, patch->address, patch->oldValue, &patch->newValue, 0); + GBPatch8(device->p->cpu, patch->address, patch->oldValue, &patch->newValue, patch->segment); patch->applied = false; } }
M src/gb/cheats.hsrc/gb/cheats.h

@@ -22,6 +22,7 @@ struct GBCheatPatch {

uint16_t address; int8_t newValue; int8_t oldValue; + int segment; bool applied; bool checkByte; };