all repos — mgba @ 76366ae70ac057d255a8470b46d436a421df3187

mGBA Game Boy Advance Emulator

Libretro: Add Game Boy cheat support
Vicki Pfau vi@endrift.com
Tue, 25 Sep 2018 15:15:22 -0700
commit

76366ae70ac057d255a8470b46d436a421df3187

parent

ec4e2e80d9b485fa98972f0e13affc986ec0f1de

2 files changed, 42 insertions(+), 15 deletions(-)

jump to
M CHANGESCHANGES

@@ -99,6 +99,8 @@ - Core: Remove broken option for whether rewinding restores save games

- FFmpeg: Support lossless VP9 encoding - mGUI: Add fast forward toggle Changes from beta 1: +Features: + - Libretro: Add Game Boy cheat support Bugfixes: - PSP2: Fix audio crackling after fast forward - PSP2: Fix audio crackling when buffer is full
M src/platform/libretro/libretro.csrc/platform/libretro/libretro.c

@@ -605,24 +605,49 @@ } else {

cheatSet = device->createSet(device, NULL); mCheatAddSet(device, cheatSet); } - // 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]; +// Convert the super wonky unportable libretro format to something normal +#ifdef M_CORE_GBA + if (core->platform(core) == PLATFORM_GBA) { + 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'; + mCheatAddLine(cheatSet, realCode, 0); + pos = 0; + continue; + } + ++pos; } - if ((pos == 13 && (realCode[pos] == ' ' || !realCode[pos])) || pos == 17) { - realCode[pos] = '\0'; - mCheatAddLine(cheatSet, realCode, 0); - pos = 0; - continue; + } +#endif +#ifdef M_CORE_GB + if (core->platform(core) == PLATFORM_GB) { + char realCode[] = "XXX-XXX-XXX"; + 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] = '\0'; + } else { + realCode[pos] = code[i]; + } + if (pos == 11 || !realCode[pos]) { + realCode[pos] = '\0'; + mCheatAddLine(cheatSet, realCode, 0); + pos = 0; + continue; + } + ++pos; } - ++pos; } +#endif } unsigned retro_get_region(void) {