Skip to content

Commit

Permalink
convert SPU to OOP
Browse files Browse the repository at this point in the history
  • Loading branch information
Arisotura committed Nov 4, 2023
1 parent ac38fae commit 76976fe
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 201 deletions.
4 changes: 2 additions & 2 deletions src/ARMJIT_Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ void* GetFuncForAddr(ARM* cpu, u32 addr, bool store, int size)
switch (addr & 0xFF800000)
{
case 0x04000000:
if (addr >= 0x04000400 && addr < 0x04000520)
/*if (addr >= 0x04000400 && addr < 0x04000520)
{
switch (size | store)
{
Expand All @@ -1331,7 +1331,7 @@ void* GetFuncForAddr(ARM* cpu, u32 addr, bool store, int size)
case 32: return (void*)SPU::Read32;
case 33: return (void*)SPU::Write32;
}
}
}*/

if (NDS::ConsoleType == 0)
{
Expand Down
55 changes: 25 additions & 30 deletions src/NDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ u32 KeyInput;
u16 KeyCnt[2];
u16 RCnt;

SPIHost* SPI;
class SPU* SPU;
class SPIHost* SPI;
class RTC* RTC;

bool Running;
Expand Down Expand Up @@ -218,13 +219,13 @@ bool Init()
DMAs[6] = new DMA(1, 2);
DMAs[7] = new DMA(1, 3);

SPI = new SPIHost();
SPU = new class SPU;
SPI = new class SPIHost();
RTC = new class RTC();

if (!NDSCart::Init()) return false;
if (!GBACart::Init()) return false;
if (!GPU::Init()) return false;
if (!SPU::Init()) return false;
if (!Wifi::Init()) return false;

if (!DSi::Init()) return false;
Expand All @@ -240,28 +241,22 @@ void DeInit()
ARMJIT::DeInit();
#endif

delete ARM9;
ARM9 = nullptr;

delete ARM7;
ARM7 = nullptr;
delete ARM9; ARM9 = nullptr;
delete ARM7; ARM7 = nullptr;

for (int i = 0; i < 8; i++)
{
delete DMAs[i];
DMAs[i] = nullptr;
}

delete SPI;
SPI = nullptr;

delete RTC;
RTC = nullptr;
delete SPU; SPU = nullptr;
delete SPI; SPI = nullptr;
delete RTC; RTC = nullptr;

NDSCart::DeInit();
GBACart::DeInit();
GPU::DeInit();
SPU::DeInit();
Wifi::DeInit();

DSi::DeInit();
Expand Down Expand Up @@ -529,7 +524,7 @@ void SetupDirectBoot(const std::string& romname)

NDSCart::SPICnt = 0x8000;

SPU::SetBias(0x200);
SPU->SetBias(0x200);

SetWifiWaitCnt(0x0030);
}
Expand Down Expand Up @@ -648,15 +643,15 @@ void Reset()
NDSCart::Reset();
GBACart::Reset();
GPU::Reset();
SPU::Reset();
SPU->Reset();
SPI->Reset();
RTC->Reset();
Wifi::Reset();

// TODO: move the SOUNDBIAS/degrade logic to SPU?

// The SOUNDBIAS register does nothing on DSi
SPU::SetApplyBias(ConsoleType == 0);
SPU->SetApplyBias(ConsoleType == 0);

bool degradeAudio = true;

Expand All @@ -673,7 +668,7 @@ void Reset()
else if (bitDepth == 2) // Always 16-bit
degradeAudio = false;

SPU::SetDegrade10Bit(degradeAudio);
SPU->SetDegrade10Bit(degradeAudio);

AREngine::Reset();
}
Expand Down Expand Up @@ -722,7 +717,7 @@ void Stop(Platform::StopReason reason)
Running = false;
Platform::SignalStop(reason);
GPU::Stop();
SPU::Stop();
SPU->Stop();

if (ConsoleType == 1)
DSi::Stop();
Expand Down Expand Up @@ -850,7 +845,7 @@ bool DoSavestate(Savestate* file)
if (ConsoleType == 0)
GBACart::DoSavestate(file);
GPU::DoSavestate(file);
SPU::DoSavestate(file);
SPU->DoSavestate(file);
SPI->DoSavestate(file);
RTC->DoSavestate(file);
Wifi::DoSavestate(file);
Expand All @@ -862,7 +857,7 @@ bool DoSavestate(Savestate* file)
{
GPU::SetPowerCnt(PowerControl9);

SPU::SetPowerCnt(PowerControl7 & 0x0001);
SPU->SetPowerCnt(PowerControl7 & 0x0001);
Wifi::SetPowerCnt(PowerControl7 & 0x0002);
}

