Skip to content

Commit

Permalink
Move NDSCart-related global state into objects (#1871)
Browse files Browse the repository at this point in the history
* Move NDSCart-related global state into objects

- RAII will now do the heavy lifting
- Mark some methods as const or noexcept

* Move GBACart-related global state into objects (#1870)

- RAII will now do the heavy lifting
- Mark some methods as const or noexcept
- Once the `NDS` object is finalized, most of these `assert`s can go away

* Make AREngine::RunCheat public (#1872)

- I use it directly in melonDS DS to apply single cheats without using ARCodeFile
- Before the AREngine refactor I could just redeclare the function in my code
- Now I can't
  • Loading branch information
JesseTG authored Nov 9, 2023
1 parent 3d3e424 commit 88072a0
Show file tree
Hide file tree
Showing 7 changed files with 329 additions and 327 deletions.
7 changes: 6 additions & 1 deletion src/ARMJIT_Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,11 @@ T VRAMRead(u32 addr)
}
}

u32 NDSCartSlot_ReadROMData()
{ // TODO: Add a NDS* parameter, when NDS* is eventually implemented
return NDS::NDSCartSlot->ReadROMData();
}

void* GetFuncForAddr(ARM* cpu, u32 addr, bool store, int size)
{
if (cpu->Num == 0)
Expand All @@ -1256,7 +1261,7 @@ void* GetFuncForAddr(ARM* cpu, u32 addr, bool store, int size)
{
case 0x04000000:
if (!store && size == 32 && addr == 0x04100010 && NDS::ExMemCnt[0] & (1<<11))
return (void*)NDSCart::ReadROMData;
return (void*)NDSCartSlot_ReadROMData;

/*
unfortunately we can't map GPU2D this way
Expand Down
16 changes: 8 additions & 8 deletions src/DSi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void Reset()
SCFG_Clock7 = 0x0187;
SCFG_EXT[0] = 0x8307F100;
SCFG_EXT[1] = 0x93FFFB06;
SCFG_MC = 0x0010 | (~((u32)(NDSCart::Cart != nullptr))&1);//0x0011;
SCFG_MC = 0x0010 | (~((u32)(NDS::NDSCartSlot->GetCart() != nullptr))&1);//0x0011;
SCFG_RST = 0;

DSP->SetRstLine(false);
Expand Down Expand Up @@ -310,13 +310,13 @@ void DecryptModcryptArea(u32 offset, u32 size, u8* iv)
if ((offset == 0) || (size == 0))
return;

const NDSHeader& header = NDSCart::Cart->GetHeader();
const NDSHeader& header = NDS::NDSCartSlot->GetCart()->GetHeader();

if ((header.DSiCryptoFlags & (1<<4)) ||
(header.AppFlags & (1<<7)))
{
// dev key
const u8* cartrom = NDSCart::Cart->GetROM();
const u8* cartrom = NDS::NDSCartSlot->GetCart()->GetROM();
memcpy(key, &cartrom[0], 16);
}
else
Expand Down Expand Up @@ -403,9 +403,9 @@ void DecryptModcryptArea(u32 offset, u32 size, u8* iv)
void SetupDirectBoot()
{
bool dsmode = false;
NDSHeader& header = NDSCart::Cart->GetHeader();
const u8* cartrom = NDSCart::Cart->GetROM();
u32 cartid = NDSCart::Cart->ID();
NDSHeader& header = NDS::NDSCartSlot->GetCart()->GetHeader();
const u8* cartrom = NDS::NDSCartSlot->GetCart()->GetROM();
u32 cartid = NDS::NDSCartSlot->GetCart()->ID();
DSi_TSC* tsc = (DSi_TSC*)NDS::SPI->GetTSC();

// TODO: add controls for forcing DS or DSi mode?
Expand Down Expand Up @@ -594,7 +594,7 @@ void SetupDirectBoot()
if (header.ARM9ROMOffset >= 0x4000 && header.ARM9ROMOffset < 0x8000)
{
u8 securearea[0x800];
NDSCart::DecryptSecureArea(securearea);
NDS::NDSCartSlot->DecryptSecureArea(securearea);

for (u32 i = 0; i < 0x800; i+=4)
{
Expand Down Expand Up @@ -1289,7 +1289,7 @@ void Set_SCFG_MC(u32 val)

if ((oldslotstatus == 0x0) && ((SCFG_MC & 0xC) == 0x4))
{
NDSCart::ResetCart();
NDS::NDSCartSlot->ResetCart();
}
}

Expand Down
Loading

0 comments on commit 88072a0

Please sign in to comment.