- 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
This commit is contained in:
nitsuja 2009-10-11 07:14:35 +00:00
parent 1a7bb26c39
commit 7e1c184144
8 changed files with 75 additions and 17 deletions

View File

@ -891,8 +891,8 @@ void MMU_DeInit(void) {
u32 rom_mask = 0; u32 rom_mask = 0;
u32 DMASrc[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}}; //u32 DMADst[2][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}};
void MMU_Reset() void MMU_Reset()
{ {
@ -938,6 +938,17 @@ void MMU_Reset()
memset(MMU.dscard, 0, sizeof(nds_dscard) * 2); 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.SPI_CNT = 0;
MMU.AUX_SPI_CNT = 0; MMU.AUX_SPI_CNT = 0;

View File

@ -353,8 +353,8 @@ struct MMU_struct
memory_chip_t fw; memory_chip_t fw;
nds_dscard dscard[2]; nds_dscard dscard[2];
u32 CheckTimers; //u32 CheckTimers;
u32 CheckDMAs; //u32 CheckDMAs;
}; };
//this contains things which can't be memzeroed because they are smarter classes //this contains things which can't be memzeroed because they are smarter classes

View File

@ -533,9 +533,7 @@ int NDS_Init( void) {
if (SPU_Init(SNDCORE_DUMMY, 740) != 0) if (SPU_Init(SNDCORE_DUMMY, 740) != 0)
return -1; return -1;
#ifdef EXPERIMENTAL_WIFI
WIFI_Init() ; WIFI_Init() ;
#endif
nds.FW_ARM9BootCode = NULL; nds.FW_ARM9BootCode = NULL;
nds.FW_ARM7BootCode = NULL; nds.FW_ARM7BootCode = NULL;
@ -2392,6 +2390,8 @@ void execHardware_interrupts()
} }
} }
static void resetUserInput();
bool _HACK_DONT_STOPMOVIE = false; bool _HACK_DONT_STOPMOVIE = false;
void NDS_Reset() void NDS_Reset()
{ {
@ -2576,6 +2576,8 @@ void NDS_Reset()
LidClosed = FALSE; LidClosed = FALSE;
countLid = 0; countLid = 0;
resetUserInput();
/* /*
* Setup a copy of the firmware user settings in memory. * Setup a copy of the firmware user settings in memory.
* (this is what the DS firmware would do). * (this is what the DS firmware would do).
@ -2624,9 +2626,7 @@ void NDS_Reset()
gpu3D->NDS_3D_Reset(); gpu3D->NDS_3D_Reset();
SPU_Reset(); SPU_Reset();
#ifdef EXPERIMENTAL_WIFI
WIFI_Reset(); WIFI_Reset();
#endif
memcpy(FW_Mac, (MMU.fw.data + 0x36), 6); 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); read32le(&input.mic.micButtonPressed, is);
return true; 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.) // (userinput is kind of a misnomer, e.g. finalUserInput has to mirror nds.pad, nds.touchX, etc.)
static void saveUserInput(EMUFILE* os) static void saveUserInput(EMUFILE* os)
{ {
@ -2744,6 +2748,11 @@ static bool loadUserInput(EMUFILE* is, int version)
read32le((u32*)&TurboTime.array[i], is); read32le((u32*)&TurboTime.array[i], is);
return rv; return rv;
} }
static void resetUserInput()
{
resetUserInput(finalUserInput);
resetUserInput(intermediateUserInput);
}
static inline void gotInputRequest() static inline void gotInputRequest()
{ {

View File

@ -342,7 +342,7 @@ static u8 MM3x3ind = 0;
// Data for vertex submission // Data for vertex submission
static CACHE_ALIGN float coord[4] = {0.0, 0.0, 0.0, 0.0}; static CACHE_ALIGN float coord[4] = {0.0, 0.0, 0.0, 0.0};
static char coordind = 0; static char coordind = 0;
static u32 vtxFormat; static u32 vtxFormat = 0;
static BOOL inBegin = FALSE; static BOOL inBegin = FALSE;
// Data for basic transforms // 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 int transind = 0;
static CACHE_ALIGN float scale[4] = {0.0, 0.0, 0.0, 0.0}; static CACHE_ALIGN float scale[4] = {0.0, 0.0, 0.0, 0.0};
static int scaleind = 0; static int scaleind = 0;
static u32 viewport; static u32 viewport = 0;
//various other registers //various other registers
static float _t=0, _s=0; static float _t=0, _s=0;
@ -514,6 +514,24 @@ void gfx3d_reset()
gfx3d.polylist = polylist; gfx3d.polylist = polylist;
gfx3d.vertlist = vertlist; 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[0]);
MatrixInit (mtxCurrent[1]); MatrixInit (mtxCurrent[1]);
MatrixInit (mtxCurrent[2]); MatrixInit (mtxCurrent[2]);

View File

@ -3307,6 +3307,15 @@ DEFINE_LUA_FUNCTION(emu_openscript, "filename")
return 0; 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 // TODO
/* /*
DEFINE_LUA_FUNCTION(emu_loadrom, "filename") DEFINE_LUA_FUNCTION(emu_loadrom, "filename")
@ -4051,6 +4060,7 @@ static const struct luaL_reg emulib [] =
{"print", print}, // sure, why not {"print", print}, // sure, why not
{"openscript", emu_openscript}, {"openscript", emu_openscript},
// {"loadrom", emu_loadrom}, // {"loadrom", emu_loadrom},
{"reset", emu_reset},
// alternative names // alternative names
// {"openrom", emu_loadrom}, // {"openrom", emu_loadrom},
{NULL, NULL} {NULL, NULL}

View File

@ -185,7 +185,7 @@ void MatrixStackInit(MatrixStack *stack)
{ {
for (int i = 0; i < stack->size; i++) for (int i = 0; i < stack->size; i++)
{ {
MatrixInit(&stack->matrix[i]); MatrixInit(&stack->matrix[i*16]);
} }
stack->position = 0; stack->position = 0;
} }

View File

@ -178,8 +178,8 @@ SFORMAT SF_NDS[]={
{ 0 } { 0 }
}; };
extern u32 DMASrc[2][4]; //extern u32 DMASrc[2][4];
extern u32 DMADst[2][4]; //extern u32 DMADst[2][4];
SFORMAT SF_MMU[]={ SFORMAT SF_MMU[]={
{ "M7BI", 1, sizeof(MMU.ARM7_BIOS), MMU.ARM7_BIOS}, { "M7BI", 1, sizeof(MMU.ARM7_BIOS), MMU.ARM7_BIOS},
@ -212,8 +212,8 @@ SFORMAT SF_MMU[]={
{ "MDCR", 4, 8, MMU.DMACrt}, { "MDCR", 4, 8, MMU.DMACrt},
{ "MDMA", 4, 8, MMU.DMAing}, { "MDMA", 4, 8, MMU.DMAing},
{ "MDMC", 4, 8, MMU.DMACompleted}, { "MDMC", 4, 8, MMU.DMACompleted},
{ "MDSR", 4, 8, DMASrc}, //{ "MDSR", 4, 8, DMASrc},
{ "MDDS", 4, 8, DMADst}, //{ "MDDS", 4, 8, DMADst},
{ "MDV1", 4, 1, &MMU.divRunning}, { "MDV1", 4, 1, &MMU.divRunning},
{ "MDV2", 8, 1, &MMU.divResult}, { "MDV2", 8, 1, &MMU.divResult},
@ -239,8 +239,8 @@ SFORMAT SF_MMU[]={
{ "MC0T", 4, 1, &MMU.dscard[0].transfer_count}, { "MC0T", 4, 1, &MMU.dscard[0].transfer_count},
{ "MC1A", 4, 1, &MMU.dscard[1].address}, { "MC1A", 4, 1, &MMU.dscard[1].address},
{ "MC1T", 4, 1, &MMU.dscard[1].transfer_count}, { "MC1T", 4, 1, &MMU.dscard[1].transfer_count},
{ "MCHT", 4, 1, &MMU.CheckTimers}, //{ "MCHT", 4, 1, &MMU.CheckTimers},
{ "MCHD", 4, 1, &MMU.CheckDMAs}, //{ "MCHD", 4, 1, &MMU.CheckDMAs},
//fifos //fifos
{ "F0TH", 1, 1, &ipc_fifo[0].head}, { "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 // 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); SetupMMU(nds.debugConsole);
execute = !driver->EMU_IsEmulationPaused();
} }
bool savestate_load(EMUFILE* is) bool savestate_load(EMUFILE* is)

View File

@ -673,10 +673,12 @@ bool WIFI_Init()
WIFI_resetRF(&wifiMac.RF) ; WIFI_resetRF(&wifiMac.RF) ;
wifi_netEnabled = false; wifi_netEnabled = false;
#ifdef EXPERIMENTAL_WIFI
if(driver->WIFI_Host_InitSystem()) if(driver->WIFI_Host_InitSystem())
{ {
wifi_netEnabled = true; wifi_netEnabled = true;
} }
#endif
wifiMac.powerOn = FALSE; wifiMac.powerOn = FALSE;
wifiMac.powerOnPending = FALSE; wifiMac.powerOnPending = FALSE;
@ -684,7 +686,9 @@ bool WIFI_Init()
wifiMac.rfPins = 0x0004; wifiMac.rfPins = 0x0004;
wifiCom = wifiComs[CommonSettings.wifi.mode]; wifiCom = wifiComs[CommonSettings.wifi.mode];
#ifdef EXPERIMENTAL_WIFI
wifiCom->Init(); wifiCom->Init();
#endif
return true; return true;
} }
@ -700,10 +704,12 @@ void WIFI_Reset()
WIFI_resetRF(&wifiMac.RF) ; WIFI_resetRF(&wifiMac.RF) ;
wifi_netEnabled = false; wifi_netEnabled = false;
#ifdef EXPERIMENTAL_WIFI
if(driver->WIFI_Host_InitSystem()) if(driver->WIFI_Host_InitSystem())
{ {
wifi_netEnabled = true; wifi_netEnabled = true;
} }
#endif
wifiMac.powerOn = FALSE; wifiMac.powerOn = FALSE;
wifiMac.powerOnPending = FALSE; wifiMac.powerOnPending = FALSE;
@ -711,7 +717,9 @@ void WIFI_Reset()
wifiMac.rfPins = 0x0004; wifiMac.rfPins = 0x0004;
wifiCom = wifiComs[CommonSettings.wifi.mode]; wifiCom = wifiComs[CommonSettings.wifi.mode];
#ifdef EXPERIMENTAL_WIFI
wifiCom->Reset(); wifiCom->Reset();
#endif
} }