Custom path support (#1333)

also including:
* getting rid of shitty strings
* all new, cleaner ROM handling code
* base for DSi savestates
* GBA slot addons (for now, memory cart)
This commit is contained in:
Arisotura
2022-01-07 14:00:43 +01:00
committed by GitHub
parent c4cd9da674
commit e665e25bd3
64 changed files with 3606 additions and 2662 deletions

View File

@ -32,7 +32,6 @@
#include "Wifi.h"
#include "AREngine.h"
#include "Platform.h"
#include "NDSCart_SRAMManager.h"
#include "FreeBIOS.h"
#ifdef JIT_ENABLED
@ -42,6 +41,9 @@
#include "DSi.h"
#include "DSi_SPI_TSC.h"
#include "DSi_NWifi.h"
#include "DSi_Camera.h"
#include "DSi_DSP.h"
namespace NDS
@ -200,7 +202,6 @@ bool Init()
DMAs[6] = new DMA(1, 2);
DMAs[7] = new DMA(1, 3);
if (!NDSCart_SRAMManager::Init()) return false;
if (!NDSCart::Init()) return false;
if (!GBACart::Init()) return false;
if (!GPU::Init()) return false;
@ -228,7 +229,6 @@ void DeInit()
for (int i = 0; i < 8; i++)
delete DMAs[i];
NDSCart_SRAMManager::DeInit();
NDSCart::DeInit();
GBACart::DeInit();
GPU::DeInit();
@ -353,7 +353,28 @@ void InitTimings()
// handled later: GBA slot, wifi
}
void SetupDirectBoot()
bool NeedsDirectBoot()
{
if (ConsoleType == 1)
{
// for now, DSi mode requires original BIOS/NAND
return false;
}
else
{
// internal BIOS does not support direct boot
if (!Platform::GetConfigBool(Platform::ExternalBIOSEnable))
return true;
// DSi/3DS firmwares aren't bootable
if (SPI_Firmware::GetFirmwareLength() == 0x20000)
return true;
return false;
}
}
void SetupDirectBoot(std::string romname)
{
if (ConsoleType == 1)
{
@ -444,6 +465,8 @@ void SetupDirectBoot()
ARM9->CP15Write(0x911, 0x00000020);
}
NDSCart::SetupDirectBoot(romname);
ARM9->R[12] = NDSCart::Header.ARM9EntryAddress;
ARM9->R[13] = 0x03002F7C;
ARM9->R[14] = NDSCart::Header.ARM9EntryAddress;
@ -542,7 +565,6 @@ void Reset()
if (ConsoleType == 1)
{
DSi::LoadBIOS();
DSi::LoadNAND();
ARM9ClockShift = 2;
MainRAMMask = 0xFFFFFF;
@ -658,6 +680,11 @@ void Reset()
AREngine::Reset();
}
void Start()
{
Running = true;
}
void Stop()
{
printf("Stopping: shutdown\n");
@ -692,7 +719,14 @@ bool DoSavestate_Scheduler(Savestate* file)
DivDone,
SqrtDone,
NULL
DSi_SDHost::FinishRX,
DSi_SDHost::FinishTX,
DSi_NWifi::MSTimer,
DSi_Camera::IRQ,
DSi_Camera::Transfer,
DSi_DSP::DSPCatchUpU32,
nullptr
};
int len = Event_MAX;
@ -702,7 +736,7 @@ bool DoSavestate_Scheduler(Savestate* file)
{
SchedEvent* evt = &SchedList[i];
u32 funcid = -1;
u32 funcid = 0xFFFFFFFF;
if (evt->Func)
{
for (int j = 0; eventfuncs[j]; j++)
@ -749,7 +783,7 @@ bool DoSavestate_Scheduler(Savestate* file)
evt->Func = eventfuncs[funcid];
}
else
evt->Func = NULL;
evt->Func = nullptr;
file->Var64(&evt->Timestamp);
file->Var32(&evt->Param);
@ -763,15 +797,26 @@ bool DoSavestate(Savestate* file)
{
file->Section("NDSG");
// TODO:
// * do something for bool's (sizeof=1)
// * do something for 'loading DSi-mode savestate in DS mode' and vice-versa
// * add IE2/IF2 there
if (file->Saving)
{
u32 console = ConsoleType;
file->Var32(&console);
}
else
{
u32 console;
file->Var32(&console);
if (console != ConsoleType)
return false;
}
file->VarArray(MainRAM, 0x400000);
file->VarArray(SharedWRAM, 0x8000);
file->VarArray(MainRAM, MainRAMMaxSize);
file->VarArray(SharedWRAM, SharedWRAMSize);
file->VarArray(ARM7WRAM, ARM7WRAMSize);
//file->VarArray(ARM9BIOS, 0x1000);
//file->VarArray(ARM7BIOS, 0x4000);
file->VarArray(ExMemCnt, 2*sizeof(u16));
file->VarArray(ROMSeed0, 2*8);
file->VarArray(ROMSeed1, 2*8);
@ -781,6 +826,8 @@ bool DoSavestate(Savestate* file)
file->VarArray(IME, 2*sizeof(u32));
file->VarArray(IE, 2*sizeof(u32));
file->VarArray(IF, 2*sizeof(u32));
file->Var32(&IE2);
file->Var32(&IF2);
file->Var8(&PostFlag9);
file->Var8(&PostFlag7);
@ -825,11 +872,8 @@ bool DoSavestate(Savestate* file)
file->Var64(&LastSysClockCycles);
file->Var64(&FrameStartTimestamp);
file->Var32(&NumFrames);
if (file->IsAtleastVersion(7, 1))
{
file->Var32(&NumLagFrames);
file->Bool32(&LagFrameFlag);
}
file->Var32(&NumLagFrames);
file->Bool32(&LagFrameFlag);
// TODO: save KeyInput????
file->Var16(&KeyCnt);
@ -860,13 +904,17 @@ bool DoSavestate(Savestate* file)
ARM7->DoSavestate(file);
NDSCart::DoSavestate(file);
GBACart::DoSavestate(file);
if (ConsoleType == 0)
GBACart::DoSavestate(file);
GPU::DoSavestate(file);
SPU::DoSavestate(file);
SPI::DoSavestate(file);
RTC::DoSavestate(file);
Wifi::DoSavestate(file);
if (ConsoleType == 1)
DSi::DoSavestate(file);
if (!file->Saving)
{
GPU::SetPowerCnt(PowerControl9);
@ -888,73 +936,59 @@ void SetConsoleType(int type)
ConsoleType = type;
}
bool LoadROM(const u8* romdata, u32 filelength, const char *sram, bool direct)
bool LoadCart(const u8* romdata, u32 romlen, const u8* savedata, u32 savelen)
{
if (NDSCart::LoadROM(romdata, filelength, sram, direct))
{
Running = true;
return true;
}
else
{
printf("Failed to load ROM from archive\n");
if (!NDSCart::LoadROM(romdata, romlen))
return false;
}
if (savedata && savelen)
NDSCart::LoadSave(savedata, savelen);
return true;
}
bool LoadROM(const char* path, const char* sram, bool direct)
void LoadSave(const u8* savedata, u32 savelen)
{
if (NDSCart::LoadROM(path, sram, direct))
{
Running = true;
return true;
}
else
{
printf("Failed to load ROM %s\n", path);
return false;
}
if (savedata && savelen)
NDSCart::LoadSave(savedata, savelen);
}
bool LoadGBAROM(const char* path, const char* sram)
void EjectCart()
{
if (GBACart::LoadROM(path, sram))
{
return true;
}
else
{
printf("Failed to load ROM %s\n", path);
return false;
}
NDSCart::EjectCart();
}
bool LoadGBAROM(const u8* romdata, u32 filelength, const char *filename, const char *sram)
bool CartInserted()
{
if (GBACart::LoadROM(romdata, filelength, sram))
{
return true;
}
else
{
printf("Failed to load ROM %s from archive\n", filename);
return NDSCart::CartInserted;
}
bool LoadGBACart(const u8* romdata, u32 romlen, const u8* savedata, u32 savelen)
{
if (!GBACart::LoadROM(romdata, romlen))
return false;
}
if (savedata && savelen)
GBACart::LoadSave(savedata, savelen);
return true;
}
void LoadGBAAddon(int type)
{
GBACart::LoadAddon(type);
}
void EjectGBACart()
{
GBACart::EjectCart();
}
void LoadBIOS()
{
Reset();
Running = true;
}
void RelocateSave(const char* path, bool write)
{
printf("SRAM: relocating to %s (write=%s)\n", path, write?"true":"false");
NDSCart::RelocateSave(path, write);
}
u64 NextTarget()
{
@ -1094,8 +1128,6 @@ u32 RunFrame()
GPU3D::Timestamp-SysTimestamp);
#endif
SPU::TransferOutput();
NDSCart::FlushSRAMFile();
}
// In the context of TASes, frame count is traditionally the primary measure of emulated time,
@ -1234,10 +1266,10 @@ void MicInputFrame(s16* data, int samples)
return SPI_TSC::MicInputFrame(data, samples);
}
int ImportSRAM(u8* data, u32 length)
/*int ImportSRAM(u8* data, u32 length)
{
return NDSCart::ImportSRAM(data, length);
}
}*/
void Halt()