diff --git a/source/cart_hw/ggenie.c b/source/cart_hw/ggenie.c index 719a079..853a9fe 100644 --- a/source/cart_hw/ggenie.c +++ b/source/cart_hw/ggenie.c @@ -121,39 +121,27 @@ void ggenie_switch(int enable) int i,j; if (enable) { + /* enable cheats */ for (i=0; i<6; i++) { /* patch is enabled ? */ if (ggenie.regs[0] & (1 << i)) { - /* first look if address has not already been patched */ - for (j=0;j=0; i--) { /* patch is enabled ? */ if (ggenie.regs[0] & (1 << i)) { + /* restore original ROM value */ *(uint16 *)(cart.rom + ggenie.addr[i]) = ggenie.old[i]; } } diff --git a/source/gx/gui/cheats.c b/source/gx/gui/cheats.c index f769f98..c23f3f0 100644 --- a/source/gx/gui/cheats.c +++ b/source/gx/gui/cheats.c @@ -339,14 +339,18 @@ static void apply_cheats(void) static void clear_cheats(void) { - int i; - for (i = 0; i < maxcheats; i++) + int i = maxcheats; + + /* disable cheats in reversed order in case the same address is used by multiple patches */ + while (i > 0) { /* restore original ROM data */ - if (cheatlist[i].enable && (cheatlist[i].address < cart.romsize)) + if (cheatlist[i-1].enable && (cheatlist[i-1].address < cart.romsize)) { - *(u16 *)(cart.rom + (cheatlist[i].address & 0xFFFFFE)) = cheatlist[i].old; + *(u16 *)(cart.rom + (cheatlist[i-1].address & 0xFFFFFE)) = cheatlist[i-1].old; } + + i--; } }