Skip to content

Commit

Permalink
convert AREngine
Browse files Browse the repository at this point in the history
  • Loading branch information
Arisotura committed Nov 4, 2023
1 parent 2bd09ea commit 8f1b0d4
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 47 deletions.
37 changes: 5 additions & 32 deletions src/AREngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,17 @@
using Platform::Log;
using Platform::LogLevel;

namespace AREngine
{

// AR code file - frontend is responsible for managing this
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()
AREngine::AREngine()
{
CodeFile = nullptr;

return true;
}

void DeInit()
AREngine::~AREngine()
{
}

void Reset()
void AREngine::Reset()
{
if (NDS::ConsoleType == 1)
{
Expand All @@ -74,24 +59,14 @@ void Reset()
}


ARCodeFile* GetCodeFile()
{
return CodeFile;
}

void SetCodeFile(ARCodeFile* file)
{
CodeFile = file;
}


#define case16(x) \
case ((x)+0x00): case ((x)+0x01): case ((x)+0x02): case ((x)+0x03): \
case ((x)+0x04): case ((x)+0x05): case ((x)+0x06): case ((x)+0x07): \
case ((x)+0x08): case ((x)+0x09): case ((x)+0x0A): case ((x)+0x0B): \
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];

Expand Down Expand Up @@ -437,7 +412,7 @@ void RunCheat(ARCode& arcode)
}
}

void RunCheats()
void AREngine::RunCheats()
{
if (!CodeFile) return;

Expand All @@ -454,5 +429,3 @@ void RunCheats()
}
}
}

}
28 changes: 20 additions & 8 deletions src/AREngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,30 @@

#include "ARCodeFile.h"

namespace AREngine
class AREngine
{
public:
AREngine();
~AREngine();
void Reset();

bool Init();
void DeInit();
void Reset();
ARCodeFile* GetCodeFile() { return CodeFile; }
void SetCodeFile(ARCodeFile* file) { CodeFile = file; }

ARCodeFile* GetCodeFile();
void SetCodeFile(ARCodeFile* file);
void RunCheats();

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
2 changes: 1 addition & 1 deletion src/ARM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ void ARM::TriggerIRQ()
if (Num == 1)
{
if ((NDS::IF[1] & NDS::IE[1]) & (1<<NDS::IRQ_VBlank))
AREngine::RunCheats();
NDS::AREngine->RunCheats();
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/NDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ class SPIHost* SPI;
class RTC* RTC;
class Wifi* Wifi;

class AREngine* AREngine;

bool Running;

bool RunningGame;
Expand Down Expand Up @@ -231,7 +233,7 @@ bool Init()

if (!DSi::Init()) return false;

if (!AREngine::Init()) return false;
AREngine = new class AREngine();

return true;
}
Expand Down Expand Up @@ -262,7 +264,7 @@ void DeInit()

DSi::DeInit();

AREngine::DeInit();
delete AREngine; AREngine = nullptr;

UnregisterEventFunc(Event_Div, 0);
UnregisterEventFunc(Event_Sqrt, 0);
Expand Down Expand Up @@ -671,7 +673,7 @@ void Reset()

SPU->SetDegrade10Bit(degradeAudio);

AREngine::Reset();
AREngine->Reset();
}

void Start()
Expand Down
4 changes: 4 additions & 0 deletions src/NDS.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class SPIHost;
class RTC;
class Wifi;

class AREngine;

namespace NDS
{

Expand Down Expand Up @@ -256,6 +258,8 @@ extern class SPIHost* SPI;
extern class RTC* RTC;
extern class Wifi* Wifi;

extern class AREngine* AREngine;

const u32 ARM7WRAMSize = 0x10000;
extern u8* ARM7WRAM;

Expand Down
6 changes: 3 additions & 3 deletions src/frontend/qt_sdl/ROMManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ void UnloadCheats()
{
delete CheatFile;
CheatFile = nullptr;
AREngine::SetCodeFile(nullptr);
NDS::AREngine->SetCodeFile(nullptr);
}
}

Expand All @@ -475,7 +475,7 @@ void LoadCheats()
// TODO: check for error (malformed cheat file, ...)
CheatFile = new ARCodeFile(filename);

AREngine::SetCodeFile(CheatsOn ? CheatFile : nullptr);
NDS::AREngine->SetCodeFile(CheatsOn ? CheatFile : nullptr);
}

void LoadBIOSFiles()
Expand Down Expand Up @@ -570,7 +570,7 @@ void EnableCheats(bool enable)
{
CheatsOn = enable;
if (CheatFile)
AREngine::SetCodeFile(CheatsOn ? CheatFile : nullptr);
NDS::AREngine->SetCodeFile(CheatsOn ? CheatFile : nullptr);
}

ARCodeFile* GetCheatFile()
Expand Down

0 comments on commit 8f1b0d4

Please sign in to comment.