From 947356fbe11d8c48315f8d51241d3e1cbbfff7fd Mon Sep 17 00:00:00 2001 From: zeromus Date: Thu, 11 Jun 2009 03:40:56 +0000 Subject: [PATCH] clean up rom info collection and mix it up with the movie system --- desmume/src/NDSSystem.cpp | 39 ++++++++++++++++---------------- desmume/src/NDSSystem.h | 13 ++++++++--- desmume/src/cheatSystem.cpp | 2 +- desmume/src/movie.cpp | 13 +++++++---- desmume/src/movie.h | 7 +++--- desmume/src/utils/md5.cpp | 4 ++-- desmume/src/utils/xstring.cpp | 7 ++++++ desmume/src/utils/xstring.h | 1 + desmume/src/windows/replay.cpp | 31 +++++++++++++++++++++++-- desmume/src/windows/resources.rc | 4 ++-- 10 files changed, 82 insertions(+), 39 deletions(-) diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index a752c08f1..f69b87ad3 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -58,7 +58,8 @@ static BOOL LidClosed = FALSE; static u8 countLid = 0; char pathToROM[MAX_PATH]; char pathFilenameToROMwithoutExt[MAX_PATH]; -char ROMserial[20]; + +GameInfo gameInfo; /* the count of bytes copied from the firmware into memory */ #define NDS_FW_USER_SETTINGS_MEM_BYTE_COUNT 0x70 @@ -672,11 +673,12 @@ static u32 ones32(u32 x) } #endif -static void NDS_SetROMSerial() +void GameInfo::populate() { - NDS_header * header; + NDS_header * _header = NDS_getROMHeader(); + header = *_header; + delete _header; - header = NDS_getROMHeader(); if ( // ??? in all Homebrews game title have is 2E0000EA //( @@ -686,15 +688,15 @@ static void NDS_SetROMSerial() //(header->gameTile[3] == 0xEA) //) && ( - ((header->gameCode[0] == 0x23) && - (header->gameCode[1] == 0x23) && - (header->gameCode[2] == 0x23) && - (header->gameCode[3] == 0x23) + ((header.gameCode[0] == 0x23) && + (header.gameCode[1] == 0x23) && + (header.gameCode[2] == 0x23) && + (header.gameCode[3] == 0x23) ) || - (header->gameCode[0] == 0x00) + (header.gameCode[0] == 0x00) ) && - header->makerCode == 0x0 + header.makerCode == 0x0 ) { memset(ROMserial, 0, sizeof(ROMserial)); @@ -703,13 +705,11 @@ static void NDS_SetROMSerial() else { memset(ROMserial, '_', sizeof(ROMserial)); - memcpy(ROMserial, header->gameTile, strlen(header->gameTile) < 12 ? strlen(header->gameTile) : 12); - memcpy(ROMserial+12+1, header->gameCode, 4); - memcpy(ROMserial+12+1+4, &header->makerCode, 2); + memcpy(ROMserial, header.gameTile, strlen(header.gameTile) < 12 ? strlen(header.gameTile) : 12); + memcpy(ROMserial+12+1, header.gameCode, 4); + memcpy(ROMserial+12+1+4, &header.makerCode, 2); memset(ROMserial+19, '\0', 1); } - delete header; - INFO("\nROM serial: %s\n", ROMserial); } #ifdef EXPERIMENTAL_GBASLOT @@ -849,11 +849,10 @@ int NDS_LoadROM( const char *filename, strcat(buf, ".dct"); // DeSmuME cheat :) cheatsInit(buf); - NDS_SetROMSerial(); - - uLong crc = crc32(0,data,size); - INFO("\nROM crc: %08X\n\n", crc); - + gameInfo.populate(); + gameInfo.crc = crc32(0,data,size); + INFO("\nROM crc: %08X\n\n", gameInfo.crc); + INFO("\nROM serial: %s\n", gameInfo.ROMserial); return ret; } diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index 94ddfa965..e9e86759b 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -267,6 +267,16 @@ NDS_FillDefaultFirmwareConfigData( struct NDS_fw_config_data *fw_config); BOOL NDS_SetROM(u8 * rom, u32 mask); NDS_header * NDS_getROMHeader(void); + +struct GameInfo +{ + u32 crc; + NDS_header header; + char ROMserial[20]; + void populate(); +}; + +extern GameInfo gameInfo; void NDS_setTouchPos(u16 x, u16 y); void NDS_releaseTouch(void); @@ -399,9 +409,6 @@ extern struct TCommonSettings { } CommonSettings; -extern char ROMserial[20]; - - extern std::string InputDisplayString; extern int LagFrameFlag; diff --git a/desmume/src/cheatSystem.cpp b/desmume/src/cheatSystem.cpp index f383a62c6..2cb7478cf 100644 --- a/desmume/src/cheatSystem.cpp +++ b/desmume/src/cheatSystem.cpp @@ -562,7 +562,7 @@ BOOL cheatsSave() if (fcheat) { fprintf(fcheat, "; DeSmuME cheat file. VERSION %i.%03i\n", CHEAT_VERSION_MAJOR, CHEAT_VERSION_MINOR); - fprintf(fcheat, "Name=%s\n", ROMserial); + fprintf(fcheat, "Name=%s\n", gameInfo.ROMserial); fputs("; cheats list\n", fcheat); for (int i = 0; i < cheatsNum; i++) { diff --git a/desmume/src/movie.cpp b/desmume/src/movie.cpp index fa33a3526..1c353715f 100644 --- a/desmume/src/movie.cpp +++ b/desmume/src/movie.cpp @@ -167,9 +167,8 @@ MovieData::MovieData() , emuVersion(DESMUME_VERSION_NUMERIC) , rerecordCount(1) , binaryFlag(false) - //, greenZoneCount(0) + , romChecksum(0) { - memset(&romChecksum,0,sizeof(MD5DATA)); } void MovieData::truncateAt(int frame) @@ -191,6 +190,8 @@ void MovieData::installValue(std::string& key, std::string& val) romFilename = val; else if(key == "romChecksum") StringToBytes(val,&romChecksum,MD5DATA::size); + else if(key == "romSerial") + romSerial = val; else if(key == "guid") guid = Desmume_Guid::fromString(val); else if(key == "comment") @@ -217,7 +218,8 @@ int MovieData::dump(std::ostream *os, bool binary) *os << "emuVersion " << emuVersion << endl; *os << "rerecordCount " << rerecordCount << endl; *os << "romFilename " << romFilename << endl; - *os << "romChecksum " << BytesToString(romChecksum.data,MD5DATA::size) << endl; + *os << "romChecksum " << u32ToHexString(gameInfo.crc) << endl; + *os << "romSerial " << romSerial << endl; *os << "guid " << guid.toString() << endl; for(uint32 i=0;itellg(); @@ -478,7 +480,8 @@ static void openRecordingMovie(const char* fname) currMovieData.guid.newGuid(); if(author != L"") currMovieData.comments.push_back(L"author " + author); - //currMovieData.romChecksum = GameInfo->MD5; + currMovieData.romChecksum = gameInfo.crc; + currMovieData.romSerial = gameInfo.ROMserial; currMovieData.romFilename = GetRomName(); extern bool _HACK_DONT_STOPMOVIE; diff --git a/desmume/src/movie.h b/desmume/src/movie.h index 1e0c9bf0b..a25029ee8 100644 --- a/desmume/src/movie.h +++ b/desmume/src/movie.h @@ -89,9 +89,6 @@ public: void clear(); - //a waste of memory in lots of cases.. maybe make it a pointer later? - //std::vector savestate; - void parse(MovieData* md, std::istream* is); bool parseBinary(MovieData* md, std::istream* is); void dump(MovieData* md, std::ostream* os, int index); @@ -116,7 +113,8 @@ public: int emuVersion; //todo - somehow force mutual exclusion for poweron and reset (with an error in the parser) - MD5DATA romChecksum; + u32 romChecksum; + std::string romSerial; std::string romFilename; std::vector savestate; std::vector records; @@ -193,6 +191,7 @@ void NDS_setTouchFromMovie(void); void mov_savestate(std::ostream* os); bool mov_loadstate(std::istream* is, int size); void LoadFM2_binarychunk(MovieData& movieData, std::istream* fp, int size); +bool LoadFM2(MovieData& movieData, std::istream* fp, int size, bool stopAfterHeader); extern bool movie_readonly; extern bool ShowInputDisplay; extern int MicButtonPressed; diff --git a/desmume/src/utils/md5.cpp b/desmume/src/utils/md5.cpp index d4f36dec3..3ba6e3709 100644 --- a/desmume/src/utils/md5.cpp +++ b/desmume/src/utils/md5.cpp @@ -241,8 +241,8 @@ char *md5_asciistr(MD5DATA& md5) for(x=0;x<16;x++) { - str[x*2]=trans[digest[x]&0x0F]; - str[x*2+1]=trans[digest[x]>>4]; + str[x*2]=trans[digest[x]>>4]; + str[x*2+1]=trans[digest[x]&0x0F]; } return(str); } diff --git a/desmume/src/utils/xstring.cpp b/desmume/src/utils/xstring.cpp index 84900dc3a..f50ed0e46 100644 --- a/desmume/src/utils/xstring.cpp +++ b/desmume/src/utils/xstring.cpp @@ -192,6 +192,13 @@ private: unsigned char data[256]; } Base64Table; +std::string u32ToHexString(u32 val) +{ + char temp[16]; + sprintf(temp,"%08X",val); + return temp; +} + ///Converts the provided data to a string in a standard, user-friendly, round-trippable format std::string BytesToString(const void* data, int len) { diff --git a/desmume/src/utils/xstring.h b/desmume/src/utils/xstring.h index 87f7b8574..f02246c43 100644 --- a/desmume/src/utils/xstring.h +++ b/desmume/src/utils/xstring.h @@ -30,6 +30,7 @@ int str_replace(char *str, char *search, char *replace); int HexStringToBytesLength(const std::string& str); int Base64StringToBytesLength(const std::string& str); +std::string u32ToHexString(u32 val); std::string BytesToString(const void* data, int len); bool StringToBytes(const std::string& str, void* data, int len); diff --git a/desmume/src/windows/replay.cpp b/desmume/src/windows/replay.cpp index db6349381..a69bca91a 100644 --- a/desmume/src/windows/replay.cpp +++ b/desmume/src/windows/replay.cpp @@ -1,4 +1,5 @@ #include +#include #include "resource.h" #include "replay.h" #include "common.h" @@ -24,7 +25,33 @@ inline std::string GetDlgItemText(HWND hDlg, int nIDDlgItem) { } -char playfilename[MAX_PATH] = ""; +static char playfilename[MAX_PATH] = ""; + +void Describe(HWND hwndDlg) +{ + std::fstream fs (playfilename); + MovieData md; + LoadFM2(md, &fs, INT_MAX, false); + fs.close(); + + u32 num_frames = md.records.size(); + + u32 div = 60; + float tempCount = (num_frames % 60); //Get fraction of a second + float getTime = ((tempCount / div) * 100); //Convert to 2 digit number + int fraction = getTime; //Convert to 2 digit int + int seconds = (num_frames / div) % 60; + int minutes = (num_frames/(div*60))%60; + int hours = num_frames/(div*60*60); + char tmp[256]; + sprintf(tmp, "%02d:%02d:%02d.%02d", hours, minutes, seconds, fraction); + + SetDlgItemText(hwndDlg,IDC_MLENGTH,tmp); + SetDlgItemInt(hwndDlg,IDC_MFRAMES,num_frames,FALSE); + SetDlgItemText(hwndDlg, PM_FILENAME, playfilename); + SetDlgItemInt(hwndDlg,IDC_MRERECORDCOUNT,md.rerecordCount,FALSE); + SetDlgItemText(hwndDlg,IDC_MROM,md.romSerial.c_str()); +} //Replay movie dialog BOOL CALLBACK ReplayDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) @@ -62,7 +89,7 @@ BOOL CALLBACK ReplayDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP ofn.lpstrDefExt = "dsm"; GetOpenFileName(&ofn); strcpy(playfilename, filename); - SetDlgItemText(hwndDlg, PM_FILENAME, playfilename); + Describe(hwndDlg); return true; case IDC_CHECK_READONLY: diff --git a/desmume/src/windows/resources.rc b/desmume/src/windows/resources.rc index 4e57358cd..5358a91be 100644 --- a/desmume/src/windows/resources.rc +++ b/desmume/src/windows/resources.rc @@ -3527,13 +3527,13 @@ FONT 8, "MS Shell Dlg", 0, 0, 0 PUSHBUTTON "Browse...", ID_BROWSE, 224, 12, 50, 14, BS_PUSHBUTTON EDITTEXT PM_FILENAME, 35, 12, 184, 14, ES_AUTOHSCROLL | ES_READONLY LTEXT "Length:", IDC_STATIC, 38, 70, 25, 8, SS_LEFT - LTEXT "Static", IDC_MLENGTH, 68, 70, 19, 8, SS_LEFT + LTEXT "Static", IDC_MLENGTH, 68, 70, 60, 8, SS_LEFT LTEXT "Frames:", IDC_STATIC, 37, 81, 26, 8, SS_LEFT LTEXT "Static", IDC_MFRAMES, 68, 81, 19, 8, SS_LEFT LTEXT "Rerecord Count:", IDC_STATIC, 10, 91, 53, 8, SS_LEFT LTEXT "Static", IDC_MRERECORDCOUNT, 68, 92, 19, 8, SS_LEFT LTEXT "ROM Used:", IDC_STATIC, 24, 102, 38, 8, SS_LEFT - LTEXT "Static", IDC_MROM, 67, 103, 19, 8, SS_LEFT + LTEXT "Static", IDC_MROM, 67, 103, 100, 8, SS_LEFT }