GBA: Change how GameShark ROM patches work
Jeffrey Pfau jeffrey@endrift.com
Sun, 08 Feb 2015 21:03:05 -0800
2 files changed,
13 insertions(+),
12 deletions(-)
M
src/gba/cheats.c
→
src/gba/cheats.c
@@ -227,13 +227,10 @@ cheat->address = op2;
cheats->incompleteCheat = cheat; break; case GSA_PATCH: - if (cheats->nRomPatches >= MAX_ROM_PATCHES) { - return false; - } - cheats->romPatches[cheats->nRomPatches].address = (op1 & 0xFFFFFF) << 1; - cheats->romPatches[cheats->nRomPatches].newValue = op2; - cheats->romPatches[cheats->nRomPatches].applied = false; - ++cheats->nRomPatches; + cheats->romPatches[0].address = (op1 & 0xFFFFFF) << 1; + cheats->romPatches[0].newValue = op2; + cheats->romPatches[0].applied = false; + cheats->romPatches[0].exists = true; return true; case GSA_BUTTON: // TODO: Implement button@@ -298,8 +295,8 @@ if (!device->cheats || !device->p) {
return; } int i; - for (i = 0; i < device->cheats->nRomPatches; ++i) { - if (device->cheats->romPatches[i].applied) { + for (i = 0; i < MAX_ROM_PATCHES; ++i) { + if (!device->cheats->romPatches[i].exists || device->cheats->romPatches[i].applied) { continue; } GBAPatch16(device->p->cpu, device->cheats->romPatches[i].address, device->cheats->romPatches[i].newValue, &device->cheats->romPatches[i].oldValue);@@ -312,8 +309,8 @@ if (!device->cheats || !device->p) {
return; } int i; - for (i = 0; i < device->cheats->nRomPatches; ++i) { - if (!device->cheats->romPatches[i].applied) { + for (i = 0; i < MAX_ROM_PATCHES; ++i) { + if (!device->cheats->romPatches[i].exists || !device->cheats->romPatches[i].applied) { continue; } GBAPatch16(device->p->cpu, device->cheats->romPatches[i].address, device->cheats->romPatches[i].oldValue, 0);@@ -338,6 +335,10 @@ set->incompleteCheat = 0;
set->patchedOpcode = 0; set->gsaVersion = 0; set->remainingAddresses = 0; + int i; + for (i = 0; i < MAX_ROM_PATCHES; ++i) { + set->romPatches[i].exists = false; + } } void GBACheatSetDeinit(struct GBACheatSet* set) {
M
src/gba/cheats.h
→
src/gba/cheats.h
@@ -82,8 +82,8 @@ uint32_t address;
int16_t newValue; int16_t oldValue; bool applied; + bool exists; } romPatches[MAX_ROM_PATCHES]; - int nRomPatches; int gsaVersion; uint32_t gsaSeeds[4];