all repos — mgba @ c8d348880497cbb357f66f9a3c1c3a4e2cdb41cb

mGBA Game Boy Advance Emulator

GBA: Split out autodetected version cheats from GameShark cheats
Jeffrey Pfau jeffrey@endrift.com
Sat, 14 Feb 2015 17:44:53 -0800
commit

c8d348880497cbb357f66f9a3c1c3a4e2cdb41cb

parent

0bd9ae087e149599e352bbee24c4de23e6247ec5

2 files changed, 37 insertions(+), 3 deletions(-)

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

@@ -579,6 +579,37 @@ uint32_t o1 = op1;

uint32_t o2 = op2; switch (set->gsaVersion) { case 0: + _setGameSharkVersion(set, 1); + // Fall through + case 1: + _decryptGameShark(&o1, &o2, set->gsaSeeds); + return _addGSA1(set, o1, o2); + } + return false; +} + +bool GBACheatAddGameSharkLine(struct GBACheatSet* cheats, const char* line) { + uint32_t op1; + uint32_t op2; + line = _hex32(line, &op1); + if (!line) { + return false; + } + while (*line == ' ') { + ++line; + } + line = _hex32(line, &op2); + if (!line) { + return false; + } + return GBACheatAddGameShark(cheats, op1, op2); +} + +bool GBACheatAddAutodetect(struct GBACheatSet* set, uint32_t op1, uint32_t op2) { + uint32_t o1 = op1; + uint32_t o2 = op2; + switch (set->gsaVersion) { + case 0: // Try to detect GameShark version _decryptGameShark(&o1, &o2, _gsa1S); if ((o1 & 0xF0000000) == 0xF0000000 && !(o2 & 0xFFFFFCFE)) {

@@ -603,7 +634,7 @@ }

return false; } -bool GBACheatAddGameSharkLine(struct GBACheatSet* cheats, const char* line) { +bool GBACheatAutodetectLine(struct GBACheatSet* cheats, const char* line) { uint32_t op1; uint32_t op2; line = _hex32(line, &op1);

@@ -617,7 +648,7 @@ line = _hex32(line, &op2);

if (!line) { return false; } - return GBACheatAddGameShark(cheats, op1, op2); + return GBACheatAddAutodetect(cheats, op1, op2); } bool GBACheatParseFile(struct GBACheatDevice* device, struct VFile* vf) {

@@ -707,7 +738,7 @@ }

uint32_t realOp2 = op2; realOp2 <<= 16; realOp2 |= op3; - return GBACheatAddGameShark(cheats, op1, realOp2); + return GBACheatAddAutodetect(cheats, op1, realOp2); } void GBACheatRefresh(struct GBACheatDevice* device, struct GBACheatSet* cheats) {
M src/gba/cheats.hsrc/gba/cheats.h

@@ -192,6 +192,9 @@

bool GBACheatAddGameShark(struct GBACheatSet*, uint32_t op1, uint32_t op2); bool GBACheatAddGameSharkLine(struct GBACheatSet*, const char* line); +bool GBACheatAddAutodetect(struct GBACheatSet*, uint32_t op1, uint32_t op2); +bool GBACheatAddAutodetectLine(struct GBACheatSet*, const char* line); + bool GBACheatParseFile(struct GBACheatDevice*, struct VFile*); bool GBACheatAddLine(struct GBACheatSet*, const char* line);