From 891a607507b3093985e1db427514820cbf926d2c Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Mon, 19 Sep 2016 07:26:06 -0700 Subject: [PATCH] GB, GBA: Unload cheats when unloading ROM --- src/gb/core.c | 12 +++++++++++- src/gba/core.c | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/gb/core.c b/src/gb/core.c index 99334fa7c..f4000a867 100644 --- a/src/gb/core.c +++ b/src/gb/core.c @@ -194,6 +194,14 @@ static bool _GBCoreLoadPatch(struct mCore* core, struct VFile* vf) { } static void _GBCoreUnloadROM(struct mCore* core) { + struct GBCore* gbcore = (struct GBCore*) core; + struct LR35902Core* cpu = core->cpu; + if (gbcore->cheatDevice) { + LR35902HotplugDetach(cpu, CPU_COMPONENT_CHEAT_DEVICE); + cpu->components[CPU_COMPONENT_CHEAT_DEVICE] = NULL; + mCheatDeviceDestroy(gbcore->cheatDevice); + gbcore->cheatDevice = NULL; + } return GBUnloadROM(core->board); } @@ -455,7 +463,9 @@ static void _GBCoreAttachDebugger(struct mCore* core, struct mDebugger* debugger static void _GBCoreDetachDebugger(struct mCore* core) { struct LR35902Core* cpu = core->cpu; - LR35902HotplugDetach(cpu, CPU_COMPONENT_DEBUGGER); + if (core->debugger) { + LR35902HotplugDetach(cpu, CPU_COMPONENT_DEBUGGER); + } cpu->components[CPU_COMPONENT_DEBUGGER] = NULL; core->debugger = NULL; } diff --git a/src/gba/core.c b/src/gba/core.c index 6f03440de..5b31030a5 100644 --- a/src/gba/core.c +++ b/src/gba/core.c @@ -228,6 +228,14 @@ static bool _GBACoreLoadPatch(struct mCore* core, struct VFile* vf) { } static void _GBACoreUnloadROM(struct mCore* core) { + struct GBACore* gbacore = (struct GBACore*) core; + struct ARMCore* cpu = core->cpu; + if (gbacore->cheatDevice) { + ARMHotplugDetach(cpu, CPU_COMPONENT_CHEAT_DEVICE); + cpu->components[CPU_COMPONENT_CHEAT_DEVICE] = NULL; + mCheatDeviceDestroy(gbacore->cheatDevice); + gbacore->cheatDevice = NULL; + } return GBAUnloadROM(core->board); }