fix code that would have fucking asploded

This commit is contained in:
StapleButter 2018-10-18 01:38:33 +02:00
parent f4cf54829e
commit 148f4032f1
6 changed files with 110 additions and 4 deletions

View File

@ -156,6 +156,11 @@ void Stop()
memset(Framebuffer, 0, 256*192*2*4);
}
void DoSavestate(Savestate* file)
{
//
}
// VRAM mapping notes
//

View File

@ -72,6 +72,9 @@ void DeInit();
void Reset();
void Stop();
void DoSavestate(Savestate* file);
void MapVRAM_AB(u32 bank, u8 cnt);
void MapVRAM_CD(u32 bank, u8 cnt);
void MapVRAM_E(u32 bank, u8 cnt);
@ -389,6 +392,9 @@ void DisplaySwap(u32 val);
void StartFrame();
void FinishFrame(u32 lines);
void StartScanline(u32 line);
void StartHBlank(u32 line);
void DisplayFIFO(u32 x);
void SetDispStat(u32 cpu, u16 val);

View File

@ -112,6 +112,10 @@ u16 RCnt;
bool Running;
void DivDone(u32 param);
void SqrtDone(u32 param);
bool Init()
{
ARM9 = new ARM(0);
@ -356,7 +360,91 @@ void Stop()
SPU::Stop();
}
void DoSavestate(Savestate* file)
bool DoSavestate_Scheduler(Savestate* file)
{
// this is a bit of a hack
// but uh, your local coder realized that the scheduler list contains function pointers
// and that storing those as-is is not a very good idea
// unless you want it to crash and burn
// this is the solution your local coder came up with.
// it's gross but I think it's the best solution for this problem.
// just remember to add here if you add more event callbacks, kay?
// atleast until we come up with something more elegant.
void (*eventfuncs[])(u32) =
{
GPU::StartScanline, GPU::StartHBlank, GPU::FinishFrame,
SPU::Mix,
Wifi::USTimer,
GPU::DisplayFIFO,
NDSCart::ROMPrepareData, NDSCart::ROMEndTransfer,
NDSCart::SPITransferDone,
SPI::TransferDone,
DivDone,
SqrtDone,
NULL
};
int len = Event_MAX;
if (file->Saving)
{
for (int i = 0; i < len; i++)
{
SchedEvent* evt = &SchedList[i];
u32 funcid = -1;
for (int j = 0; eventfuncs[j]; j++)
{
if (evt->Func == eventfuncs[j])
{
funcid = j;
break;
}
}
if (funcid < 0)
{
printf("savestate: VERY BAD!!!!! FUNCTION POINTER FOR EVENT %d NOT IN HACKY LIST. CANNOT SAVE. SMACK STAPLEBUTTER.\n", i);
return false;
}
file->Var32(&funcid);
file->Var32((u32*)&evt->WaitCycles);
file->Var32(&evt->Param);
}
}
else
{
for (int i = 0; i < len; i++)
{
SchedEvent* evt = &SchedList[i];
u32 funcid;
file->Var32(&funcid);
for (int j = 0; ; j++)
{
if (!eventfuncs[j])
{
printf("savestate: VERY BAD!!!!!! EVENT FUNCTION POINTER ID %d IS OUT OF RANGE. HAX?????\n", j);
return false;
}
if (j == funcid) break;
}
evt->Func = eventfuncs[funcid];
file->Var32((u32*)&evt->WaitCycles);
file->Var32(&evt->Param);
}
}
return true;
}
bool DoSavestate(Savestate* file)
{
file->Section("NDSG");
@ -399,7 +487,8 @@ void DoSavestate(Savestate* file)
file->VarArray(DMA9Fill, 4*sizeof(u32));
file->VarArray(SchedList, sizeof(SchedList));
//file->VarArray(SchedList, sizeof(SchedList));
if (!DoSavestate_Scheduler(file)) return false;
file->Var32(&SchedListMask);
file->Var32((u32*)&CurIterationCycles);
file->Var32((u32*)&ARM7Offset);
@ -420,7 +509,7 @@ void DoSavestate(Savestate* file)
ARM7->DoSavestate(file);
CP15::DoSavestate(file);
// NDSCart
NDSCart::DoSavestate(file);
// GPU
// SPU
// SPI

View File

@ -109,7 +109,7 @@ void DeInit();
void Reset();
void Stop();
void DoSavestate(Savestate* file);
bool DoSavestate(Savestate* file);
bool LoadROM(const char* path, bool direct);
void LoadBIOS();

View File

@ -53,6 +53,10 @@ void WriteSPICnt(u16 val);
u8 ReadSPIData();
void WriteSPIData(u8 val);
void ROMPrepareData(u32 param);
void ROMEndTransfer(u32 param);
void SPITransferDone(u32 param);
}
#endif

View File

@ -52,6 +52,8 @@ void WriteCnt(u16 val);
u8 ReadData();
void WriteData(u8 val);
void TransferDone(u32 param);
}
#endif