Add support for short GG cheats.

This commit is contained in:
iLag 2017-03-25 20:04:04 -07:00
parent 929d8bd723
commit 0ac5889f81

View File

@ -1265,7 +1265,7 @@ static uint32_t decode_cheat(char *string, int index)
//If System is Master-based //If System is Master-based
//Game Genie //Game Genie
if ((strlen(string) >=11) && (string[3] == '-') && (string[7] == '-')) if ((strlen(string) >=7) && (string[3] == '-'))
{ {
/* decode 8-bit data */ /* decode 8-bit data */
for (i=0; i<2; i++) for (i=0; i<2; i++)
@ -1290,13 +1290,9 @@ static uint32_t decode_cheat(char *string, int index)
n = (p - arvalidchars) & 0xF; n = (p - arvalidchars) & 0xF;
n ^= 0xF; /* bits inversion */ n ^= 0xF; /* bits inversion */
address |= (n << 12); address |= (n << 12);
/* RAM address are also supported */ /* Optional: decode reference 8-bit data */
if (address >= 0xC000) if (*string=='-')
{ {
/* convert to 24-bit Work RAM address */
address = 0xFF0000 | (address & 0x1FFF);
}
/* decode reference 8-bit data */
for (i=0; i<2; i++) for (i=0; i<2; i++)
{ {
string++; /* skip separator and 2nd digit */ string++; /* skip separator and 2nd digit */
@ -1307,11 +1303,15 @@ static uint32_t decode_cheat(char *string, int index)
} }
ref = (ref >> 2) | ((ref & 0x03) << 6); /* 2-bit right rotation */ ref = (ref >> 2) | ((ref & 0x03) << 6); /* 2-bit right rotation */
ref ^= 0xBA; /* XOR */ ref ^= 0xBA; /* XOR */
/* update old data value */
cheatlist[index].old = ref;
/* code length */ /* code length */
len = 11; len = 11;
} }
else
{
/* code length */
len = 7;
}
}
//Action Replay //Action Replay
else if ((strlen(string) >=9) && (string[4] == '-')){ else if ((strlen(string) >=9) && (string[4] == '-')){
@ -1389,11 +1389,14 @@ static uint32_t decode_cheat(char *string, int index)
n = (p - arvalidchars) & 0xF; n = (p - arvalidchars) & 0xF;
data |= (n << ((1 - i) * 4)); data |= (n << ((1 - i) * 4));
} }
/* update old data value */
cheatlist[index].old = ref;
/* code length */ /* code length */
len = 9; len = 9;
} }
/* convert to 24-bit Work RAM address */
if (address >= 0xC000)
{
address = 0xFF0000 | (address & 0x1FFF);
}
} }
/* Valid code found ? */ /* Valid code found ? */
if (len) if (len)
@ -1401,6 +1404,7 @@ static uint32_t decode_cheat(char *string, int index)
/* update cheat address & data values */ /* update cheat address & data values */
cheatlist[index].address = address; cheatlist[index].address = address;
cheatlist[index].data = data; cheatlist[index].data = data;
cheatlist[index].old = ref;
} }
/* return code length (0 = invalid) */ /* return code length (0 = invalid) */
return len; return len;
@ -1544,8 +1548,8 @@ void ROMCheatUpdate(void)
/* get current banked ROM address */ /* get current banked ROM address */
ptr = &z80_readmap[(cheatlist[index].address) >> 10][cheatlist[index].address & 0x03FF]; ptr = &z80_readmap[(cheatlist[index].address) >> 10][cheatlist[index].address & 0x03FF];
/* check if reference matches original ROM data */ /* check if reference exists and matches original ROM data */
if (((uint8_t)cheatlist[index].old) == *ptr) if (!cheatlist[index].old || ((uint8_t)cheatlist[index].old) == *ptr)
{ {
/* patch data */ /* patch data */
*ptr = cheatlist[index].data; *ptr = cheatlist[index].data;