GBA Cheats: Use an enum for GSA versions
Vicki Pfau vi@endrift.com
Fri, 29 Sep 2017 22:25:51 -0700
4 files changed,
33 insertions(+),
26 deletions(-)
M
src/gba/cheats.c
→
src/gba/cheats.c
@@ -150,26 +150,26 @@ o1 = op1;
o2 = op2; if (gsaP > maxProbability) { maxProbability = gsaP; - GBACheatSetGameSharkVersion(set, 1); + GBACheatSetGameSharkVersion(set, GBA_GS_GSAV1); } GBACheatDecryptGameShark(&o1, &o2, GBACheatProActionReplaySeeds); parP = GBACheatProActionReplayProbability(o1, o2); if (parP > maxProbability) { maxProbability = parP; - GBACheatSetGameSharkVersion(set, 3); + GBACheatSetGameSharkVersion(set, GBA_GS_PARV3); } rgsaP = GBACheatGameSharkProbability(op1, op1); if (rgsaP > maxProbability) { maxProbability = rgsaP; - GBACheatSetGameSharkVersion(set, 2); + GBACheatSetGameSharkVersion(set, GBA_GS_GSAV1_RAW); } rparP = GBACheatProActionReplayProbability(op1, op1); if (rparP > maxProbability) { maxProbability = rparP; - GBACheatSetGameSharkVersion(set, 4); + GBACheatSetGameSharkVersion(set, GBA_GS_PARV3_RAW); } if (set->gsaVersion < 3) {@@ -304,19 +304,19 @@ size_t d;
for (d = 0; d < StringListSize(directives); ++d) { const char* directive = *StringListGetConstPointer(directives, d); if (strcmp(directive, "GSAv1") == 0) { - GBACheatSetGameSharkVersion(cheats, 1); + GBACheatSetGameSharkVersion(cheats, GBA_GS_GSAV1); continue; } if (strcmp(directive, "GSAv1 raw") == 0) { - GBACheatSetGameSharkVersion(cheats, 2); + GBACheatSetGameSharkVersion(cheats, GBA_GS_GSAV1_RAW); continue; } if (strcmp(directive, "PARv3") == 0) { - GBACheatSetGameSharkVersion(cheats, 3); + GBACheatSetGameSharkVersion(cheats, GBA_GS_PARV3); continue; } if (strcmp(directive, "PARv3 raw") == 0) { - GBACheatSetGameSharkVersion(cheats, 4); + GBACheatSetGameSharkVersion(cheats, GBA_GS_PARV3_RAW); continue; } }
M
src/gba/cheats/gameshark.c
→
src/gba/cheats/gameshark.c
@@ -5,6 +5,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include <mgba/internal/gba/cheats.h> +#include "gba/cheats/gameshark.h" #include "gba/cheats/parv3.h" #include <mgba/internal/gba/gba.h> #include <mgba-util/string.h>@@ -73,16 +74,18 @@ }
} } -void GBACheatSetGameSharkVersion(struct GBACheatSet* cheats, int version) { +void GBACheatSetGameSharkVersion(struct GBACheatSet* cheats, enum GBACheatGameSharkVersion version) { cheats->gsaVersion = version; switch (version) { - case 1: - case 2: + case GBA_GS_GSAV1: + case GBA_GS_GSAV1_RAW: memcpy(cheats->gsaSeeds, GBACheatGameSharkSeeds, 4 * sizeof(uint32_t)); break; - case 3: - case 4: + case GBA_GS_PARV3: + case GBA_GS_PARV3_RAW: memcpy(cheats->gsaSeeds, GBACheatProActionReplaySeeds, 4 * sizeof(uint32_t)); + break; + default: break; } }@@ -197,15 +200,13 @@ char line[18] = "XXXXXXXX XXXXXXXX";
snprintf(line, sizeof(line), "%08X %08X", op1, op2); switch (set->gsaVersion) { - case 0: - case 3: - case 4: - GBACheatSetGameSharkVersion(set, 1); + default: + GBACheatSetGameSharkVersion(set, GBA_GS_GSAV1); // Fall through - case 1: + case GBA_GS_GSAV1: GBACheatDecryptGameShark(&o1, &o2, set->gsaSeeds); // Fall through - case 2: + case GBA_GS_GSAV1_RAW: return GBACheatAddGameSharkRaw(set, o1, o2); } return false;
M
src/gba/cheats/gameshark.h
→
src/gba/cheats/gameshark.h
@@ -12,10 +12,18 @@ CXX_GUARD_START
extern const uint32_t GBACheatGameSharkSeeds[4]; +enum GBACheatGameSharkVersion { + GBA_GS_NOT_SET = 0, + GBA_GS_GSAV1 = 1, + GBA_GS_GSAV1_RAW = 2, + GBA_GS_PARV3 = 3, + GBA_GS_PARV3_RAW = 4 +}; + struct GBACheatSet; void GBACheatDecryptGameShark(uint32_t* op1, uint32_t* op2, const uint32_t* seeds); void GBACheatReseedGameShark(uint32_t* seeds, uint16_t params, const uint8_t* t1, const uint8_t* t2); -void GBACheatSetGameSharkVersion(struct GBACheatSet* cheats, int version); +void GBACheatSetGameSharkVersion(struct GBACheatSet* cheats, enum GBACheatGameSharkVersion version); bool GBACheatAddGameSharkRaw(struct GBACheatSet* cheats, uint32_t op1, uint32_t op2); int GBACheatGameSharkProbability(uint32_t op1, uint32_t op2);
M
src/gba/cheats/parv3.c
→
src/gba/cheats/parv3.c
@@ -301,15 +301,13 @@ char line[18] = "XXXXXXXX XXXXXXXX";
snprintf(line, sizeof(line), "%08X %08X", op1, op2); switch (set->gsaVersion) { - case 0: - case 1: - case 2: - GBACheatSetGameSharkVersion(set, 3); + default: + GBACheatSetGameSharkVersion(set, GBA_GS_PARV3); // Fall through - case 3: + case GBA_GS_PARV3: GBACheatDecryptGameShark(&o1, &o2, set->gsaSeeds); // Fall through - case 4: + case GBA_GS_PARV3_RAW: return GBACheatAddProActionReplayRaw(set, o1, o2); } return false;