mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-25 15:19:53 -06:00
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:

committed by
GitHub

parent
c84cb17462
commit
e973236203
183
src/DSi.h
183
src/DSi.h
@ -20,7 +20,12 @@
|
||||
#define DSI_H
|
||||
|
||||
#include "NDS.h"
|
||||
#include "DSi_NDMA.h"
|
||||
#include "DSi_SD.h"
|
||||
#include "DSi_DSP.h"
|
||||
#include "DSi_AES.h"
|
||||
#include "DSi_Camera.h"
|
||||
#include "DSi_NAND.h"
|
||||
|
||||
namespace melonDS
|
||||
{
|
||||
@ -34,99 +39,135 @@ namespace DSi_NAND
|
||||
class NANDImage;
|
||||
}
|
||||
|
||||
namespace DSi
|
||||
class DSi final : public NDS
|
||||
{
|
||||
protected:
|
||||
void DoSavestateExtra(Savestate* file) override;
|
||||
public:
|
||||
u16 SCFG_BIOS;
|
||||
u16 SCFG_Clock9;
|
||||
u32 SCFG_EXT[2];
|
||||
|
||||
extern u16 SCFG_BIOS;
|
||||
extern u16 SCFG_Clock9;
|
||||
extern u32 SCFG_EXT[2];
|
||||
u8 ARM9iBIOS[0x10000];
|
||||
u8 ARM7iBIOS[0x10000];
|
||||
std::unique_ptr<DSi_NAND::NANDImage> NANDImage;
|
||||
DSi_SDHost SDMMC;
|
||||
DSi_SDHost SDIO;
|
||||
|
||||
const u32 NWRAMSize = 0x40000;
|
||||
|
||||
extern u8 ARM9iBIOS[0x10000];
|
||||
extern u8 ARM7iBIOS[0x10000];
|
||||
u8* NWRAM_A;
|
||||
u8* NWRAM_B;
|
||||
u8* NWRAM_C;
|
||||
|
||||
extern std::unique_ptr<DSi_NAND::NANDImage> NANDImage;
|
||||
extern DSi_SDHost* SDMMC;
|
||||
extern DSi_SDHost* SDIO;
|
||||
u8* NWRAMMap_A[2][4];
|
||||
u8* NWRAMMap_B[3][8];
|
||||
u8* NWRAMMap_C[3][8];
|
||||
|
||||
const u32 NWRAMSize = 0x40000;
|
||||
u32 NWRAMStart[2][3];
|
||||
u32 NWRAMEnd[2][3];
|
||||
u32 NWRAMMask[2][3];
|
||||
|
||||
extern u8* NWRAM_A;
|
||||
extern u8* NWRAM_B;
|
||||
extern u8* NWRAM_C;
|
||||
DSi_I2CHost I2C;
|
||||
DSi_CamModule CamModule;
|
||||
DSi_AES AES;
|
||||
DSi_DSP DSP;
|
||||
|
||||
extern u8* NWRAMMap_A[2][4];
|
||||
extern u8* NWRAMMap_B[3][8];
|
||||
extern u8* NWRAMMap_C[3][8];
|
||||
void Reset() override;
|
||||
void Stop(Platform::StopReason reason) override;
|
||||
|
||||
extern u32 NWRAMStart[2][3];
|
||||
extern u32 NWRAMEnd[2][3];
|
||||
extern u32 NWRAMMask[2][3];
|
||||
bool DoSavestate(Savestate* file);
|
||||
|
||||
extern DSi_I2CHost* I2C;
|
||||
extern DSi_CamModule* CamModule;
|
||||
extern DSi_AES* AES;
|
||||
extern DSi_DSP* DSP;
|
||||
void SetCartInserted(bool inserted);
|
||||
|
||||
bool Init();
|
||||
void DeInit();
|
||||
void Reset();
|
||||
void Stop();
|
||||
void SetupDirectBoot() override;
|
||||
void SoftReset();
|
||||
|
||||
void DoSavestate(Savestate* file);
|
||||
bool LoadNAND();
|
||||
|
||||
void SetCartInserted(bool inserted);
|
||||
void RunNDMAs(u32 cpu);
|
||||
void StallNDMAs();
|
||||
bool NDMAsInMode(u32 cpu, u32 mode);
|
||||
bool NDMAsRunning(u32 cpu);
|
||||
void CheckNDMAs(u32 cpu, u32 mode);
|
||||
void StopNDMAs(u32 cpu, u32 mode);
|
||||
|
||||
void SetupDirectBoot();
|
||||
void SoftReset();
|
||||
void MapNWRAM_A(u32 num, u8 val);
|
||||
void MapNWRAM_B(u32 num, u8 val);
|
||||
void MapNWRAM_C(u32 num, u8 val);
|
||||
void MapNWRAMRange(u32 cpu, u32 num, u32 val);
|
||||
|
||||
bool LoadNAND();
|
||||
u8 ARM9Read8(u32 addr) override;
|
||||
u16 ARM9Read16(u32 addr) override;
|
||||
u32 ARM9Read32(u32 addr) override;
|
||||
void ARM9Write8(u32 addr, u8 val) override;
|
||||
void ARM9Write16(u32 addr, u16 val) override;
|
||||
void ARM9Write32(u32 addr, u32 val) override;
|
||||
|
||||
void RunNDMAs(u32 cpu);
|
||||
void StallNDMAs();
|
||||
bool NDMAsInMode(u32 cpu, u32 mode);
|
||||
bool NDMAsRunning(u32 cpu);
|
||||
void CheckNDMAs(u32 cpu, u32 mode);
|
||||
void StopNDMAs(u32 cpu, u32 mode);
|
||||
bool ARM9GetMemRegion(u32 addr, bool write, MemRegion* region) override;
|
||||
|
||||
void MapNWRAM_A(u32 num, u8 val);
|
||||
void MapNWRAM_B(u32 num, u8 val);
|
||||
void MapNWRAM_C(u32 num, u8 val);
|
||||
void MapNWRAMRange(u32 cpu, u32 num, u32 val);
|
||||
u8 ARM7Read8(u32 addr) override;
|
||||
u16 ARM7Read16(u32 addr) override;
|
||||
u32 ARM7Read32(u32 addr) override;
|
||||
void ARM7Write8(u32 addr, u8 val) override;
|
||||
void ARM7Write16(u32 addr, u16 val) override;
|
||||
void ARM7Write32(u32 addr, u32 val) override;
|
||||
|
||||
u8 ARM9Read8(u32 addr);
|
||||
u16 ARM9Read16(u32 addr);
|
||||
u32 ARM9Read32(u32 addr);
|
||||
void ARM9Write8(u32 addr, u8 val);
|
||||
void ARM9Write16(u32 addr, u16 val);
|
||||
void ARM9Write32(u32 addr, u32 val);
|
||||
bool ARM7GetMemRegion(u32 addr, bool write, MemRegion* region) override;
|
||||
|
||||
bool ARM9GetMemRegion(u32 addr, bool write, NDS::MemRegion* region);
|
||||
u8 ARM9IORead8(u32 addr) override;
|
||||
u16 ARM9IORead16(u32 addr) override;
|
||||
u32 ARM9IORead32(u32 addr) override;
|
||||
void ARM9IOWrite8(u32 addr, u8 val) override;
|
||||
void ARM9IOWrite16(u32 addr, u16 val) override;
|
||||
void ARM9IOWrite32(u32 addr, u32 val) override;
|
||||
|
||||
u8 ARM7Read8(u32 addr);
|
||||
u16 ARM7Read16(u32 addr);
|
||||
u32 ARM7Read32(u32 addr);
|
||||
void ARM7Write8(u32 addr, u8 val);
|
||||
void ARM7Write16(u32 addr, u16 val);
|
||||
void ARM7Write32(u32 addr, u32 val);
|
||||
u8 ARM7IORead8(u32 addr) override;
|
||||
u16 ARM7IORead16(u32 addr) override;
|
||||
u32 ARM7IORead32(u32 addr) override;
|
||||
void ARM7IOWrite8(u32 addr, u8 val) override;
|
||||
void ARM7IOWrite16(u32 addr, u16 val) override;
|
||||
void ARM7IOWrite32(u32 addr, u32 val) override;
|
||||
|
||||
bool ARM7GetMemRegion(u32 addr, bool write, NDS::MemRegion* region);
|
||||
public:
|
||||
DSi() noexcept;
|
||||
~DSi() noexcept override;
|
||||
DSi(const DSi&) = delete;
|
||||
DSi& operator=(const DSi&) = delete;
|
||||
DSi(DSi&&) = delete;
|
||||
DSi& operator=(DSi&&) = delete;
|
||||
bool LoadCart(const u8* romdata, u32 romlen, const u8* savedata, u32 savelen) override;
|
||||
void EjectCart() override;
|
||||
bool NeedsDirectBoot() override
|
||||
{
|
||||
// for now, DSi mode requires original BIOS/NAND
|
||||
return false;
|
||||
}
|
||||
void CamInputFrame(int cam, u32* data, int width, int height, bool rgb) override;
|
||||
bool DMAsInMode(u32 cpu, u32 mode) override;
|
||||
bool DMAsRunning(u32 cpu) override;
|
||||
void StopDMAs(u32 cpu, u32 mode) override;
|
||||
void CheckDMAs(u32 cpu, u32 mode) override;
|
||||
u16 SCFG_Clock7;
|
||||
u32 SCFG_MC;
|
||||
u16 SCFG_RST;
|
||||
u32 MBK[2][9];
|
||||
u32 NDMACnt[2];
|
||||
std::array<DSi_NDMA, 8> NDMAs;
|
||||
// FIXME: these currently have no effect (and aren't stored in a savestate)
|
||||
// ... not that they matter all that much
|
||||
u8 GPIO_Data;
|
||||
u8 GPIO_Dir;
|
||||
u8 GPIO_IEdgeSel;
|
||||
u8 GPIO_IE;
|
||||
u8 GPIO_WiFi;
|
||||
|
||||
u8 ARM9IORead8(u32 addr);
|
||||
u16 ARM9IORead16(u32 addr);
|
||||
u32 ARM9IORead32(u32 addr);
|
||||
void ARM9IOWrite8(u32 addr, u8 val);
|
||||
void ARM9IOWrite16(u32 addr, u16 val);
|
||||
void ARM9IOWrite32(u32 addr, u32 val);
|
||||
|
||||
u8 ARM7IORead8(u32 addr);
|
||||
u16 ARM7IORead16(u32 addr);
|
||||
u32 ARM7IORead32(u32 addr);
|
||||
void ARM7IOWrite8(u32 addr, u8 val);
|
||||
void ARM7IOWrite16(u32 addr, u16 val);
|
||||
void ARM7IOWrite32(u32 addr, u32 val);
|
||||
|
||||
}
|
||||
private:
|
||||
void Set_SCFG_Clock9(u16 val);
|
||||
void Set_SCFG_MC(u32 val);
|
||||
void DecryptModcryptArea(u32 offset, u32 size, u8* iv);
|
||||
void ApplyNewRAMSize(u32 size);
|
||||
};
|
||||
|
||||
}
|
||||
#endif // DSI_H
|
||||
|
Reference in New Issue
Block a user