From 5567576861389ab3ba3a9f80573ec4023f9dac40 Mon Sep 17 00:00:00 2001 From: ekeeke31 Date: Wed, 23 Feb 2011 19:17:21 +0000 Subject: [PATCH] fixed cheat codes handling when multiple codes affect identical ROM address --- source/cart_hw/ggenie.c | 24 ++++++------------------ source/gx/gui/cheats.c | 12 ++++++++---- 2 files changed, 14 insertions(+), 22 deletions(-) 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--; } }