(finally) build the goddamn cheat interface

This commit is contained in:
Arisotura
2020-08-15 00:14:05 +02:00
parent 4299ef5f06
commit f8d1d08e9c
11 changed files with 506 additions and 35 deletions

View File

@ -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);
}
}