From 95f0e30dcbf6390535c19951bcfac6e1cb0d348d Mon Sep 17 00:00:00 2001 From: Arisotura Date: Fri, 7 Jan 2022 11:08:47 +0100 Subject: [PATCH] more savestate crapo --- src/DSi.cpp | 4 ++++ src/DSi_AES.cpp | 10 +++++----- src/DSi_Camera.cpp | 39 ++++++++++++++++++++++++++++++++++++++- src/DSi_Camera.h | 4 ++++ src/DSi_DSP.cpp | 2 ++ src/DSi_DSP.h | 2 -- src/DSi_I2C.cpp | 20 ++++++++++++++++++++ src/DSi_I2C.h | 2 +- 8 files changed, 74 insertions(+), 9 deletions(-) diff --git a/src/DSi.cpp b/src/DSi.cpp index ca02cc09..889d518a 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -82,6 +82,7 @@ u8 eMMC_CID[16]; void Set_SCFG_Clock9(u16 val); +void Set_SCFG_MC(u32 val); bool Init() @@ -240,6 +241,9 @@ void DoSavestate(Savestate* file) NDMAs[i]->DoSavestate(file); DSi_AES::DoSavestate(file); + DSi_Camera::DoSavestate(file); + DSi_DSP::DoSavestate(file); + DSi_I2C::DoSavestate(file); } void DecryptModcryptArea(u32 offset, u32 size, u8* iv) diff --git a/src/DSi_AES.cpp b/src/DSi_AES.cpp index fa21e6d2..ec7b0e6c 100644 --- a/src/DSi_AES.cpp +++ b/src/DSi_AES.cpp @@ -157,7 +157,7 @@ void Reset() void DoSavestate(Savestate* file) { - file->Section("AES."); + file->Section("AESi"); file->Var32(&Cnt); @@ -171,8 +171,8 @@ void DoSavestate(Savestate* file) file->Var32(&OutputDMASize); file->Var32(&AESMode); - InputFIFO->DoSavestate(file); - OutputFIFO->DoSavestate(file); + InputFIFO.DoSavestate(file); + OutputFIFO.DoSavestate(file); file->VarArray(IV, 16); @@ -188,8 +188,8 @@ void DoSavestate(Savestate* file) file->VarArray(OutputMAC, 16); file->Bool32(&OutputMACDue); - file->VarArray(Ctx->RoundKey, AES_keyExpSize); - file->VarArray(Ctx->Iv, AES_BLOCKLEN); + file->VarArray(Ctx.RoundKey, AES_keyExpSize); + file->VarArray(Ctx.Iv, AES_BLOCKLEN); } diff --git a/src/DSi_Camera.cpp b/src/DSi_Camera.cpp index d8cc3350..10acdcae 100644 --- a/src/DSi_Camera.cpp +++ b/src/DSi_Camera.cpp @@ -70,6 +70,21 @@ void DSi_Camera::Reset() NDS::ScheduleEvent(NDS::Event_DSi_CamIRQ, true, kIRQInterval, IRQ, 0); } +void DSi_Camera::DoSavestate(Savestate* file) +{ + file->Section("CAMi"); + + file->Var16(&ModuleCnt); + file->Var16(&Cnt); + + file->VarArray(FrameBuffer, sizeof(FrameBuffer)); + file->Var32(&TransferPos); + file->Var32(&FrameLength); + + DSi_Camera0->DoCamSavestate(file); + DSi_Camera1->DoCamSavestate(file); +} + void DSi_Camera::IRQ(u32 param) { @@ -150,7 +165,29 @@ DSi_Camera::DSi_Camera(u32 num) DSi_Camera::~DSi_Camera() { - // +} + +void DSi_Camera::DoCamSavestate(Savestate* file) +{ + char magic[5] = "CAMx"; + magic[3] = '0' + Num; + file->Section(magic); + + file->Var32(&DataPos); + file->Var32(&RegAddr); + file->Var16(&RegData); + + file->Var16(&PLLDiv); + file->Var16(&PLLPDiv); + file->Var16(&PLLCnt); + file->Var16(&ClocksCnt); + file->Var16(&StandbyCnt); + file->Var16(&MiscCnt); + + file->Var16(&MCUAddr); + // TODO: MCUData?? + + file->VarArray(MCURegs, 0x8000); } void DSi_Camera::ResetCam() diff --git a/src/DSi_Camera.h b/src/DSi_Camera.h index 3f39e3a5..5dc037d2 100644 --- a/src/DSi_Camera.h +++ b/src/DSi_Camera.h @@ -28,6 +28,8 @@ public: static void DeInit(); static void Reset(); + static void DoSavestate(Savestate* file); + static void IRQ(u32 param); static void RequestFrame(u32 cam); @@ -36,6 +38,8 @@ public: DSi_Camera(u32 num); ~DSi_Camera(); + void DoCamSavestate(Savestate* file); + void ResetCam(); bool IsActivated(); diff --git a/src/DSi_DSP.cpp b/src/DSi_DSP.cpp index 328f01d8..c889aff9 100644 --- a/src/DSi_DSP.cpp +++ b/src/DSi_DSP.cpp @@ -587,6 +587,8 @@ void DoSavestate(Savestate* file) file->Var16(&DSP_REP[1]); file->Var16(&DSP_REP[2]); file->Var8((u8*)&SCFG_RST); + + // TODO: save the Teakra state!!! } } diff --git a/src/DSi_DSP.h b/src/DSi_DSP.h index 9f284874..ade88bac 100644 --- a/src/DSi_DSP.h +++ b/src/DSi_DSP.h @@ -41,8 +41,6 @@ bool Init(); void DeInit(); void Reset(); -// TODO: needs to be called! -// however, no DSi savestate stuff seems to be actually implemented?! void DoSavestate(Savestate* file); void DSPCatchUpU32(u32 _); diff --git a/src/DSi_I2C.cpp b/src/DSi_I2C.cpp index 6f5f2e58..9e865b12 100644 --- a/src/DSi_I2C.cpp +++ b/src/DSi_I2C.cpp @@ -72,6 +72,14 @@ void Reset() Registers[0x81] = 0x64; } +void DoSavestate(Savestate* file) +{ + file->Section("I2BP"); + + file->VarArray(Registers, 0x100); + file->Var32(&CurPos); +} + u8 GetBootFlag() { return Registers[0x70]; } void Start() @@ -169,6 +177,18 @@ void Reset() DSi_Camera::Reset(); } +void DoSavestate(Savestate* file) +{ + file->Section("I2Ci"); + + file->Var8(&Cnt); + file->Var8(&Data); + file->Var32(&Device); + + DSi_BPTWL::DoSavestate(file); + // cameras are savestated from the DSi_Camera module +} + void WriteCnt(u8 val) { //printf("I2C: write CNT %02X, %08X\n", val, NDS::GetPC(1)); diff --git a/src/DSi_I2C.h b/src/DSi_I2C.h index c0643667..55313999 100644 --- a/src/DSi_I2C.h +++ b/src/DSi_I2C.h @@ -34,7 +34,7 @@ extern u8 Cnt; bool Init(); void DeInit(); void Reset(); -//void DoSavestate(Savestate* file); +void DoSavestate(Savestate* file); void WriteCnt(u8 val);