convert AREngine

This commit is contained in:
Arisotura 2023-11-04 17:28:16 +01:00
parent 2bd09eafeb
commit 8f1b0d4a05
6 changed files with 38 additions and 47 deletions

View File

@ -26,32 +26,17 @@
using Platform::Log; using Platform::Log;
using Platform::LogLevel; using Platform::LogLevel;
namespace AREngine
{
// AR code file - frontend is responsible for managing this AREngine::AREngine()
ARCodeFile* CodeFile;
u8 (*BusRead8)(u32 addr);
u16 (*BusRead16)(u32 addr);
u32 (*BusRead32)(u32 addr);
void (*BusWrite8)(u32 addr, u8 val);
void (*BusWrite16)(u32 addr, u16 val);
void (*BusWrite32)(u32 addr, u32 val);
bool Init()
{ {
CodeFile = nullptr; CodeFile = nullptr;
return true;
} }
void DeInit() AREngine::~AREngine()
{ {
} }
void Reset() void AREngine::Reset()
{ {
if (NDS::ConsoleType == 1) if (NDS::ConsoleType == 1)
{ {
@ -74,16 +59,6 @@ void Reset()
} }
ARCodeFile* GetCodeFile()
{
return CodeFile;
}
void SetCodeFile(ARCodeFile* file)
{
CodeFile = file;
}
#define case16(x) \ #define case16(x) \
case ((x)+0x00): case ((x)+0x01): case ((x)+0x02): case ((x)+0x03): \ case ((x)+0x00): case ((x)+0x01): case ((x)+0x02): case ((x)+0x03): \
@ -91,7 +66,7 @@ void SetCodeFile(ARCodeFile* file)
case ((x)+0x08): case ((x)+0x09): case ((x)+0x0A): case ((x)+0x0B): \ case ((x)+0x08): case ((x)+0x09): case ((x)+0x0A): case ((x)+0x0B): \
case ((x)+0x0C): case ((x)+0x0D): case ((x)+0x0E): case ((x)+0x0F) case ((x)+0x0C): case ((x)+0x0D): case ((x)+0x0E): case ((x)+0x0F)
void RunCheat(ARCode& arcode) void AREngine::RunCheat(ARCode& arcode)
{ {
u32* code = &arcode.Code[0]; u32* code = &arcode.Code[0];
@ -437,7 +412,7 @@ void RunCheat(ARCode& arcode)
} }
} }
void RunCheats() void AREngine::RunCheats()
{ {
if (!CodeFile) return; if (!CodeFile) return;
@ -454,5 +429,3 @@ void RunCheats()
} }
} }
} }
}

View File

@ -21,18 +21,30 @@
#include "ARCodeFile.h" #include "ARCodeFile.h"
namespace AREngine class AREngine
{ {
public:
AREngine();
~AREngine();
void Reset();
bool Init(); ARCodeFile* GetCodeFile() { return CodeFile; }
void DeInit(); void SetCodeFile(ARCodeFile* file) { CodeFile = file; }
void Reset();
ARCodeFile* GetCodeFile(); void RunCheats();
void SetCodeFile(ARCodeFile* file);
void RunCheats(); private:
ARCodeFile* CodeFile; // AR code file - frontend is responsible for managing this
} // TEMPORARY
u8 (*BusRead8)(u32 addr);
u16 (*BusRead16)(u32 addr);
u32 (*BusRead32)(u32 addr);
void (*BusWrite8)(u32 addr, u8 val);
void (*BusWrite16)(u32 addr, u16 val);
void (*BusWrite32)(u32 addr, u32 val);
void RunCheat(ARCode& arcode);
};
#endif // ARENGINE_H #endif // ARENGINE_H

View File

@ -590,7 +590,7 @@ void ARM::TriggerIRQ()
if (Num == 1) if (Num == 1)
{ {
if ((NDS::IF[1] & NDS::IE[1]) & (1<<NDS::IRQ_VBlank)) if ((NDS::IF[1] & NDS::IE[1]) & (1<<NDS::IRQ_VBlank))
AREngine::RunCheats(); NDS::AREngine->RunCheats();
} }
} }

View File

@ -183,6 +183,8 @@ class SPIHost* SPI;
class RTC* RTC; class RTC* RTC;
class Wifi* Wifi; class Wifi* Wifi;
class AREngine* AREngine;
bool Running; bool Running;
bool RunningGame; bool RunningGame;
@ -231,7 +233,7 @@ bool Init()
if (!DSi::Init()) return false; if (!DSi::Init()) return false;
if (!AREngine::Init()) return false; AREngine = new class AREngine();
return true; return true;
} }
@ -262,7 +264,7 @@ void DeInit()
DSi::DeInit(); DSi::DeInit();
AREngine::DeInit(); delete AREngine; AREngine = nullptr;
UnregisterEventFunc(Event_Div, 0); UnregisterEventFunc(Event_Div, 0);
UnregisterEventFunc(Event_Sqrt, 0); UnregisterEventFunc(Event_Sqrt, 0);
@ -671,7 +673,7 @@ void Reset()
SPU->SetDegrade10Bit(degradeAudio); SPU->SetDegrade10Bit(degradeAudio);
AREngine::Reset(); AREngine->Reset();
} }
void Start() void Start()

View File

@ -35,6 +35,8 @@ class SPIHost;
class RTC; class RTC;
class Wifi; class Wifi;
class AREngine;
namespace NDS namespace NDS
{ {
@ -256,6 +258,8 @@ extern class SPIHost* SPI;
extern class RTC* RTC; extern class RTC* RTC;
extern class Wifi* Wifi; extern class Wifi* Wifi;
extern class AREngine* AREngine;
const u32 ARM7WRAMSize = 0x10000; const u32 ARM7WRAMSize = 0x10000;
extern u8* ARM7WRAM; extern u8* ARM7WRAM;

View File

@ -462,7 +462,7 @@ void UnloadCheats()
{ {
delete CheatFile; delete CheatFile;
CheatFile = nullptr; CheatFile = nullptr;
AREngine::SetCodeFile(nullptr); NDS::AREngine->SetCodeFile(nullptr);
} }
} }
@ -475,7 +475,7 @@ void LoadCheats()
// TODO: check for error (malformed cheat file, ...) // TODO: check for error (malformed cheat file, ...)
CheatFile = new ARCodeFile(filename); CheatFile = new ARCodeFile(filename);
AREngine::SetCodeFile(CheatsOn ? CheatFile : nullptr); NDS::AREngine->SetCodeFile(CheatsOn ? CheatFile : nullptr);
} }
void LoadBIOSFiles() void LoadBIOSFiles()
@ -570,7 +570,7 @@ void EnableCheats(bool enable)
{ {
CheatsOn = enable; CheatsOn = enable;
if (CheatFile) if (CheatFile)
AREngine::SetCodeFile(CheatsOn ? CheatFile : nullptr); NDS::AREngine->SetCodeFile(CheatsOn ? CheatFile : nullptr);
} }
ARCodeFile* GetCheatFile() ARCodeFile* GetCheatFile()