Libretro: Fix cheat loading

This commit is contained in:
Jeffrey Pfau 2015-11-16 01:02:12 -08:00
parent 99b68509da
commit 87aaefccd2
2 changed files with 20 additions and 3 deletions

View File

@ -33,7 +33,7 @@ bool GBAContextInit(struct GBAContext* context, const char* port) {
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);

View File

@ -195,9 +195,9 @@ void retro_init(void) {
#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_reset(void) {
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) {