From: Wouter V. <m97...@us...> - 2002-07-29 18:49:09
|
Update of /cvsroot/openmsx/openMSX/src In directory usw-pr-cvs1:/tmp/cvs-serv15675/src Modified Files: MSXRom.cc MSXRom.hh Added Files: romdb.dtd romdb.xml Log Message: cleanups support ROM database --- NEW FILE: romdb.dtd --- <!ELEMENT romdb (rom)+> <!ELEMENT rom (md5,romtype)> <!ATTLIST rom id CDATA #IMPLIED> <!ELEMENT md5 (#PCDATA)> <!ELEMENT romtype (#PCDATA)> --- NEW FILE: romdb.xml --- <?xml version="1.0"?> <!-- $Id: romdb.xml,v 1.1 2002/07/29 18:48:35 m9710797 Exp $ --> <!DOCTYPE romdb SYSTEM "romdb.dtd"> <romdb> <rom id="Game Master 2"> <md5>1fecd63cf4967dd6d2d4f6901d8d210b</md5> <romtype>GAMEMASTER2</romtype> </rom> <rom id="Bubbler"> <md5>3c4113a49c1cbcefc0a73655f807691a</md5> <romtype>2</romtype> </rom> </romdb> Index: MSXRom.cc =================================================================== RCS file: /cvsroot/openmsx/openMSX/src/MSXRom.cc,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- MSXRom.cc 27 Jul 2002 08:56:27 -0000 1.23 +++ MSXRom.cc 29 Jul 2002 18:48:35 -0000 1.24 @@ -7,6 +7,7 @@ #include "CPU.hh" #include <map> #include "md5.hh" +#include "libxmlx/xmlx.hh" MSXRom::MSXRom(MSXConfig::Device *config, const EmuTime &time) @@ -183,6 +184,9 @@ // no type specified, perform auto detection } if (type == "auto") { + type = searchDataBase(); + } + if (type == "") { mapperType = guessMapperType(); } else { std::map<const std::string, int, ltstr> mappertype; @@ -240,11 +244,6 @@ int MSXRom::guessMapperType() { - MD5 md5; - md5.update(romBank, romSize); - md5.finalize(); - PRT_DEBUG("MD5: "<<md5.hex_digest()); - // GameCartridges do their bankswitching by using the Z80 // instruction ld(nn),a in the middle of program code. The // adress nn depends upon the GameCartridge mappertype used. @@ -322,6 +321,38 @@ return type == 6 ? 19 : type; } } + +const std::string &MSXRom::searchDataBase() +{ + initDataBase(); + + MD5 md5; + md5.update(romBank, romSize); + md5.finalize(); + PRT_DEBUG("MD5: "<<md5.hex_digest()); + + return romDB[std::string(md5.hex_digest())]; +} + +void MSXRom::initDataBase() +{ + static bool init = false; + + if (!init) { + init = true; + XML::Document doc(FileOpener::findFileName("romdb.xml")); + //doc.dump(); + std::list<XML::Element*>::iterator it = doc.root->children.begin(); + for ( ; it != doc.root->children.end(); it++) { + const std::string md5((*it)->getElementPcdata("md5")); + const std::string romtype((*it)->getElementPcdata("romtype")); + romDB[md5] = romtype; + } + } +} + +std::map<const std::string, std::string, MSXRom::ltstr> MSXRom::romDB; + byte MSXRom::readMem(word address, const EmuTime &time) { Index: MSXRom.hh =================================================================== RCS file: /cvsroot/openmsx/openMSX/src/MSXRom.hh,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- MSXRom.hh 27 Jun 2002 10:49:40 -0000 1.14 +++ MSXRom.hh 29 Jul 2002 18:48:35 -0000 1.15 @@ -7,6 +7,7 @@ #include "config.h" #endif +#include <map> #include "MSXRomDevice.hh" #include "MSXMemDevice.hh" @@ -32,6 +33,8 @@ private: void retrieveMapperType(); int guessMapperType(); + const std::string &searchDataBase(); + void initDataBase(); bool mappedOdd(); inline void setBank4kB (int region, byte* adr); @@ -40,7 +43,14 @@ inline void setROM4kB (int region, int block); inline void setROM8kB (int region, int block); inline void setROM16kB (int region, int block); - + + struct ltstr { + bool operator()(const std::string &s1, const std::string &s2) const { + return strcasecmp(s1.c_str(), s2.c_str()) < 0; + } + }; + static std::map<const std::string, std::string, ltstr> romDB; + int mapperType; byte *internalMemoryBank[16]; // 16 blocks of 4kB byte *unmapped; |