aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--libretro.c38
-rw-r--r--source/cheats.h4
3 files changed, 39 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index cdec8ba..bbd03ba 100644
--- a/Makefile
+++ b/Makefile
@@ -125,7 +125,7 @@ endif
DEFS += -DSPC700_C -DEXECUTE_SUPERFX_PER_LINE -DSDD1_DECOMP \
-DVAR_CYCLES -DCPU_SHUTDOWN -DSPC700_SHUTDOWN \
- -DNO_INLINE_SET_GET -DNOASM -DHAVE_MKSTEMP '-DACCEPT_SIZE_T=size_t'
+ -DNO_INLINE_SET_GET -DNOASM -DHAVE_MKSTEMP '-DACCEPT_SIZE_T=size_t' -DWANT_CHEATS
DEFS += -D__LIBRETRO__
diff --git a/libretro.c b/libretro.c
index bf33bd0..1f1a3aa 100644
--- a/libretro.c
+++ b/libretro.c
@@ -734,11 +734,45 @@ bool retro_unserialize(const void* data, size_t size)
void retro_cheat_reset(void)
{
-
+#ifdef WANT_CHEATS
+ S9xDeleteCheats();
+ S9xApplyCheats();
+#endif
}
+
+#ifdef WANT_CHEATS
+extern SCheatData Cheat;
+#endif
+
void retro_cheat_set(unsigned index, bool enabled, const char* code)
{
-
+#ifdef WANT_CHEATS
+ uint32_t address;
+ uint8_t val;
+
+ bool sram;
+ uint8_t bytes[3];//used only by GoldFinger, ignored for now
+
+ if (S9xGameGenieToRaw(code, &address, &val)!=NULL &&
+ S9xProActionReplayToRaw(code, &address, &val)!=NULL &&
+ S9xGoldFingerToRaw(code, &address, &sram, &val, bytes)!=NULL)
+ { // bad code, ignore
+ return;
+ }
+ if (index > Cheat.num_cheats)
+ return; // cheat added in weird order, ignore
+ if (index == Cheat.num_cheats)
+ Cheat.num_cheats++;
+
+ Cheat.c[index].address = address;
+ Cheat.c[index].byte = val;
+ Cheat.c[index].enabled = enabled;
+
+ Cheat.c[index].saved = false; // it'll be saved next time cheats run anyways
+
+ Settings.ApplyCheats=true;
+ S9xApplyCheats();
+#endif
}
static void init_descriptors(void)
diff --git a/source/cheats.h b/source/cheats.h
index 7d43f2b..2201c3c 100644
--- a/source/cheats.h
+++ b/source/cheats.h
@@ -137,7 +137,7 @@ const char *S9xGameGenieToRaw (const char *code, uint32_t *address, uint8_t *byt
const char *S9xProActionReplayToRaw (const char *code, uint32_t *address, uint8_t *byte);
const char *S9xGoldFingerToRaw (const char *code, uint32_t *address, bool *sram,
uint8_t *num_bytes, uint8_t bytes[3]);
-void S9xApplyCheats ();
+void S9xApplyCheats(void);
void S9xApplyCheat (uint32_t which1);
void S9xRemoveCheats ();
void S9xRemoveCheat (uint32_t which1);
@@ -146,7 +146,7 @@ void S9xDisableCheat (uint32_t which1);
void S9xDisableAllCheat(void);
void S9xAddCheat (bool enable, bool save_current_value, uint32_t address,
uint8_t byte);
-void S9xDeleteCheats ();
+void S9xDeleteCheats(void);
void S9xDeleteCheat (uint32_t which1);
bool S9xLoadCheatFile (const char *filename);
bool S9xSaveCheatFile (const char *filename);