Expand Down Expand Up @@ -1193,7 +1188,7 @@ u32 RunFrame()
ARM7Timestamp-SysTimestamp,
GPU3D::Timestamp-SysTimestamp);
#endif
SPU::TransferOutput();
SPU->TransferOutput();
break;
}

Expand Down Expand Up @@ -3922,7 +3917,7 @@ u8 ARM7IORead8(u32 addr)

if (addr >= 0x04000400 && addr < 0x04000520)
{
return SPU::Read8(addr);
return SPU->Read8(addr);
}

if ((addr & 0xFFFFF000) != 0x04004000)
Expand Down Expand Up @@ -4016,7 +4011,7 @@ u16 ARM7IORead16(u32 addr)

if (addr >= 0x04000400 && addr < 0x04000520)
{
return SPU::Read16(addr);
return SPU->Read16(addr);
}

if ((addr & 0xFFFFF000) != 0x04004000)
Expand Down Expand Up @@ -4117,7 +4112,7 @@ u32 ARM7IORead32(u32 addr)

if (addr >= 0x04000400 && addr < 0x04000520)
{
return SPU::Read32(addr);
return SPU->Read32(addr);
}

if ((addr & 0xFFFFF000) != 0x04004000)
Expand Down Expand Up @@ -4195,7 +4190,7 @@ void ARM7IOWrite8(u32 addr, u8 val)

if (addr >= 0x04000400 && addr < 0x04000520)
{
SPU::Write8(addr, val);
SPU->Write8(addr, val);
return;
}

Expand Down Expand Up @@ -4336,7 +4331,7 @@ void ARM7IOWrite16(u32 addr, u16 val)
{
u16 change = PowerControl7 ^ val;
PowerControl7 = val & 0x0003;
SPU::SetPowerCnt(val & 0x0001);
SPU->SetPowerCnt(val & 0x0001);
Wifi::SetPowerCnt(val & 0x0002);
if (change & 0x0002) UpdateWifiTimings();
}
Expand All @@ -4350,7 +4345,7 @@ void ARM7IOWrite16(u32 addr, u16 val)

if (addr >= 0x04000400 && addr < 0x04000520)
{
SPU::Write16(addr, val);
SPU->Write16(addr, val);
return;
}

Expand Down Expand Up @@ -4466,7 +4461,7 @@ void ARM7IOWrite32(u32 addr, u32 val)
{
u16 change = PowerControl7 ^ val;
PowerControl7 = val & 0x0003;
SPU::SetPowerCnt(val & 0x0001);
SPU->SetPowerCnt(val & 0x0001);
Wifi::SetPowerCnt(val & 0x0002);
if (change & 0x0002) UpdateWifiTimings();
}
Expand All @@ -4484,7 +4479,7 @@ void ARM7IOWrite32(u32 addr, u32 val)

if (addr >= 0x04000400 && addr < 0x04000520)
{
SPU::Write32(addr, val);
SPU->Write32(addr, val);
return;
}

Expand Down
4 changes: 3 additions & 1 deletion src/NDS.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
// with this enabled, to make sure it doesn't desync
//#define DEBUG_CHECK_DESYNC

class SPU;
class SPIHost;
class RTC;

Expand Down Expand Up @@ -249,7 +250,8 @@ extern MemRegion SWRAM_ARM7;
extern u32 KeyInput;
extern u16 RCnt;

extern SPIHost* SPI;
extern class SPU* SPU;
extern class SPIHost* SPI;
extern class RTC* RTC;

const u32 ARM7WRAMSize = 0x10000;
Expand Down
14 changes: 5 additions & 9 deletions src/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,11 @@ SPIHost::SPIHost()

Devices[SPIDevice_FirmwareMem] = new FirmwareMem(this);
Devices[SPIDevice_PowerMan] = new PowerMan(this);
Devices[SPIDevice_TSC] = nullptr;

if (NDS::ConsoleType == 1)
Devices[SPIDevice_TSC] = new DSi_TSC(this);
else
Devices[SPIDevice_TSC] = new TSC(this);
}

SPIHost::~SPIHost()
Expand All @@ -553,14 +557,6 @@ void SPIHost::Reset()
{
Cnt = 0;

if (Devices[SPIDevice_TSC])
delete Devices[SPIDevice_TSC];

if (NDS::ConsoleType == 1)
Devices[SPIDevice_TSC] = new DSi_TSC(this);
else
Devices[SPIDevice_TSC] = new TSC(this);

for (int i = 0; i < SPIDevice_MAX; i++)
{
Devices[i]->Reset();
Expand Down
Loading

0 comments on commit 76976fe

Please sign in to comment.