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