openMSX
RomInfo.cc
Go to the documentation of this file.
2#include "RomInfo.hh"
3#include "StringOp.hh"
4#include "ranges.hh"
5#include "stl.hh"
6#include "unreachable.hh"
7#include "view.hh"
8#include <array>
9#include <cassert>
10
11namespace openmsx {
12
13static constexpr auto romTypeInfoArray = [] {
14 std::array<RomInfo::RomTypeInfo, RomType::ROM_LAST> r = {};
15
16 // Generic ROM types that don't exist in real ROMs
17 // (should not occur in any database!)
18 r[ROM_GENERIC_8KB] = {0x2000, "8kB", "Generic 8kB"};
19 r[ROM_GENERIC_16KB] = {0x4000, "16kB", "Generic 16kB"};
20
21 // ROM mapper types for normal software (mainly games)
22 r[ROM_KONAMI] = {0x2000, "Konami", "Konami MegaROM"};
23 r[ROM_KONAMI_SCC] = {0x2000, "KonamiSCC", "Konami with SCC"};
24 r[ROM_KBDMASTER] = {0x4000, "KeyboardMaster", "Konami Keyboard Master with VLM5030"}; // officially plain 16K
25 r[ROM_ASCII8] = {0x2000, "ASCII8", "ASCII 8kB"};
26 r[ROM_ASCII16] = {0x4000, "ASCII16", "ASCII 16kB"};
27 r[ROM_R_TYPE] = {0x4000, "R-Type", "R-Type"};
28 r[ROM_CROSS_BLAIM] = {0x4000, "CrossBlaim", "Cross Blaim"};
29 r[ROM_HARRY_FOX] = {0x4000, "HarryFox", "Harry Fox"};
30 r[ROM_HALNOTE] = {0x2000, "Halnote", "Halnote"};
31 r[ROM_ZEMINA25IN1] = {0x2000, "Zemina25in1", "Zemina 25 in 1"};
32 r[ROM_ZEMINA80IN1] = {0x2000, "Zemina80in1", "Zemina 80 in 1"};
33 r[ROM_ZEMINA90IN1] = {0x2000, "Zemina90in1", "Zemina 90 in 1"};
34 r[ROM_ZEMINA126IN1] = {0x2000, "Zemina126in1", "Zemina 126 in 1"};
35 r[ROM_ASCII16_2] = {0x4000, "ASCII16SRAM2", "ASCII 16kB with 2kB SRAM"};
36 r[ROM_ASCII16_8] = {0x4000, "ASCII16SRAM8", "ASCII 16kB with 8kB SRAM"};
37 r[ROM_ASCII8_8] = {0x2000, "ASCII8SRAM8", "ASCII 8kB with 8kB SRAM"};
38 r[ROM_ASCII8_32] = {0x2000, "ASCII8SRAM32", "ASCII 8kB with 32kB SRAM"};
39 r[ROM_ASCII8_2] = {0x2000, "ASCII8SRAM2", "ASCII 8kB with 2kB SRAM"};
40 r[ROM_KOEI_8] = {0x2000, "KoeiSRAM8", "Koei with 8kB SRAM"};
41 r[ROM_KOEI_32] = {0x2000, "KoeiSRAM32", "Koei with 32kB SRAM"};
42 r[ROM_WIZARDRY] = {0x2000, "Wizardry", "Wizardry"};
43 r[ROM_GAME_MASTER2] = {0x1000, "GameMaster2", "Konami's Game Master 2"};
44 r[ROM_MAJUTSUSHI] = {0x2000, "Majutsushi", "Hai no Majutsushi"};
45 r[ROM_SYNTHESIZER] = {0 , "Synthesizer", "Konami's Synthesizer"}; // plain 32K
46 r[ROM_PLAYBALL] = {0 , "PlayBall", "Sony's PlayBall"}; // plain 32K
47 r[ROM_NETTOU_YAKYUU] = {0x2000, "NettouYakyuu", "Nettou Yakuu"};
48 r[ROM_HOLY_QURAN] = {0x2000, "AlQuranDecoded", "Holy Qu'ran (pre-decrypted)"};
49 r[ROM_HOLY_QURAN2] = {0x2000, "AlQuran", "Holy Qu'ran"};
50 r[ROM_PADIAL8] = {0x2000, "Padial8", "Padial 8kB"};
51 r[ROM_PADIAL16] = {0x4000, "Padial16", "Padial 16kB"};
52 r[ROM_SUPERLODERUNNER] = {0x4000, "SuperLodeRunner", "Super Lode Runner"};
53 r[ROM_SUPERSWANGI] = {0x4000, "SuperSwangi", "Super Swangi"};
54 r[ROM_MSXDOS2] = {0x4000, "MSXDOS2", "MSX-DOS2"};
55 r[ROM_MITSUBISHIMLTS2] = {0x2000, "MitsubishiMLTS2", "Mitsubishi ML-TS2 firmware"};
56 r[ROM_MANBOW2] = {0x2000, "Manbow2", "Manbow2"};
57 r[ROM_MANBOW2_2] = {0x2000, "Manbow2_2", "Manbow2 - Second Release"};
58 r[ROM_RBSC_FLASH_KONAMI_SCC]={0x2000,"RBSC_Flash_KonamiSCC","RBSC 2MB flash, Konami SCC mapper"};
59 r[ROM_HAMARAJANIGHT] = {0x2000, "HamarajaNight", "Best of Hamaraja Night"};
60 r[ROM_MEGAFLASHROMSCC] = {0x2000, "MegaFlashRomScc", "Mega Flash ROM SCC"};
61 r[ROM_MATRAINK] = {0 , "MatraInk", "Matra Ink"};
62 r[ROM_MATRACOMPILATION]= {0x2000, "MatraCompilation","Matra Compilation"};
63 r[ROM_ARC] = {0 , "Arc", "Parallax' ARC"}; // plain 32K
64 r[ROM_ROMHUNTERMK2] = {0x2000, "ROMHunterMk2", "ROM Hunter Mk2"}; // variable block size, 8kB smallest
65 r[ROM_DOOLY] = {0x4000, "Dooly", "Baby Dinosaur Dooly"}; // officially 32K blocksize, but spread over 2 pages
66 r[ROM_MSXTRA] = {0 , "MSXtra", "PTC MSXtra"};
67 r[ROM_MSXWRITE] = {0x4000, "MSXWrite", "Japanese MSX Write"};
68 r[ROM_MULTIROM] = {0x4000, "MultiRom", "MultiRom Collection"};
69 r[ROM_RAMFILE] = {0 , "RAMFILE", "Tecall MSX RAMFILE"};
70 r[ROM_RETROHARD31IN1] = {0x2000, "RetroHardMultiCart31in1", "RetroHard MultiCart 31 in 1"};
71 r[ROM_ALALAMIAH30IN1] = {0x8000, "AlAlamiah30-in-1", "Al Alamiah 30-in-1"};
72 r[ROM_COLECOMEGACART] = {0x4000, "ColecoMegaCart", "ColecoVision MegaCart"};
73 r[ROM_MEGAFLASHROMSCCPLUS]={0 ,"MegaFlashRomSccPlus","Mega Flash ROM SCC Plus"}; // variable block size
74 r[ROM_REPRO_CARTRIDGE1]= {0x2000, "ReproCartridgeV1","Repro Cartridge V1"};
75 r[ROM_REPRO_CARTRIDGE2]= {0x2000, "ReproCartridgeV2","Repro Cartridge V2"};
76 r[ROM_KONAMI_ULTIMATE_COLLECTION]={0x2000,"KonamiUltimateCollection","Konami Ultimate Collection"};
77 r[ROM_NEO8] = {0x2000, "NEO-8", "NEO-8 mapper"};
78 r[ROM_NEO16] = {0x4000, "NEO-16", "NEO-16 mapper"};
79
80 // ROM mapper types used for system ROMs in machines
81 r[ROM_PANASONIC] = {0x2000, "Panasonic", "Panasonic internal mapper"};
82 r[ROM_NATIONAL] = {0x4000, "National", "National internal mapper"};
83 r[ROM_FSA1FM1] = {0 , "FSA1FM1", "Panasonic FS-A1FM internal mapper 1"}; // TODO: romblocks debuggable?
84 r[ROM_FSA1FM2] = {0x2000, "FSA1FM2", "Panasonic FS-A1FM internal mapper 2"};
85 r[ROM_DRAM] = {0x2000, "DRAM", "MSXturboR DRAM"};
86
87 // Non-mapper ROM types
88 r[ROM_MIRRORED] = {0, "Mirrored", "Plain rom, mirrored (any size)"};
89 r[ROM_MIRRORED0000] = {0, "Mirrored0000", "Plain rom, mirrored start at 0x0000"};
90 r[ROM_MIRRORED4000] = {0, "Mirrored4000", "Plain rom, mirrored start at 0x4000"};
91 r[ROM_MIRRORED8000] = {0, "Mirrored8000", "Plain rom, mirrored start at 0x8000"};
92 r[ROM_MIRROREDC000] = {0, "MirroredC000", "Plain rom, mirrored start at 0xC000"};
93 r[ROM_NORMAL] = {0, "Normal", "Plain rom (any size)"};
94 r[ROM_NORMAL0000] = {0, "Normal0000", "Plain rom start at 0x0000"};
95 r[ROM_NORMAL4000] = {0, "Normal4000", "Plain rom start at 0x4000"};
96 r[ROM_NORMAL8000] = {0, "Normal8000", "Plain rom start at 0x8000"};
97 r[ROM_NORMALC000] = {0, "NormalC000", "Plain rom start at 0xC000"};
98 r[ROM_PAGE0] = {0, "Page0", "Plain 16kB page 0"};
99 r[ROM_PAGE1] = {0, "Page1", "Plain 16kB page 1"};
100 r[ROM_PAGE2] = {0, "Page2", "Plain 16kB page 2 (BASIC)"};
101 r[ROM_PAGE3] = {0, "Page3", "Plain 16kB page 3"};
102 r[ROM_PAGE01] = {0, "Page01", "Plain 32kB page 0-1"};
103 r[ROM_PAGE12] = {0, "Page12", "Plain 32kB page 1-2"};
104 r[ROM_PAGE23] = {0, "Page23", "Plain 32kB page 2-3"};
105 r[ROM_PAGE012] = {0, "Page012", "Plain 48kB page 0-2"};
106 r[ROM_PAGE123] = {0, "Page123", "Plain 48kB page 1-3"};
107 r[ROM_PAGE0123] = {0, "Page0123", "Plain 64kB"};
108 return r;
109}();
110const std::array<RomInfo::RomTypeInfo, RomType::ROM_LAST>& RomInfo::getRomTypeInfo()
111{
112 return romTypeInfoArray;
113}
114
117 std::string_view name;
118};
119static constexpr std::array aliasTable = {
121 RomTypeAndName{ROM_GENERIC_8KB, "GenericKonami"}, // probably actually used in a Zemina Box
122 RomTypeAndName{ROM_GENERIC_16KB,"1"},
123 RomTypeAndName{ROM_KONAMI_SCC, "2"},
124 RomTypeAndName{ROM_KONAMI_SCC, "SCC"},
125 RomTypeAndName{ROM_KONAMI_SCC, "KONAMI5"},
126 RomTypeAndName{ROM_KONAMI, "KONAMI4"},
127 RomTypeAndName{ROM_KONAMI, "3"},
128 RomTypeAndName{ROM_ASCII8, "4"},
129 RomTypeAndName{ROM_ASCII16, "5"},
130 RomTypeAndName{ROM_MIRRORED, "64kB"},
131 RomTypeAndName{ROM_MIRRORED, "Plain"},
132 RomTypeAndName{ROM_NORMAL0000, "0x0000"},
133 RomTypeAndName{ROM_NORMAL4000, "0x4000"},
134 RomTypeAndName{ROM_NORMAL8000, "0x8000"},
135 RomTypeAndName{ROM_NORMALC000, "0xC000"},
136 RomTypeAndName{ROM_ASCII16_2, "HYDLIDE2"},
137 RomTypeAndName{ROM_GAME_MASTER2,"RC755"},
138 RomTypeAndName{ROM_NORMAL8000, "ROMBAS"},
139 RomTypeAndName{ROM_R_TYPE, "RTYPE"},
140 RomTypeAndName{ROM_ZEMINA80IN1, "KOREAN80IN1"},
141 RomTypeAndName{ROM_ZEMINA90IN1, "KOREAN90IN1"},
142 RomTypeAndName{ROM_ZEMINA126IN1,"KOREAN126IN1"},
143 RomTypeAndName{ROM_HOLY_QURAN, "HolyQuran"},
144};
145
146static constexpr auto combinedRomTable = [] {
147 constexpr auto N = std::size(romTypeInfoArray) + std::size(aliasTable);
148 std::array<RomTypeAndName, N> result = {};
149 size_t i = 0;
150 for (const auto& e : romTypeInfoArray) {
151 result[i].romType = static_cast<RomType>(i);
152 result[i].name = e.name;
153 ++i;
154 }
155 for (const auto& e : aliasTable) {
156 result[i++] = e;
157 }
158 return result;
159}();
160
162 [[nodiscard]] constexpr uint32_t operator()(std::string_view str) const {
163 constexpr auto MASK = uint8_t(~('a' - 'A')); // case insensitive
164 uint32_t d = 0;
165 for (char c : str) {
166 d = (d ^ (c & MASK)) * 0x01000193;
167 }
168 return d;
169 }
170};
171
172// Construct perfect hash function to lookup RomType by name.
173static constexpr auto pmh = [] {
174 auto getKey = [](size_t i) { return combinedRomTable[i].name; };
175 return PerfectMinimalHash::create<std::size(combinedRomTable)>(RomTypeNameHash{}, getKey);
176}();
177
178RomType RomInfo::nameToRomType(std::string_view name)
179{
180 auto idx = pmh.lookupIndex(name);
181 assert(idx < std::size(combinedRomTable));
183 if (cmp(combinedRomTable[idx].name, name)) {
184 return combinedRomTable[idx].romType;
185 }
186 return ROM_UNKNOWN;
187}
188
189std::string_view RomInfo::romTypeToName(RomType type)
190{
191 return romTypeInfoArray[type].name;
192}
193
194std::string_view RomInfo::getDescription(RomType type)
195{
196 return romTypeInfoArray[type].description;
197}
198
200{
201 return romTypeInfoArray[type].blockSize;
202}
203
204} // namespace openmsx
static unsigned getBlockSize(RomType type)
Definition RomInfo.cc:199
static const std::array< RomInfo::RomTypeInfo, RomType::ROM_LAST > & getRomTypeInfo()
Definition RomInfo.cc:110
static std::string_view getDescription(RomType type)
Definition RomInfo.cc:194
static std::string_view romTypeToName(RomType type)
Definition RomInfo.cc:189
static RomType nameToRomType(std::string_view name)
Definition RomInfo.cc:178
constexpr double e
Definition Math.hh:21
This file implemented 3 utility functions:
Definition Autofire.cc:9
@ ROM_HALNOTE
Definition RomTypes.hh:26
@ ROM_COLECOMEGACART
Definition RomTypes.hh:17
@ ROM_MATRACOMPILATION
Definition RomTypes.hh:44
@ ROM_DRAM
Definition RomTypes.hh:20
@ ROM_PADIAL8
Definition RomTypes.hh:66
@ ROM_ASCII16_2
Definition RomTypes.hh:15
@ ROM_FSA1FM1
Definition RomTypes.hh:21
@ ROM_FSA1FM2
Definition RomTypes.hh:22
@ ROM_ZEMINA126IN1
Definition RomTypes.hh:91
@ ROM_PADIAL16
Definition RomTypes.hh:67
@ ROM_NORMAL0000
Definition RomTypes.hh:62
@ ROM_KOEI_8
Definition RomTypes.hh:32
@ ROM_MIRRORED8000
Definition RomTypes.hh:50
@ ROM_UNKNOWN
Definition RomTypes.hh:94
@ ROM_ZEMINA90IN1
Definition RomTypes.hh:90
@ ROM_PAGE1
Definition RomTypes.hh:69
@ ROM_SYNTHESIZER
Definition RomTypes.hh:86
@ ROM_PAGE2
Definition RomTypes.hh:71
@ ROM_PANASONIC
Definition RomTypes.hh:78
@ ROM_GENERIC_16KB
Definition RomTypes.hh:25
@ ROM_REPRO_CARTRIDGE2
Definition RomTypes.hh:37
@ ROM_PAGE01
Definition RomTypes.hh:70
@ ROM_MANBOW2_2
Definition RomTypes.hh:41
@ ROM_ZEMINA80IN1
Definition RomTypes.hh:89
@ ROM_ROMHUNTERMK2
Definition RomTypes.hh:83
@ ROM_HAMARAJANIGHT
Definition RomTypes.hh:27
@ ROM_MIRRORED0000
Definition RomTypes.hh:48
@ ROM_CROSS_BLAIM
Definition RomTypes.hh:18
@ ROM_RETROHARD31IN1
Definition RomTypes.hh:82
@ ROM_MANBOW2
Definition RomTypes.hh:40
@ ROM_NETTOU_YAKYUU
Definition RomTypes.hh:60
@ ROM_MULTIROM
Definition RomTypes.hh:56
@ ROM_GAME_MASTER2
Definition RomTypes.hh:23
@ ROM_MEGAFLASHROMSCC
Definition RomTypes.hh:45
@ ROM_PAGE3
Definition RomTypes.hh:74
@ ROM_MIRRORED4000
Definition RomTypes.hh:49
@ ROM_PAGE12
Definition RomTypes.hh:72
@ ROM_MEGAFLASHROMSCCPLUS
Definition RomTypes.hh:46
@ ROM_MSXDOS2
Definition RomTypes.hh:53
@ ROM_ASCII16
Definition RomTypes.hh:14
@ ROM_ZEMINA25IN1
Definition RomTypes.hh:88
@ ROM_MAJUTSUSHI
Definition RomTypes.hh:39
@ ROM_ARC
Definition RomTypes.hh:8
@ ROM_SUPERLODERUNNER
Definition RomTypes.hh:84
@ ROM_SUPERSWANGI
Definition RomTypes.hh:85
@ ROM_PAGE123
Definition RomTypes.hh:76
@ ROM_ASCII8_32
Definition RomTypes.hh:12
@ ROM_PAGE23
Definition RomTypes.hh:75
@ ROM_KONAMI_ULTIMATE_COLLECTION
Definition RomTypes.hh:38
@ ROM_NATIONAL
Definition RomTypes.hh:57
@ ROM_NORMALC000
Definition RomTypes.hh:65
@ ROM_NORMAL4000
Definition RomTypes.hh:63
@ ROM_KBDMASTER
Definition RomTypes.hh:31
@ ROM_RBSC_FLASH_KONAMI_SCC
Definition RomTypes.hh:42
@ ROM_MIRRORED
Definition RomTypes.hh:47
@ ROM_ASCII16_8
Definition RomTypes.hh:16
@ ROM_NEO16
Definition RomTypes.hh:59
@ ROM_HARRY_FOX
Definition RomTypes.hh:28
@ ROM_R_TYPE
Definition RomTypes.hh:80
@ ROM_NORMAL8000
Definition RomTypes.hh:64
@ ROM_WIZARDRY
Definition RomTypes.hh:87
@ ROM_NORMAL
Definition RomTypes.hh:61
@ ROM_KONAMI
Definition RomTypes.hh:34
@ ROM_MATRAINK
Definition RomTypes.hh:43
@ ROM_PLAYBALL
Definition RomTypes.hh:79
@ ROM_PAGE0123
Definition RomTypes.hh:77
@ ROM_RAMFILE
Definition RomTypes.hh:81
@ ROM_MITSUBISHIMLTS2
Definition RomTypes.hh:52
@ ROM_ASCII8_2
Definition RomTypes.hh:11
@ ROM_PAGE012
Definition RomTypes.hh:73
@ ROM_PAGE0
Definition RomTypes.hh:68
@ ROM_MSXTRA
Definition RomTypes.hh:54
@ ROM_MIRROREDC000
Definition RomTypes.hh:51
@ ROM_GENERIC_8KB
Definition RomTypes.hh:24
@ ROM_KOEI_32
Definition RomTypes.hh:33
@ ROM_HOLY_QURAN2
Definition RomTypes.hh:30
@ ROM_MSXWRITE
Definition RomTypes.hh:55
@ ROM_ASCII8_8
Definition RomTypes.hh:13
@ ROM_NEO8
Definition RomTypes.hh:58
@ ROM_DOOLY
Definition RomTypes.hh:19
@ ROM_KONAMI_SCC
Definition RomTypes.hh:35
@ ROM_REPRO_CARTRIDGE1
Definition RomTypes.hh:36
@ ROM_HOLY_QURAN
Definition RomTypes.hh:29
@ ROM_ALALAMIAH30IN1
Definition RomTypes.hh:9
@ ROM_ASCII8
Definition RomTypes.hh:10
std::string_view name
Definition RomInfo.cc:117
constexpr uint32_t operator()(std::string_view str) const
Definition RomInfo.cc:162