fixed cheat codes handling when multiple codes affect identical ROM address

This commit is contained in:
ekeeke31 2011-02-23 19:17:21 +00:00
parent ef8efa2c10
commit 5567576861
2 changed files with 14 additions and 22 deletions

View File

@ -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<i;j++)
{
if (ggenie.addr[i] == ggenie.addr[j])
{
/* disable code for later initialization */
ggenie.regs[0] &= ~(1 << i);
j = i;
}
}
/* save old value and patch ROM if enabled */
if (ggenie.regs[0] & (1 << i))
{
ggenie.old[i] = *(uint16 *)(cart.rom + ggenie.addr[i]);
*(uint16 *)(cart.rom + ggenie.addr[i]) = ggenie.data[i];
}
ggenie.old[i] = *(uint16 *)(cart.rom + ggenie.addr[i]);
*(uint16 *)(cart.rom + ggenie.addr[i]) = ggenie.data[i];
}
}
}
else
{
/* restore old values */
for (i=0; i<6; i++)
/* disable cheats in reversed order in case the same address is used by multiple patches */
for (i=5; i>=0; i--)
{
/* patch is enabled ? */
if (ggenie.regs[0] & (1 << i))
{
/* restore original ROM value */
*(uint16 *)(cart.rom + ggenie.addr[i]) = ggenie.old[i];
}
}

View File

@ -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--;
}
}