openMSX
RomInfo.cc
Go to the documentation of this file.
1 #include "RomInfo.hh"
2 #include "CliComm.hh"
3 #include "StringOp.hh"
4 #include "unreachable.hh"
5 #include <cassert>
6 #include <map>
7 
8 using std::map;
9 using std::vector;
10 using std::string;
11 using std::pair;
12 
13 namespace openmsx {
14 
15 static inline RomType makeAlias(RomType type)
16 {
17  return static_cast<RomType>(ROM_ALIAS | type);
18 }
19 static inline RomType removeAlias(RomType type)
20 {
21  return static_cast<RomType>(type & ~ROM_ALIAS);
22 }
23 static inline bool isAlias(RomType type)
24 {
25  return (type & ROM_ALIAS) != 0;
26 }
27 
28 
29 static bool isInit = false;
30 typedef map<string_ref, RomType, StringOp::caseless> RomTypeMap;
31 typedef map<RomType, pair<string_ref, unsigned>> RomTypeInfoMap; // description blocksize
32 static RomTypeMap romTypeMap;
33 static RomTypeInfoMap romTypeInfoMap;
34 
35 static void init(RomType type, string_ref name,
36  unsigned blocksize, string_ref description)
37 {
38  romTypeMap[name] = type;
39  romTypeInfoMap[type] = std::make_pair(description, blocksize);
40 }
41 static void initAlias(RomType type, string_ref name)
42 {
43  romTypeMap[name] = makeAlias(type);
44 }
45 static void init()
46 {
47  if (isInit) return;
48  isInit = true;
49 
50  // Generic ROM types that don't exist in real ROMs
51  // (should not occur in any database!)
52  init(ROM_GENERIC_8KB, "8kB", 0x2000, "Generic 8kB");
53  init(ROM_GENERIC_16KB, "16kB", 0x4000, "Generic 16kB");
54 
55  // ROM mapper types for normal software (mainly games)
56  init(ROM_KONAMI, "Konami", 0x2000, "Konami MegaROM");
57  init(ROM_KONAMI_SCC, "KonamiSCC", 0x2000, "Konami with SCC");
58  init(ROM_KBDMASTER, "KeyboardMaster", 0x4000, "Konami Keyboard Master with VLM5030"); // officially plain 16K
59  init(ROM_ASCII8, "ASCII8", 0x2000, "ASCII 8kB");
60  init(ROM_ASCII16, "ASCII16", 0x4000, "ASCII 16kB");
61  init(ROM_R_TYPE, "R-Type", 0x4000, "R-Type");
62  init(ROM_CROSS_BLAIM, "CrossBlaim", 0x4000, "Cross Blaim");
63  init(ROM_HARRY_FOX, "HarryFox", 0x4000, "Harry Fox");
64  init(ROM_HALNOTE, "Halnote", 0x2000, "Halnote");
65  init(ROM_ZEMINA80IN1, "Zemina80in1", 0x2000, "Zemina 80 in 1");
66  init(ROM_ZEMINA90IN1, "Zemina90in1", 0x2000, "Zemina 90 in 1");
67  init(ROM_ZEMINA126IN1, "Zemina126in1", 0x2000, "Zemina 126 in 1");
68  init(ROM_ASCII16_2, "ASCII16SRAM2", 0x4000, "ASCII 16kB with 2kB SRAM");
69  init(ROM_ASCII8_8, "ASCII8SRAM8", 0x2000, "ASCII 8kB with 8kB SRAM");
70  init(ROM_KOEI_8, "KoeiSRAM8", 0x2000, "Koei with 8kB SRAM");
71  init(ROM_KOEI_32, "KoeiSRAM32", 0x2000, "Koei with 32kB SRAM");
72  init(ROM_WIZARDRY, "Wizardry", 0x2000, "Wizardry");
73  init(ROM_GAME_MASTER2, "GameMaster2", 0x1000, "Konami's Game Master 2");
74  init(ROM_MAJUTSUSHI, "Majutsushi", 0x2000, "Hai no Majutsushi");
75  init(ROM_SYNTHESIZER, "Synthesizer", 0x4000, "Konami's Synthesizer"); // officially plain 32K
76  init(ROM_PLAYBALL, "PlayBall", 0x4000, "Sony's PlayBall"); // officially plain 32K
77  init(ROM_NETTOU_YAKYUU, "NettouYakyuu", 0x2000, "Nettou Yakuu");
78  init(ROM_HOLY_QURAN, "AlQuranDecoded", 0x2000, "Holy Qu'ran (pre-decrypted)");
79  init(ROM_HOLY_QURAN2, "AlQuran", 0x2000, "Holy Qu'ran");
80  init(ROM_PADIAL8, "Padial8", 0x2000, "Padial 8kB");
81  init(ROM_PADIAL16, "Padial16", 0x4000, "Padial 16kB");
82  init(ROM_SUPERLODERUNNER,"SuperLodeRunner",0x4000, "Super Lode Runner");
83  init(ROM_MSXDOS2, "MSXDOS2", 0x4000, "MSX-DOS2");
84  init(ROM_MANBOW2, "Manbow2", 0x2000, "Manbow2");
85  init(ROM_MANBOW2_2, "Manbow2_2", 0x2000, "Manbow2 - Second Release");
86  init(ROM_HAMARAJANIGHT, "HamarajaNight", 0x2000, "Best of Hamaraja Night");
87  init(ROM_MEGAFLASHROMSCC,"MegaFlashRomScc",0x2000, "Mega Flash ROM SCC");
88  init(ROM_MATRAINK, "MatraInk", 0x0000, "Matra Ink");
89  init(ROM_ARC, "Arc", 0x4000, "Parallax' ARC"); // officially plain 32K
90  init(ROM_DOOLY, "Dooly", 0x4000, "Baby Dinosaur Dooly"); // officially 32K blocksize, but spread over 2 pages
91  init(ROM_MSXTRA, "MSXtra", 0x0000, "PTC MSXtra");
92  init(ROM_MULTIROM, "MultiRom", 0x0000, "MultiRom Collection");
93  init(ROM_MEGAFLASHROMSCCPLUS,"MegaFlashRomSccPlus",0x0000, "Mega Flash ROM SCC Plus"); // ****
94 
95  // ROM mapper types used for system ROMs in machines
96  init(ROM_PANASONIC, "Panasonic", 0x2000, "Panasonic internal mapper");
97  init(ROM_NATIONAL, "National", 0x4000, "National internal mapper");
98  init(ROM_FSA1FM1, "FSA1FM1", 0x0000, "Panasonic FS-A1FM internal mapper 1"); // TODO: romblocks debuggable?
99  init(ROM_FSA1FM2, "FSA1FM2", 0x2000, "Panasonic FS-A1FM internal mapper 2");
100  init(ROM_DRAM, "DRAM", 0x2000, "MSXturboR DRAM");
101 
102  // Non-mapper ROM types
103  init(ROM_MIRRORED, "Mirrored", 0x2000, "Plain rom, mirrored (any size)");
104  init(ROM_MIRRORED0000,"Mirrored0000",0x2000, "Plain rom, mirrored start at 0x0000");
105  init(ROM_MIRRORED4000,"Mirrored4000",0x2000, "Plain rom, mirrored start at 0x4000");
106  init(ROM_MIRRORED8000,"Mirrored8000",0x2000, "Plain rom, mirrored start at 0x8000");
107  init(ROM_MIRROREDC000,"MirroredC000",0x2000, "Plain rom, mirrored start at 0xC000");
108  init(ROM_NORMAL, "Normal", 0x2000, "Plain rom (any size)");
109  init(ROM_NORMAL0000, "Normal0000", 0x2000, "Plain rom start at 0x0000");
110  init(ROM_NORMAL4000, "Normal4000", 0x2000, "Plain rom start at 0x4000");
111  init(ROM_NORMAL8000, "Normal8000", 0x2000, "Plain rom start at 0x8000");
112  init(ROM_NORMALC000, "NormalC000", 0x2000, "Plain rom start at 0xC000");
113  init(ROM_PAGE0, "Page0", 0x2000, "Plain 16kB page 0");
114  init(ROM_PAGE1, "Page1", 0x2000, "Plain 16kB page 1");
115  init(ROM_PAGE2, "Page2", 0x2000, "Plain 16kB page 2 (BASIC)");
116  init(ROM_PAGE3, "Page3", 0x2000, "Plain 16kB page 3");
117  init(ROM_PAGE01, "Page01", 0x2000, "Plain 32kB page 0-1");
118  init(ROM_PAGE12, "Page12", 0x2000, "Plain 32kB page 1-2");
119  init(ROM_PAGE23, "Page23", 0x2000, "Plain 32kB page 2-3");
120  init(ROM_PAGE012, "Page012", 0x2000, "Plain 48kB page 0-2");
121  init(ROM_PAGE123, "Page123", 0x2000, "Plain 48kB page 1-3");
122  init(ROM_PAGE0123, "Page0123", 0x2000, "Plain 64kB");
123 
124  // Alternative names for rom types, mainly for backwards compatibility
125  initAlias(ROM_GENERIC_8KB, "0");
126  initAlias(ROM_GENERIC_8KB, "GenericKonami"); // probably actually used in a Zemina Box
127  initAlias(ROM_GENERIC_16KB,"1");
128  initAlias(ROM_KONAMI_SCC, "2");
129  initAlias(ROM_KONAMI_SCC, "SCC");
130  initAlias(ROM_KONAMI_SCC, "KONAMI5");
131  initAlias(ROM_KONAMI, "KONAMI4");
132  initAlias(ROM_KONAMI, "3");
133  initAlias(ROM_ASCII8, "4");
134  initAlias(ROM_ASCII16, "5");
135  initAlias(ROM_MIRRORED, "64kB");
136  initAlias(ROM_MIRRORED, "Plain");
137  initAlias(ROM_NORMAL0000, "0x0000");
138  initAlias(ROM_NORMAL4000, "0x4000");
139  initAlias(ROM_NORMAL8000, "0x8000");
140  initAlias(ROM_NORMALC000, "0xC000");
141  initAlias(ROM_ASCII16_2, "HYDLIDE2");
142  initAlias(ROM_GAME_MASTER2,"RC755");
143  initAlias(ROM_NORMAL8000, "ROMBAS");
144  initAlias(ROM_R_TYPE, "RTYPE");
145  initAlias(ROM_ZEMINA80IN1, "KOREAN80IN1");
146  initAlias(ROM_ZEMINA90IN1, "KOREAN90IN1");
147  initAlias(ROM_ZEMINA126IN1,"KOREAN126IN1");
148  initAlias(ROM_HOLY_QURAN, "HolyQuran");
149 }
150 static const RomTypeMap& getRomTypeMap()
151 {
152  init();
153  return romTypeMap;
154 }
155 static const RomTypeInfoMap& getRomTypeInfoMap()
156 {
157  init();
158  return romTypeInfoMap;
159 }
160 
162  string_ref ncompany, string_ref ncountry,
163  bool noriginal, string_ref norigType,
164  string_ref nremark, const RomType& nromType,
165  int ngenMSXid)
166  : title (ntitle .str())
167  , year (nyear .str())
168  , company (ncompany .str())
169  , country (ncountry .str())
170  , origType(norigType.str())
171  , remark (nremark .str())
172  , romType(nromType)
173  , genMSXid(ngenMSXid)
174  , original(noriginal)
175 {
176 }
177 
179 {
180  auto& romTypeMap = getRomTypeMap();
181  auto it = romTypeMap.find(name);
182  if (it == romTypeMap.end()) {
183  return ROM_UNKNOWN;
184  }
185  return removeAlias(it->second);
186 }
187 
189 {
190  assert(!isAlias(type));
191  for (auto& p : getRomTypeMap()) {
192  if (p.second == type) {
193  return p.first;
194  }
195  }
196  UNREACHABLE; return "";
197 }
198 
199 vector<string> RomInfo::getAllRomTypes()
200 {
201  vector<string> result;
202  for (auto& p : getRomTypeMap()) {
203  if (!isAlias(p.second)) {
204  result.push_back(p.first.str());
205  }
206  }
207  return result;
208 }
209 
211 {
212  auto& m = getRomTypeInfoMap();
213  auto it = m.find(type);
214  assert(it != m.end());
215  return it->second.first;
216 }
217 
219 {
220  auto& m = getRomTypeInfoMap();
221  auto it = m.find(type);
222  assert(it != m.end());
223  return it->second.second;
224 }
225 
226 } // namespace openmsx