From 0b362afcc03cbcca5b34eddcdb26445d29dcb87e Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Mon, 31 Aug 2020 12:49:42 +0800 Subject: [PATCH 1/3] Cheats: Fix pro action replay cheat format Two issues are causiong PAR cheats to not work. 1. GG decoder should only accept specific characters. When it fails, assume PAR code. 2. The corrent code that makes PAR decoding work was not set. Both fixed on this PR with some added notes. --- src/cheat.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/cheat.c b/src/cheat.c index f92e8d4..2602bf5 100644 --- a/src/cheat.c +++ b/src/cheat.c @@ -332,27 +332,33 @@ int FCEUI_DecodeGG(const char *str, uint16 *a, uint8 *v, int *c) { if (s != 6 && s != 8) return(0); t = GGtobin(*str++); + if (!t) return (0); V |= (t & 0x07); V |= (t & 0x08) << 4; t = GGtobin(*str++); + if (!t) return (0); V |= (t & 0x07) << 4; A |= (t & 0x08) << 4; t = GGtobin(*str++); + if (!t) return (0); A |= (t & 0x07) << 4; /* if(t&0x08) return(0); */ /* 8-character code?! */ t = GGtobin(*str++); + if (!t) return (0); A |= (t & 0x07) << 12; A |= (t & 0x08); t = GGtobin(*str++); + if (!t) return (0); A |= (t & 0x07); A |= (t & 0x08) << 8; if (s == 6) { t = GGtobin(*str++); + if (!t) return (0); A |= (t & 0x07) << 8; V |= (t & 0x08); @@ -362,14 +368,17 @@ int FCEUI_DecodeGG(const char *str, uint16 *a, uint8 *v, int *c) { return(1); } else { t = GGtobin(*str++); + if (!t) return (0); A |= (t & 0x07) << 8; C |= (t & 0x08); t = GGtobin(*str++); + if (!t) return (0); C |= (t & 0x07); C |= (t & 0x08) << 4; t = GGtobin(*str++); + if (!t) return (0); C |= (t & 0x07) << 4; V |= (t & 0x08); *a = A; @@ -388,13 +397,21 @@ int FCEUI_DecodePAR(const char *str, uint16 *a, uint8 *v, int *c, int *type) { *c = -1; - if (1) { + /* 2020-08-31 - negativeExponent + * Why is the top code set as default on non-debug runtime when + * bottom code is what works for PAR? + */ + /* if (1) { *a = (boo[3] << 8) | (boo[2] + 0x7F); *v = 0; } else { *v = boo[3]; *a = boo[2] | (boo[1] << 8); - } + } */ + + *v = boo[3]; + *a = boo[2] | (boo[1] << 8); + /* Zero-page addressing modes don't go through the normal read/write handlers in FCEU, so we must do the old hacky method of RAM cheats. */ From 0ca1e69a9d87a91e9aa376564d25793d9ed0be04 Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Mon, 31 Aug 2020 13:09:40 +0800 Subject: [PATCH 2/3] Cheat: Add raw codes support in xxxx?yy:zz format --- src/drivers/libretro/libretro.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index 2bef7bb..11137e3 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -1985,11 +1985,22 @@ void retro_cheat_set(unsigned index, bool enabled, const char *code) { if ((strlen(codepart) == 7) && (codepart[4]==':')) { - /* raw code format */ - c = -1; + /* raw code in xxxx:xx format */ codepart[4] = '\0'; a = strtoul(codepart, NULL, 16); v = strtoul(codepart + 5, NULL, 16); + c = -1; + FCEUI_AddCheat(name, a, v, c, type); + log_cb.log(RETRO_LOG_DEBUG, "Cheat code added: '%s' (Raw)\n", codepart); + } + else if ((strlen(codepart) == 10) && (codepart[4] == '?') && (codepart[7] == ':')) + { + /* raw code in xxxx?xx:xx */ + codepart[4] = '\0'; + codepart[7] = '\0'; + a = strtoul(codepart, NULL, 16); + v = strtoul(codepart + 8, NULL, 16); + c = strtoul(codepart + 5, NULL, 16); FCEUI_AddCheat(name, a, v, c, type); log_cb.log(RETRO_LOG_DEBUG, "Cheat code added: '%s' (Raw)\n", codepart); } From 771822a2e0d93b51d57f9f45ec21f3cdea5471dd Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Mon, 31 Aug 2020 13:38:58 +0800 Subject: [PATCH 3/3] Fix logs --- src/drivers/libretro/libretro.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index 11137e3..153e746 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -1986,23 +1986,23 @@ void retro_cheat_set(unsigned index, bool enabled, const char *code) if ((strlen(codepart) == 7) && (codepart[4]==':')) { /* raw code in xxxx:xx format */ + log_cb.log(RETRO_LOG_DEBUG, "Cheat code added: '%s' (Raw)\n", codepart); codepart[4] = '\0'; a = strtoul(codepart, NULL, 16); v = strtoul(codepart + 5, NULL, 16); c = -1; FCEUI_AddCheat(name, a, v, c, type); - log_cb.log(RETRO_LOG_DEBUG, "Cheat code added: '%s' (Raw)\n", codepart); } else if ((strlen(codepart) == 10) && (codepart[4] == '?') && (codepart[7] == ':')) { /* raw code in xxxx?xx:xx */ + log_cb.log(RETRO_LOG_DEBUG, "Cheat code added: '%s' (Raw)\n", codepart); codepart[4] = '\0'; codepart[7] = '\0'; a = strtoul(codepart, NULL, 16); v = strtoul(codepart + 8, NULL, 16); c = strtoul(codepart + 5, NULL, 16); FCEUI_AddCheat(name, a, v, c, type); - log_cb.log(RETRO_LOG_DEBUG, "Cheat code added: '%s' (Raw)\n", codepart); } else if (FCEUI_DecodeGG(codepart, &a, &v, &c)) {