diff --git a/src/platform/libretro/libretro.c b/src/platform/libretro/libretro.c index 6b07a698d..1b5ef453d 100644 --- a/src/platform/libretro/libretro.c +++ b/src/platform/libretro/libretro.c @@ -51,8 +51,6 @@ static struct CircleBuffer rumbleHistory; static struct mRumble rumble; static struct GBALuminanceSource lux; static int luxLevel; -static struct GBACheatDevice cheats; -static struct GBACheatSet cheatSet; static struct mLogger logger; static void _reloadSettings(void) { @@ -213,9 +211,6 @@ void retro_init(void) { } void retro_deinit(void) { - GBACheatRemoveSet(&cheats, &cheatSet); - GBACheatDeviceDestroy(&cheats); - GBACheatSetDeinit(&cheatSet); free(outputBuffer); } @@ -341,11 +336,6 @@ bool retro_load_game(const struct retro_game_info* game) { core->loadBIOS(core, bios, 0); } } - - GBACheatDeviceCreate(&cheats); - GBACheatAttachDevice(gba, &cheats); - GBACheatSetInit(&cheatSet, "libretro"); - GBACheatAddSet(&cheats, &cheatSet); } #endif @@ -389,13 +379,20 @@ bool retro_unserialize(const void* data, size_t size) { } void retro_cheat_reset(void) { - GBACheatSetDeinit(&cheatSet); - GBACheatSetInit(&cheatSet, "libretro"); + mCheatDeviceClear(core->cheatDevice(core)); } void retro_cheat_set(unsigned index, bool enabled, const char* code) { UNUSED(index); UNUSED(enabled); + struct mCheatDevice* device = core->cheatDevice(core); + struct mCheatSet* cheatSet = NULL; + if (mCheatSetsSize(&device->cheats)) { + cheatSet = *mCheatSetsGetPointer(&device->cheats, 0); + } 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 @@ -408,7 +405,7 @@ void retro_cheat_set(unsigned index, bool enabled, const char* code) { } if ((pos == 13 && (realCode[pos] == ' ' || !realCode[pos])) || pos == 17) { realCode[pos] = '\0'; - GBACheatAddLine(&cheatSet, realCode); + mCheatAddLine(cheatSet, realCode, 0); pos = 0; continue; } diff --git a/src/platform/openemu/mGBAGameCore.m b/src/platform/openemu/mGBAGameCore.m index 4eaa46890..9a2b0bb35 100644 --- a/src/platform/openemu/mGBAGameCore.m +++ b/src/platform/openemu/mGBAGameCore.m @@ -27,11 +27,8 @@ #include "util/common.h" #include "core/core.h" -#include "gba/audio.h" #include "gba/cheats.h" #include "gba/core.h" -#include "gba/cheats/gameshark.h" -#include "gba/gba.h" #include "gba/input.h" #include "gba/serialize.h" #include "util/circle-buffer.h" @@ -47,8 +44,6 @@ @interface mGBAGameCore () { struct mCore* core; - struct GBA* gba; - struct GBACheatDevice cheats; void* outputBuffer; NSMutableDictionary *cheatSets; } @@ -75,9 +70,6 @@ core->setVideoBuffer(core, outputBuffer, width); core->setAudioBufferSize(core, SAMPLES); - gba = core->board; - GBACheatDeviceCreate(&cheats); - GBACheatAttachDevice(gba, &cheats); cheatSets = [[NSMutableDictionary alloc] init]; } @@ -87,17 +79,6 @@ - (void)dealloc { core->deinit(core); - [cheatSets enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { - UNUSED(key); - UNUSED(stop); - GBACheatRemoveSet(&cheats, [obj pointerValue]); - }]; - GBACheatDeviceDestroy(&cheats); - [cheatSets enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { - UNUSED(key); - UNUSED(stop); - GBACheatSetDeinit([obj pointerValue]); - }]; [cheatSets release]; free(outputBuffer); @@ -288,25 +269,26 @@ const int GBAMap[] = { code = [code stringByReplacingOccurrencesOfString:@" " withString:@""]; NSString *codeId = [code stringByAppendingFormat:@"/%@", type]; - struct GBACheatSet* cheatSet = [[cheatSets objectForKey:codeId] pointerValue]; + struct mCheatSet* cheatSet = [[cheatSets objectForKey:codeId] pointerValue]; if (cheatSet) { cheatSet->enabled = enabled; return; } - cheatSet = malloc(sizeof(*cheatSet)); - GBACheatSetInit(cheatSet, [codeId UTF8String]); + struct mCheatDevice* cheats = core->cheatDevice(core); + cheatSet = cheats->createSet(cheats, [codeId UTF8String]); + int codeType = GBA_CHEAT_AUTODETECT; if ([type isEqual:@"GameShark"]) { - GBACheatSetGameSharkVersion(cheatSet, 1); + codeType = GBA_CHEAT_GAMESHARK; } else if ([type isEqual:@"Action Replay"]) { - GBACheatSetGameSharkVersion(cheatSet, 3); + codeType = GBA_CHEAT_PRO_ACTION_REPLAY; } NSArray *codeSet = [code componentsSeparatedByString:@"+"]; for (id c in codeSet) { - GBACheatAddLine(cheatSet, [c UTF8String]); + mCheatAddLine(cheatSet, [c UTF8String], codeType); } cheatSet->enabled = enabled; [cheatSets setObject:[NSValue valueWithPointer:cheatSet] forKey:codeId]; - GBACheatAddSet(&cheats, cheatSet); + mCheatAddSet(cheats, cheatSet); } @end