clean up rom info collection and mix it up with the movie system

This commit is contained in:
zeromus 2009-06-11 03:40:56 +00:00
parent 5e3e6f8676
commit 947356fbe1
10 changed files with 82 additions and 39 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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++)
{

View File

@ -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;i<comments.size();i++)
@ -244,7 +246,7 @@ int MovieData::dump(std::ostream *os, bool binary)
}
//yuck... another custom text parser.
static bool LoadFM2(MovieData& movieData, std::istream* fp, int size, bool stopAfterHeader)
bool LoadFM2(MovieData& movieData, std::istream* fp, int size, bool stopAfterHeader)
{
//TODO - start with something different. like 'desmume movie version 1"
std::ios::pos_type curr = fp->tellg();
@ -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;

View File

@ -89,9 +89,6 @@ public:
void clear();
//a waste of memory in lots of cases.. maybe make it a pointer later?
//std::vector<char> 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<char> savestate;
std::vector<MovieRecord> 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;

View File

@ -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);
}

View File

@ -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)
{

View File

@ -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);

View File

@ -1,4 +1,5 @@
#include <io.h>
#include <fstream>
#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:

View File

@ -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
}