all repos — mgba @ 87aaefccd2ebed4bffb0cedc5c316696760480e5

mGBA Game Boy Advance Emulator

Libretro: Fix cheat loading
Jeffrey Pfau jeffrey@endrift.com
Mon, 16 Nov 2015 01:02:12 -0800
commit

87aaefccd2ebed4bffb0cedc5c316696760480e5

parent

99b68509da043383177aa17a28d9dc342c0107fa

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

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

@@ -33,7 +33,7 @@ }

return false; } GBACreate(context->gba); - ARMSetComponents(context->cpu, &context->gba->d, 0, context->components); + ARMSetComponents(context->cpu, &context->gba->d, GBA_COMPONENT_MAX, context->components); ARMInit(context->cpu); GBAConfigInit(&context->config, port);
M src/platform/libretro/libretro.csrc/platform/libretro/libretro.c

@@ -195,9 +195,9 @@ blip_set_rates(context.gba->audio.right, GBA_ARM7TDMI_FREQUENCY, 32768);

#endif GBACheatDeviceCreate(&cheats); + GBACheatAttachDevice(context.gba, &cheats); GBACheatSetInit(&cheatSet, "libretro"); GBACheatAddSet(&cheats, &cheatSet); - GBACheatAttachDevice(context.gba, &cheats); } void retro_deinit(void) {

@@ -321,7 +321,24 @@

void retro_cheat_set(unsigned index, bool enabled, const char* code) { UNUSED(index); UNUSED(enabled); - GBACheatAddLine(&cheatSet, code); + // Convert the super wonky unportable libretro format to something normal + char realCode[] = "XXXXXXXX XXXXXXXX"; + size_t len = strlen(code) + 1; // Include null terminator + size_t i, pos; + for (i = 0, pos = 0; i < len; ++i) { + if (isspace((int) code[i]) || code[i] == '+') { + realCode[pos] = ' '; + } else { + realCode[pos] = code[i]; + } + if ((pos == 13 && (realCode[pos] == ' ' || !realCode[pos])) || pos == 17) { + realCode[pos] = '\0'; + GBACheatAddLine(&cheatSet, realCode); + pos = 0; + continue; + } + ++pos; + } } unsigned retro_get_region(void) {