From 7e1c18414417e31240f0223aa7ed8e4247af8909 Mon Sep 17 00:00:00 2001 From: nitsuja Date: Sun, 11 Oct 2009 07:14:35 +0000 Subject: [PATCH] - fixed a bug in MatrixStackInit - fixed various other savestated variables not getting cleared on reset - fixed game staying frozen after loading a savestate after the game crashes - added emu.reset Lua function - removed a few unused values from savestates --- desmume/src/MMU.cpp | 15 +++++++++++++-- desmume/src/MMU.h | 4 ++-- desmume/src/NDSSystem.cpp | 17 +++++++++++++---- desmume/src/gfx3d.cpp | 22 ++++++++++++++++++++-- desmume/src/lua-engine.cpp | 10 ++++++++++ desmume/src/matrix.cpp | 2 +- desmume/src/saves.cpp | 14 ++++++++------ desmume/src/wifi.cpp | 8 ++++++++ 8 files changed, 75 insertions(+), 17 deletions(-) diff --git a/desmume/src/MMU.cpp b/desmume/src/MMU.cpp index cf4f4a0da..fcbe2c67d 100644 --- a/desmume/src/MMU.cpp +++ b/desmume/src/MMU.cpp @@ -891,8 +891,8 @@ void MMU_DeInit(void) { u32 rom_mask = 0; -u32 DMASrc[2][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}}; -u32 DMADst[2][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}}; +//u32 DMASrc[2][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}}; +//u32 DMADst[2][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}}; void MMU_Reset() { @@ -938,6 +938,17 @@ void MMU_Reset() memset(MMU.dscard, 0, sizeof(nds_dscard) * 2); + MMU.divRunning = 0; + MMU.divResult = 0; + MMU.divMod = 0; + MMU.divCnt = 0; + MMU.divCycles = 0; + + MMU.sqrtRunning = 0; + MMU.sqrtResult = 0; + MMU.sqrtCnt = 0; + MMU.sqrtCycles = 0; + MMU.SPI_CNT = 0; MMU.AUX_SPI_CNT = 0; diff --git a/desmume/src/MMU.h b/desmume/src/MMU.h index 5a59d41f1..6619c817b 100644 --- a/desmume/src/MMU.h +++ b/desmume/src/MMU.h @@ -353,8 +353,8 @@ struct MMU_struct memory_chip_t fw; nds_dscard dscard[2]; - u32 CheckTimers; - u32 CheckDMAs; + //u32 CheckTimers; + //u32 CheckDMAs; }; //this contains things which can't be memzeroed because they are smarter classes diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index cdd1d6a3f..686ae3b1d 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -533,9 +533,7 @@ int NDS_Init( void) { if (SPU_Init(SNDCORE_DUMMY, 740) != 0) return -1; -#ifdef EXPERIMENTAL_WIFI WIFI_Init() ; -#endif nds.FW_ARM9BootCode = NULL; nds.FW_ARM7BootCode = NULL; @@ -2392,6 +2390,8 @@ void execHardware_interrupts() } } +static void resetUserInput(); + bool _HACK_DONT_STOPMOVIE = false; void NDS_Reset() { @@ -2576,6 +2576,8 @@ void NDS_Reset() LidClosed = FALSE; countLid = 0; + resetUserInput(); + /* * Setup a copy of the firmware user settings in memory. * (this is what the DS firmware would do). @@ -2624,9 +2626,7 @@ void NDS_Reset() gpu3D->NDS_3D_Reset(); SPU_Reset(); -#ifdef EXPERIMENTAL_WIFI WIFI_Reset(); -#endif memcpy(FW_Mac, (MMU.fw.data + 0x36), 6); @@ -2725,6 +2725,10 @@ static bool loadUserInput(EMUFILE* is, UserInput& input, int version) read32le(&input.mic.micButtonPressed, is); return true; } +static void resetUserInput(UserInput& input) +{ + memset(&input, 0, sizeof(UserInput)); +} // (userinput is kind of a misnomer, e.g. finalUserInput has to mirror nds.pad, nds.touchX, etc.) static void saveUserInput(EMUFILE* os) { @@ -2744,6 +2748,11 @@ static bool loadUserInput(EMUFILE* is, int version) read32le((u32*)&TurboTime.array[i], is); return rv; } +static void resetUserInput() +{ + resetUserInput(finalUserInput); + resetUserInput(intermediateUserInput); +} static inline void gotInputRequest() { diff --git a/desmume/src/gfx3d.cpp b/desmume/src/gfx3d.cpp index 8afd3b686..2d1484e1e 100644 --- a/desmume/src/gfx3d.cpp +++ b/desmume/src/gfx3d.cpp @@ -342,7 +342,7 @@ static u8 MM3x3ind = 0; // Data for vertex submission static CACHE_ALIGN float coord[4] = {0.0, 0.0, 0.0, 0.0}; static char coordind = 0; -static u32 vtxFormat; +static u32 vtxFormat = 0; static BOOL inBegin = FALSE; // Data for basic transforms @@ -350,7 +350,7 @@ static CACHE_ALIGN float trans[4] = {0.0, 0.0, 0.0, 0.0}; static int transind = 0; static CACHE_ALIGN float scale[4] = {0.0, 0.0, 0.0, 0.0}; static int scaleind = 0; -static u32 viewport; +static u32 viewport = 0; //various other registers static float _t=0, _s=0; @@ -514,6 +514,24 @@ void gfx3d_reset() gfx3d.polylist = polylist; gfx3d.vertlist = vertlist; + polyAttr = 0; + textureFormat = 0; + texturePalette = 0; + polyAttrPending = 0; + mode = 0; + memset(coord, 0, sizeof(coord)); + coordind = 0; + vtxFormat = 0; + memset(trans, 0, sizeof(trans)); + transind = 0; + memset(scale, 0, sizeof(scale)); + scaleind = 0; + viewport = 0; + memset(gxPIPE.cmd, 0, sizeof(gxPIPE.cmd)); + memset(gxPIPE.param, 0, sizeof(gxPIPE.param)); + memset(colorRGB, 0, sizeof(colorRGB)); + memset(&tempVertInfo, 0, sizeof(tempVertInfo)); + MatrixInit (mtxCurrent[0]); MatrixInit (mtxCurrent[1]); MatrixInit (mtxCurrent[2]); diff --git a/desmume/src/lua-engine.cpp b/desmume/src/lua-engine.cpp index 7683a0338..f9701a676 100644 --- a/desmume/src/lua-engine.cpp +++ b/desmume/src/lua-engine.cpp @@ -3307,6 +3307,15 @@ DEFINE_LUA_FUNCTION(emu_openscript, "filename") return 0; } +DEFINE_LUA_FUNCTION(emu_reset, "") +{ + extern bool _HACK_DONT_STOPMOVIE; + _HACK_DONT_STOPMOVIE = true; + NDS_Reset(); + _HACK_DONT_STOPMOVIE = false; + return 0; +} + // TODO /* DEFINE_LUA_FUNCTION(emu_loadrom, "filename") @@ -4051,6 +4060,7 @@ static const struct luaL_reg emulib [] = {"print", print}, // sure, why not {"openscript", emu_openscript}, // {"loadrom", emu_loadrom}, + {"reset", emu_reset}, // alternative names // {"openrom", emu_loadrom}, {NULL, NULL} diff --git a/desmume/src/matrix.cpp b/desmume/src/matrix.cpp index 7491c6ab1..02ff5ff4f 100644 --- a/desmume/src/matrix.cpp +++ b/desmume/src/matrix.cpp @@ -185,7 +185,7 @@ void MatrixStackInit(MatrixStack *stack) { for (int i = 0; i < stack->size; i++) { - MatrixInit(&stack->matrix[i]); + MatrixInit(&stack->matrix[i*16]); } stack->position = 0; } diff --git a/desmume/src/saves.cpp b/desmume/src/saves.cpp index daa253646..6651e5898 100644 --- a/desmume/src/saves.cpp +++ b/desmume/src/saves.cpp @@ -178,8 +178,8 @@ SFORMAT SF_NDS[]={ { 0 } }; -extern u32 DMASrc[2][4]; -extern u32 DMADst[2][4]; +//extern u32 DMASrc[2][4]; +//extern u32 DMADst[2][4]; SFORMAT SF_MMU[]={ { "M7BI", 1, sizeof(MMU.ARM7_BIOS), MMU.ARM7_BIOS}, @@ -212,8 +212,8 @@ SFORMAT SF_MMU[]={ { "MDCR", 4, 8, MMU.DMACrt}, { "MDMA", 4, 8, MMU.DMAing}, { "MDMC", 4, 8, MMU.DMACompleted}, - { "MDSR", 4, 8, DMASrc}, - { "MDDS", 4, 8, DMADst}, + //{ "MDSR", 4, 8, DMASrc}, + //{ "MDDS", 4, 8, DMADst}, { "MDV1", 4, 1, &MMU.divRunning}, { "MDV2", 8, 1, &MMU.divResult}, @@ -239,8 +239,8 @@ SFORMAT SF_MMU[]={ { "MC0T", 4, 1, &MMU.dscard[0].transfer_count}, { "MC1A", 4, 1, &MMU.dscard[1].address}, { "MC1T", 4, 1, &MMU.dscard[1].transfer_count}, - { "MCHT", 4, 1, &MMU.CheckTimers}, - { "MCHD", 4, 1, &MMU.CheckDMAs}, + //{ "MCHT", 4, 1, &MMU.CheckTimers}, + //{ "MCHD", 4, 1, &MMU.CheckDMAs}, //fifos { "F0TH", 1, 1, &ipc_fifo[0].head}, @@ -1113,6 +1113,8 @@ static void loadstate() // no need to restore 0x60 since control and MMU.ARM9_REG are both in the savestates, and restoring it could mess up the ack bits anyway SetupMMU(nds.debugConsole); + + execute = !driver->EMU_IsEmulationPaused(); } bool savestate_load(EMUFILE* is) diff --git a/desmume/src/wifi.cpp b/desmume/src/wifi.cpp index 5dcd19464..ff289f354 100644 --- a/desmume/src/wifi.cpp +++ b/desmume/src/wifi.cpp @@ -673,10 +673,12 @@ bool WIFI_Init() WIFI_resetRF(&wifiMac.RF) ; wifi_netEnabled = false; +#ifdef EXPERIMENTAL_WIFI if(driver->WIFI_Host_InitSystem()) { wifi_netEnabled = true; } +#endif wifiMac.powerOn = FALSE; wifiMac.powerOnPending = FALSE; @@ -684,7 +686,9 @@ bool WIFI_Init() wifiMac.rfPins = 0x0004; wifiCom = wifiComs[CommonSettings.wifi.mode]; +#ifdef EXPERIMENTAL_WIFI wifiCom->Init(); +#endif return true; } @@ -700,10 +704,12 @@ void WIFI_Reset() WIFI_resetRF(&wifiMac.RF) ; wifi_netEnabled = false; +#ifdef EXPERIMENTAL_WIFI if(driver->WIFI_Host_InitSystem()) { wifi_netEnabled = true; } +#endif wifiMac.powerOn = FALSE; wifiMac.powerOnPending = FALSE; @@ -711,7 +717,9 @@ void WIFI_Reset() wifiMac.rfPins = 0x0004; wifiCom = wifiComs[CommonSettings.wifi.mode]; +#ifdef EXPERIMENTAL_WIFI wifiCom->Reset(); +#endif }