- add checks savestate ROM header data with loaded ROM header;

This commit is contained in:
mtabachenko 2013-05-13 08:08:19 +00:00
parent 997be2f2a2
commit 42b51f4e45
3 changed files with 74 additions and 46 deletions

View File

@ -399,7 +399,7 @@ void CHEATS::ARparser(CHEATS_LIST& list)
_MMU_write08<ARMCPU_ARM9,MMU_AT_DEBUG>(hi+t, tmp);
}
break;
default: PROGINFO("AR: ERROR uknown command 0x%2X at %08X:%08X\n", type, hi, lo); break;
default: PROGINFO("AR: ERROR unknown command 0x%2X at %08X:%08X\n", type, hi, lo); break;
}
}
}

View File

@ -278,39 +278,6 @@ SFORMAT SF_MOVIE[]={
{ 0 }
};
static void mmu_savestate(EMUFILE* os)
{
u32 version = 8;
write32le(version,os);
//version 2:
MMU_new.backupDevice.save_state(os);
//version 3:
MMU_new.gxstat.savestate(os);
for(int i=0;i<2;i++)
for(int j=0;j<4;j++)
MMU_new.dma[i][j].savestate(os);
MMU_timing.arm9codeFetch.savestate(os, version);
MMU_timing.arm9dataFetch.savestate(os, version);
MMU_timing.arm7codeFetch.savestate(os, version);
MMU_timing.arm7dataFetch.savestate(os, version);
MMU_timing.arm9codeCache.savestate(os, version);
MMU_timing.arm9dataCache.savestate(os, version);
//version 4:
MMU_new.sqrt.savestate(os);
MMU_new.div.savestate(os);
//version 6:
MMU_new.dsi_tsc.save_state(os);
//version 8:
os->write32le(MMU.fw.size);
os->fwrite(MMU.fw.data,MMU.fw.size);
}
// TODO: integrate the new wifi state variables once everything is settled
SFORMAT SF_WIFI[]={
{ "W000", 4, 1, &wifiMac.powerOn},
@ -388,6 +355,47 @@ SFORMAT SF_WIFI[]={
{ 0 }
};
extern SFORMAT SF_RTC[];
static u8 reserveVal = 0;
SFORMAT reserveChunks[] = {
{ "RESV", 1, 1, &reserveVal},
{ 0 }
};
static void mmu_savestate(EMUFILE* os)
{
u32 version = 8;
write32le(version,os);
//version 2:
MMU_new.backupDevice.save_state(os);
//version 3:
MMU_new.gxstat.savestate(os);
for(int i=0;i<2;i++)
for(int j=0;j<4;j++)
MMU_new.dma[i][j].savestate(os);
MMU_timing.arm9codeFetch.savestate(os, version);
MMU_timing.arm9dataFetch.savestate(os, version);
MMU_timing.arm7codeFetch.savestate(os, version);
MMU_timing.arm7dataFetch.savestate(os, version);
MMU_timing.arm9codeCache.savestate(os, version);
MMU_timing.arm9dataCache.savestate(os, version);
//version 4:
MMU_new.sqrt.savestate(os);
MMU_new.div.savestate(os);
//version 6:
MMU_new.dsi_tsc.save_state(os);
//version 8:
os->write32le(MMU.fw.size);
os->fwrite(MMU.fw.data,MMU.fw.size);
}
static bool mmu_loadstate(EMUFILE* is, int size)
{
//read version
@ -924,8 +932,6 @@ bool savestate_save (const char *file_name)
} else return false;
}
extern SFORMAT SF_RTC[];
static void writechunks(EMUFILE* os) {
savestate_WriteChunk(os,1,SF_ARM9);
savestate_WriteChunk(os,2,SF_ARM7);
@ -945,6 +951,13 @@ static void writechunks(EMUFILE* os) {
savestate_WriteChunk(os,110,SF_WIFI);
savestate_WriteChunk(os,120,SF_RTC);
savestate_WriteChunk(os,130,SF_NDS_HEADER);
// reserved for future versions
savestate_WriteChunk(os,140,reserveChunks);
savestate_WriteChunk(os,150,reserveChunks);
savestate_WriteChunk(os,160,reserveChunks);
savestate_WriteChunk(os,170,reserveChunks);
savestate_WriteChunk(os,180,reserveChunks);
// ============================
savestate_WriteChunk(os,0xFFFFFFFF,(SFORMAT*)0);
}
@ -964,8 +977,8 @@ static bool ReadStateChunks(EMUFILE* is, s32 totalsize)
while(totalsize > 0)
{
uint32 size;
u32 t;
u32 size = 0;
u32 t = 0;
if(!read32le(&t,is)) { ret=false; break; }
if(t == 0xFFFFFFFF) break;
if(!read32le(&size,is)) { ret=false; break; }
@ -989,12 +1002,23 @@ static bool ReadStateChunks(EMUFILE* is, s32 totalsize)
case 110: if(!ReadStateChunk(is,SF_WIFI,size)) ret=false; break;
case 120: if(!ReadStateChunk(is,SF_RTC,size)) ret=false; break;
case 130: if(!ReadStateChunk(is,SF_HEADER,size)) ret=false; else haveInfo=true; break;
// reserved for future versions
case 140:
case 150:
case 160:
case 170:
case 180:
if(!ReadStateChunk(is,reserveChunks,size)) ret=false;
break;
// ============================
default:
return false;
}
if(!ret)
return false;
}
if (haveInfo)
{
char buf[14] = {0};
@ -1008,7 +1032,8 @@ static bool ReadStateChunks(EMUFILE* is, s32 totalsize)
printf("\tCRC16: %04Xh\n", header.CRC16);
printf("\tHeader CRC16: %04Xh\n", header.headerCRC16);
// TODO: compare loaded rom header with savestate
if (gameInfo.romsize != romsize || memcmp(&gameInfo.header, &header, sizeof(header)) != 0)
msgbox->warn("The savestate you are loading does not match the ROM you are running.\nYou should find the correct ROM");
}
return ret;

