Refactor NDS and DSi to be objects (#1893)

* First crack at refactoring NDS and DSi into objects

- Remove all global/`static` variables in `NDS` and related classes
- Rely more on virtual dispatch when we need to pick methods at runtime
- Pass `NDS&` or `DSi&` to its constituent components where necessary
- Introduce some headers or move some definitions to break `#include` cycles

* Refactor the frontend to accommodate the core's changes

* Move up `SchedList`'s declaration

- Move it to before the components are initialized so the `map`s inside are initialized
- Fields in C++ are initialized in the order they're declared

* Fix a crash when allocating memory

* Fix JIT-free builds

* Fix GDB-free builds

* Fix Linux builds

- Explicitly qualify some member types in NDS, since they share the same name as their classes

* Remove an unnecessary template argument

- This was causing the build to fail on macOS

* Fix ARM and Android builds

* Rename `Constants.h` to `MemConstants.h`

* Add `NDS::IsRunning()`

* Use an `#include` guard instead of `#pragma once`
This commit is contained in:
Jesse Talavera-Greenberg
2023-11-28 17:16:41 -05:00
committed by GitHub
parent c84cb17462
commit e973236203
73 changed files with 3537 additions and 3176 deletions

View File

@ -139,6 +139,10 @@ const u8 CmdNumParams[256] =
void MatrixLoadIdentity(s32* m);
GPU3D::GPU3D(melonDS::NDS& nds) noexcept : NDS(nds)
{
}
void GPU3D::ResetRenderingState() noexcept
{
RenderNumPolygons = 0;
@ -1596,7 +1600,7 @@ void GPU3D::CmdFIFOWrite(CmdFIFOEntry& entry) noexcept
// has 64 entries. this is less complicated than trying to make STMxx stall-able.
CmdStallQueue.Write(entry);
NDS::GXFIFOStall();
NDS.GXFIFOStall();
return;
}
@ -1640,7 +1644,7 @@ GPU3D::CmdFIFOEntry GPU3D::CmdFIFORead() noexcept
}
if (CmdStallQueue.IsEmpty())
NDS::GXFIFOUnstall();
NDS.GXFIFOUnstall();
}
CheckFIFODMA();
@ -2273,13 +2277,13 @@ void GPU3D::Run() noexcept
if (!GeometryEnabled || FlushRequest ||
(CmdPIPE.IsEmpty() && !(GXStat & (1<<27))))
{
Timestamp = NDS::ARM9Timestamp >> NDS::ARM9ClockShift;
Timestamp = NDS.ARM9Timestamp >> NDS.ARM9ClockShift;
return;
}
s32 cycles = (NDS::ARM9Timestamp >> NDS::ARM9ClockShift) - Timestamp;
s32 cycles = (NDS.ARM9Timestamp >> NDS.ARM9ClockShift) - Timestamp;
CycleCount -= cycles;
Timestamp = NDS::ARM9Timestamp >> NDS::ARM9ClockShift;
Timestamp = NDS.ARM9Timestamp >> NDS.ARM9ClockShift;
if (CycleCount <= 0)
{
@ -2312,14 +2316,14 @@ void GPU3D::CheckFIFOIRQ() noexcept
case 2: irq = CmdFIFO.IsEmpty(); break;
}
if (irq) NDS::SetIRQ(0, NDS::IRQ_GXFIFO);
else NDS::ClearIRQ(0, NDS::IRQ_GXFIFO);
if (irq) NDS.SetIRQ(0, IRQ_GXFIFO);
else NDS.ClearIRQ(0, IRQ_GXFIFO);
}
void GPU3D::CheckFIFODMA() noexcept
{
if (CmdFIFO.Level() < 128)
NDS::CheckDMAs(0, 0x07);
NDS.CheckDMAs(0, 0x07);
}
void GPU3D::VCount144() noexcept