summaryrefslogtreecommitdiff
path: root/libretro/libretro.cpp
diff options
context:
space:
mode:
authorToad King2014-02-17 19:57:43 -0500
committerToad King2014-02-17 19:57:43 -0500
commitfccecaa7c88b4943d85aebe6412a98f6165a8f36 (patch)
tree3eb33aced34f3de62520e1e1c7d27d060921d3fb /libretro/libretro.cpp
parent95b246566efccacd2e2258f23ee353c241196a19 (diff)
parent9b8697f1ebc967e485530d274172ddabc8dba576 (diff)
downloadsnes9x2002-fccecaa7c88b4943d85aebe6412a98f6165a8f36.tar.gz
snes9x2002-fccecaa7c88b4943d85aebe6412a98f6165a8f36.tar.bz2
snes9x2002-fccecaa7c88b4943d85aebe6412a98f6165a8f36.zip
Merge pull request #4 from virmitio/master
add libretro cheat support
Diffstat (limited to 'libretro/libretro.cpp')
-rw-r--r--libretro/libretro.cpp44
1 files changed, 40 insertions, 4 deletions
diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp
index ccc1859..f1f6757 100644
--- a/libretro/libretro.cpp
+++ b/libretro/libretro.cpp
@@ -231,7 +231,7 @@ static void snes_init (void)
Settings.NetPlay = FALSE;
Settings.ServerName [0] = 0;
Settings.AutoSaveDelay = 30;
- Settings.ApplyCheats = FALSE;
+ Settings.ApplyCheats = TRUE;
Settings.TurboMode = FALSE;
Settings.TurboSkipFrames = 15;
Settings.ThreadSound = FALSE;
@@ -406,10 +406,46 @@ bool retro_unserialize(const void * data, size_t size)
}
void retro_cheat_reset(void)
-{}
+{
+ S9xDeleteCheats();
+}
-void retro_cheat_set(unsigned unused, bool unused1, const char* unused2)
-{}
+void retro_cheat_set(unsigned index, bool enable, const char* in_code)
+{
+ // clean input
+ char clean_code[strlen(in_code)];
+ int i,j =0;
+ for (i = 0; i<strlen(in_code); i++)
+ {
+ switch (in_code[i])
+ {
+ case 'a': case 'A':
+ case 'b': case 'B':
+ case 'c': case 'C':
+ case 'd': case 'D':
+ case 'e': case 'E':
+ case 'f': case 'F':
+
+ case '-': case '0':
+ case '1': case '2': case '3':
+ case '4': case '5': case '6':
+ case '7': case '8': case '9':
+ clean_code[j++]=in_code[i];
+ break;
+ default:
+ break;
+ }
+ }
+ clean_code[j]=0;
+ uint32 address;
+ uint8 byte;
+
+ if ( S9xProActionReplayToRaw(clean_code, address, byte) == NULL)
+ S9xAddCheat(true, true, address, byte);
+ else if ( S9xGameGenieToRaw(clean_code, address, byte) == NULL)
+ S9xAddCheat(true, true, address, byte);
+ // else, silently ignore
+}
bool retro_load_game(const struct retro_game_info *game)
{