aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/Util_ROM.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/Util_ROM.cpp')
-rw-r--r--src/frontend/Util_ROM.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/frontend/Util_ROM.cpp b/src/frontend/Util_ROM.cpp
index 8116a93..421a6e6 100644
--- a/src/frontend/Util_ROM.cpp
+++ b/src/frontend/Util_ROM.cpp
@@ -27,6 +27,8 @@
#include "NDS.h"
#include "GBACart.h"
+#include "AREngine.h"
+
namespace Frontend
{
@@ -37,6 +39,9 @@ char PrevSRAMPath[ROMSlot_MAX][1024]; // for savestate 'undo load'
bool SavestateLoaded;
+ARCodeFile* CheatFile;
+bool CheatsOn;
+
void Init_ROM()
{
@@ -48,6 +53,18 @@ void Init_ROM()
memset(SRAMPath[ROMSlot_GBA], 0, 1024);
memset(PrevSRAMPath[ROMSlot_NDS], 0, 1024);
memset(PrevSRAMPath[ROMSlot_GBA], 0, 1024);
+
+ CheatFile = nullptr;
+ CheatsOn = false;
+}
+
+void DeInit_ROM()
+{
+ if (CheatFile)
+ {
+ delete CheatFile;
+ CheatFile = nullptr;
+ }
}
// TODO: currently, when failing to load a ROM for whatever reason, we attempt
@@ -198,6 +215,25 @@ int VerifyDSiNAND()
return Load_OK;
}
+void LoadCheats()
+{
+ if (CheatFile)
+ {
+ delete CheatFile;
+ CheatFile = nullptr;
+ }
+
+ char filename[1024];
+ strncpy(filename, ROMPath[ROMSlot_NDS], 1023);
+ filename[1023] = '\0';
+ strncpy(filename + strlen(ROMPath[ROMSlot_NDS]) - 3, "mch", 3);
+
+ // TODO: check for error (malformed cheat file, ...)
+ CheatFile = new ARCodeFile(filename);
+
+ AREngine::SetCodeFile(CheatsOn ? CheatFile : nullptr);
+}
+
int LoadBIOS()
{
int res;
@@ -235,6 +271,8 @@ int LoadBIOS()
SavestateLoaded = false;
+ LoadCheats();
+
return Load_OK;
}
@@ -295,6 +333,8 @@ int LoadROM(const char* file, int slot)
{
SavestateLoaded = false;
+ LoadCheats();
+
// Reload the inserted GBA cartridge (if any)
// TODO: report failure there??
if (ROMPath[ROMSlot_GBA][0] != '\0') NDS::LoadGBAROM(ROMPath[ROMSlot_GBA], SRAMPath[ROMSlot_GBA]);
@@ -387,6 +427,8 @@ int Reset()
return Load_ROMLoadError;
}
+ LoadCheats();
+
return Load_OK;
}
@@ -539,4 +581,11 @@ void UndoStateLoad()
}
}
+void EnableCheats(bool enable)
+{
+ CheatsOn = enable;
+ if (CheatFile)
+ AREngine::SetCodeFile(CheatsOn ? CheatFile : nullptr);
+}
+
}