View File

@ -252,29 +252,29 @@ using namespace std;
void msgWndInfo(const char *fmt, ...)
{
MSG_ARG;
printf("Info: %s\n", msg_buf);
printf("[INFO] %s\n", msg_buf);
MessageBox(MainWindow->getHWnd(), msg_buf, EMU_DESMUME_NAME_AND_VERSION(), MB_OK | MB_ICONINFORMATION);
}
bool msgWndConfirm(const char *fmt, ...)
{
MSG_ARG;
printf("Confirm: %s\n", msg_buf);
printf("[CONF] %s\n", msg_buf);
return (MessageBox(MainWindow->getHWnd(), msg_buf, EMU_DESMUME_NAME_AND_VERSION(), MB_YESNO | MB_ICONQUESTION) == IDYES);
}
void msgWndError(const char *fmt, ...)
{
MSG_ARG;
printf("Error: %s\n", msg_buf);
printf("[ERR] %s\n", msg_buf);
MessageBox(MainWindow->getHWnd(), msg_buf, EMU_DESMUME_NAME_AND_VERSION(), MB_OK | MB_ICONERROR);
}
void msgWndWarn(const char *fmt, ...)
{
MSG_ARG;
printf("Warning: %s\n", msg_buf);
MessageBox(MainWindow->getHWnd(), msg_buf, EMU_DESMUME_NAME_AND_VERSION(), MB_YESNO | MB_ICONWARNING);
printf("[WARN] %s\n", msg_buf);
MessageBox(MainWindow->getHWnd(), msg_buf, EMU_DESMUME_NAME_AND_VERSION(), MB_OK | MB_ICONWARNING);
}
msgBoxInterface msgBoxWnd = {
@ -2379,8 +2379,11 @@ static BOOL LoadROM(const char * filename, const char * physicalName, const char
//if (strcmp(filename,"")!=0) INFO("Attempting to load ROM: %s\n",filename);
video.clear();
osd->addFixed(100, 100, "Loading ROM...");
osd->addFixed(100, 120, "Please, wait...");
osd->clear();
osd->addFixed(90, 80, "Loading ROM.");
osd->addFixed(90, 100, "Please, wait...");
osd->addFixed(90, 192 + 80, "Loading ROM.");
osd->addFixed(90, 192 + 100, "Please, wait...");
displayProc(true);
if (NDS_LoadROM(filename, physicalName, logicalName) > 0)
{