mirror of https://github.com/mgba-emu/mgba.git
Libretro: Fix cheat loading
This commit is contained in:
parent
99b68509da
commit
87aaefccd2
|
@ -33,7 +33,7 @@ bool GBAContextInit(struct GBAContext* context, const char* port) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
GBACreate(context->gba);
|
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);
|
ARMInit(context->cpu);
|
||||||
|
|
||||||
GBAConfigInit(&context->config, port);
|
GBAConfigInit(&context->config, port);
|
||||||
|
|
|
@ -195,9 +195,9 @@ void retro_init(void) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
GBACheatDeviceCreate(&cheats);
|
GBACheatDeviceCreate(&cheats);
|
||||||
|
GBACheatAttachDevice(context.gba, &cheats);
|
||||||
GBACheatSetInit(&cheatSet, "libretro");
|
GBACheatSetInit(&cheatSet, "libretro");
|
||||||
GBACheatAddSet(&cheats, &cheatSet);
|
GBACheatAddSet(&cheats, &cheatSet);
|
||||||
GBACheatAttachDevice(context.gba, &cheats);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void retro_deinit(void) {
|
void retro_deinit(void) {
|
||||||
|
@ -321,7 +321,24 @@ void retro_cheat_reset(void) {
|
||||||
void retro_cheat_set(unsigned index, bool enabled, const char* code) {
|
void retro_cheat_set(unsigned index, bool enabled, const char* code) {
|
||||||
UNUSED(index);
|
UNUSED(index);
|
||||||
UNUSED(enabled);
|
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) {
|
unsigned retro_get_region(void) {
|
||||||
|
|
Loading…
Reference in New Issue