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] = {0x4000, "Synthesizer", "Konami's Synthesizer"}; // officially plain 32K
46 r[ROM_PLAYBALL] = {0x4000, "PlayBall", "Sony's PlayBall"}; // officially 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] = {0x0000, "MatraInk", "Matra Ink"};
62 r[ROM_MATRACOMPILATION]= {0x2000, "MatraCompilation","Matra Compilation"};
63 r[ROM_ARC] = {0x4000, "Arc", "Parallax' ARC"}; // officially plain 32K
64 r[ROM_ROMHUNTERMK2] = {0x0000, "ROMHunterMk2", "ROM Hunter Mk2"};
65 r[ROM_DOOLY] = {0x4000, "Dooly", "Baby Dinosaur Dooly"}; // officially 32K blocksize, but spread over 2 pages
66 r[ROM_MSXTRA] = {0x0000, "MSXtra", "PTC MSXtra"};
67 r[ROM_MSXWRITE] = {0x4000, "MSXWrite", "Japanese MSX Write"};
68 r[ROM_MULTIROM] = {0x0000, "MultiRom", "MultiRom Collection"};
69 r[ROM_RAMFILE] = {0x0000, "RAMFILE", "Tecall MSX RAMFILE"};
70 r[ROM_COLECOMEGACART] = {0x4000, "ColecoMegaCart", "ColecoVision MegaCart"};
71 r[ROM_MEGAFLASHROMSCCPLUS]={0x0000,"MegaFlashRomSccPlus","Mega Flash ROM SCC Plus"};
72 r[ROM_REPRO_CARTRIDGE1]= {0x0000, "ReproCartridgeV1","Repro Cartridge V1"};
73 r[ROM_REPRO_CARTRIDGE2]= {0x0000, "ReproCartridgeV2","Repro Cartridge V2"};
74 r[ROM_KONAMI_ULTIMATE_COLLECTION]={0x0000,"KonamiUltimateCollection","Konami Ultimate Collection"};
75
76 // ROM mapper types used for system ROMs in machines
77 r[ROM_PANASONIC] = {0x2000, "Panasonic", "Panasonic internal mapper"};
78 r[ROM_NATIONAL] = {0x4000, "National", "National internal mapper"};
79 r[ROM_FSA1FM1] = {0x0000, "FSA1FM1", "Panasonic FS-A1FM internal mapper 1"}; // TODO: romblocks debuggable?
80 r[ROM_FSA1FM2] = {0x2000, "FSA1FM2", "Panasonic FS-A1FM internal mapper 2"};
81 r[ROM_DRAM] = {0x2000, "DRAM", "MSXturboR DRAM"};
82
83 // Non-mapper ROM types
84 r[ROM_MIRRORED] = {0x2000, "Mirrored", "Plain rom, mirrored (any size)"};
85 r[ROM_MIRRORED0000] = {0x2000, "Mirrored0000", "Plain rom, mirrored start at 0x0000"};
86 r[ROM_MIRRORED4000] = {0x2000, "Mirrored4000", "Plain rom, mirrored start at 0x4000"};
87 r[ROM_MIRRORED8000] = {0x2000, "Mirrored8000", "Plain rom, mirrored start at 0x8000"};
88 r[ROM_MIRROREDC000] = {0x2000, "MirroredC000", "Plain rom, mirrored start at 0xC000"};
89 r[ROM_NORMAL] = {0x2000, "Normal", "Plain rom (any size)"};
90 r[ROM_NORMAL0000] = {0x2000, "Normal0000", "Plain rom start at 0x0000"};
91 r[ROM_NORMAL4000] = {0x2000, "Normal4000", "Plain rom start at 0x4000"};
92 r[ROM_NORMAL8000] = {0x2000, "Normal8000", "Plain rom start at 0x8000"};
93 r[ROM_NORMALC000] = {0x2000, "NormalC000", "Plain rom start at 0xC000"};
94 r[ROM_PAGE0] = {0x2000, "Page0", "Plain 16kB page 0"};
95 r[ROM_PAGE1] = {0x2000, "Page1", "Plain 16kB page 1"};
96 r[ROM_PAGE2] = {0x2000, "Page2", "Plain 16kB page 2 (BASIC)"};
97 r[ROM_PAGE3] = {0x2000, "Page3", "Plain 16kB page 3"};
98 r[ROM_PAGE01] = {0x2000, "Page01", "Plain 32kB page 0-1"};
99 r[ROM_PAGE12] = {0x2000, "Page12", "Plain 32kB page 1-2"};
100 r[ROM_PAGE23] = {0x2000, "Page23", "Plain 32kB page 2-3"};
101 r[ROM_PAGE012] = {0x2000, "Page012", "Plain 48kB page 0-2"};
102 r[ROM_PAGE123] = {0x2000, "Page123", "Plain 48kB page 1-3"};
103 r[ROM_PAGE0123] = {0x2000, "Page0123", "Plain 64kB"};
104 return r;
105}();
106const std::array<RomInfo::RomTypeInfo, RomType::ROM_LAST>& RomInfo::getRomTypeInfo()
107{
108 return romTypeInfoArray;
109}
110
113 std::string_view name;
114};
115static constexpr std::array aliasTable = {
117 RomTypeAndName{ROM_GENERIC_8KB, "GenericKonami"}, // probably actually used in a Zemina Box
118 RomTypeAndName{ROM_GENERIC_16KB,"1"},
119 RomTypeAndName{ROM_KONAMI_SCC, "2"},
120 RomTypeAndName{ROM_KONAMI_SCC, "SCC"},
121 RomTypeAndName{ROM_KONAMI_SCC, "KONAMI5"},
122 RomTypeAndName{ROM_KONAMI, "KONAMI4"},
123 RomTypeAndName{ROM_KONAMI, "3"},
124 RomTypeAndName{ROM_ASCII8, "4"},
125 RomTypeAndName{ROM_ASCII16, "5"},
126 RomTypeAndName{ROM_MIRRORED, "64kB"},
127 RomTypeAndName{ROM_MIRRORED, "Plain"},
128 RomTypeAndName{ROM_NORMAL0000, "0x0000"},
129 RomTypeAndName{ROM_NORMAL4000, "0x4000"},
130 RomTypeAndName{ROM_NORMAL8000, "0x8000"},
131 RomTypeAndName{ROM_NORMALC000, "0xC000"},
132 RomTypeAndName{ROM_ASCII16_2, "HYDLIDE2"},
133 RomTypeAndName{ROM_GAME_MASTER2,"RC755"},
134 RomTypeAndName{ROM_NORMAL8000, "ROMBAS"},
135 RomTypeAndName{ROM_R_TYPE, "RTYPE"},
136 RomTypeAndName{ROM_ZEMINA80IN1, "KOREAN80IN1"},
137 RomTypeAndName{ROM_ZEMINA90IN1, "KOREAN90IN1"},
138 RomTypeAndName{ROM_ZEMINA126IN1,"KOREAN126IN1"},
139 RomTypeAndName{ROM_HOLY_QURAN, "HolyQuran"},
140};
141
142static constexpr auto combinedRomTable = [] {
143 constexpr auto N = std::size(romTypeInfoArray) + std::size(aliasTable);
144 std::array<RomTypeAndName, N> result = {};
145 size_t i = 0;
146 for (const auto& e : romTypeInfoArray) {
147 result[i].romType = static_cast<RomType>(i);
148 result[i].name = e.name;
149 ++i;
150 }
151 for (const auto& e : aliasTable) {
152 result[i++] = e;
153 }
154 return result;
155}();
156
158 [[nodiscard]] constexpr uint32_t operator()(std::string_view str) const {
159 constexpr auto MASK = uint8_t(~('a' - 'A')); // case insensitive
160 uint32_t d = 0;
161 for (char c : str) {
162 d = (d ^ (c & MASK)) * 0x01000193;
163 }
164 return d;
165 }
166};
167
168// Construct perfect hash function to lookup RomType by name.
169static constexpr auto pmh = [] {
170 auto getKey = [](size_t i) { return combinedRomTable[i].name; };
171 return PerfectMinimalHash::create<std::size(combinedRomTable)>(RomTypeNameHash{}, getKey);
172}();
173
174RomType RomInfo::nameToRomType(std::string_view name)
175{
176 auto idx = pmh.lookupIndex(name);
177 assert(idx < std::size(combinedRomTable));
179 if (cmp(combinedRomTable[idx].name, name)) {
180 return combinedRomTable[idx].romType;
181 }
182 return ROM_UNKNOWN;
183}
184
185std::string_view RomInfo::romTypeToName(RomType type)
186{
187 return romTypeInfoArray[type].name;
188}
189
190std::string_view RomInfo::getDescription(RomType type)
191{
192 return romTypeInfoArray[type].description;
193}
194
196{
197 return romTypeInfoArray[type].blockSize;
198}
199
200} // namespace openmsx
static unsigned getBlockSize(RomType type)
Definition: RomInfo.cc:195
static std::string_view getDescription(RomType type)
Definition: RomInfo.cc:190
static std::string_view romTypeToName(RomType type)
Definition: RomInfo.cc:185
static RomType nameToRomType(std::string_view name)
Definition: RomInfo.cc:174
constexpr double e
Definition: Math.hh:20
This file implemented 3 utility functions:
Definition: Autofire.cc:9
@ ROM_HALNOTE
Definition: RomTypes.hh:25
@ ROM_COLECOMEGACART
Definition: RomTypes.hh:16
@ ROM_MATRACOMPILATION
Definition: RomTypes.hh:43
@ ROM_DRAM
Definition: RomTypes.hh:19
@ ROM_PADIAL8
Definition: RomTypes.hh:63
@ ROM_ASCII16_2
Definition: RomTypes.hh:14
@ ROM_FSA1FM1
Definition: RomTypes.hh:20
@ ROM_FSA1FM2
Definition: RomTypes.hh:21
@ ROM_ZEMINA126IN1
Definition: RomTypes.hh:87
@ ROM_PADIAL16
Definition: RomTypes.hh:64
@ ROM_NORMAL0000
Definition: RomTypes.hh:59
@ ROM_KOEI_8
Definition: RomTypes.hh:31
@ ROM_MIRRORED8000
Definition: RomTypes.hh:49
@ ROM_UNKNOWN
Definition: RomTypes.hh:90
@ ROM_ZEMINA90IN1
Definition: RomTypes.hh:86
@ ROM_PAGE1
Definition: RomTypes.hh:66
@ ROM_SYNTHESIZER
Definition: RomTypes.hh:82
@ ROM_PAGE2
Definition: RomTypes.hh:68
@ ROM_PANASONIC
Definition: RomTypes.hh:75
@ ROM_GENERIC_16KB
Definition: RomTypes.hh:24
@ ROM_REPRO_CARTRIDGE2
Definition: RomTypes.hh:36
@ ROM_PAGE01
Definition: RomTypes.hh:67
@ ROM_MANBOW2_2
Definition: RomTypes.hh:40
@ ROM_ZEMINA80IN1
Definition: RomTypes.hh:85
@ ROM_ROMHUNTERMK2
Definition: RomTypes.hh:79
@ ROM_HAMARAJANIGHT
Definition: RomTypes.hh:26
@ ROM_MIRRORED0000
Definition: RomTypes.hh:47
@ ROM_CROSS_BLAIM
Definition: RomTypes.hh:17
@ ROM_MANBOW2
Definition: RomTypes.hh:39
@ ROM_NETTOU_YAKYUU
Definition: RomTypes.hh:57
@ ROM_MULTIROM
Definition: RomTypes.hh:55
@ ROM_GAME_MASTER2
Definition: RomTypes.hh:22
@ ROM_MEGAFLASHROMSCC
Definition: RomTypes.hh:44
@ ROM_PAGE3
Definition: RomTypes.hh:71
@ ROM_MIRRORED4000
Definition: RomTypes.hh:48
@ ROM_PAGE12
Definition: RomTypes.hh:69
@ ROM_MEGAFLASHROMSCCPLUS
Definition: RomTypes.hh:45
@ ROM_MSXDOS2
Definition: RomTypes.hh:52
@ ROM_ASCII16
Definition: RomTypes.hh:13
@ ROM_ZEMINA25IN1
Definition: RomTypes.hh:84
@ ROM_MAJUTSUSHI
Definition: RomTypes.hh:38
@ ROM_ARC
Definition: RomTypes.hh:8
@ ROM_SUPERLODERUNNER
Definition: RomTypes.hh:80
@ ROM_SUPERSWANGI
Definition: RomTypes.hh:81
@ ROM_PAGE123
Definition: RomTypes.hh:73
@ ROM_ASCII8_32
Definition: RomTypes.hh:11
@ ROM_PAGE23
Definition: RomTypes.hh:72
@ ROM_KONAMI_ULTIMATE_COLLECTION
Definition: RomTypes.hh:37
@ ROM_NATIONAL
Definition: RomTypes.hh:56
@ ROM_NORMALC000
Definition: RomTypes.hh:62
@ ROM_NORMAL4000
Definition: RomTypes.hh:60
@ ROM_KBDMASTER
Definition: RomTypes.hh:30
@ ROM_RBSC_FLASH_KONAMI_SCC
Definition: RomTypes.hh:41
@ ROM_MIRRORED
Definition: RomTypes.hh:46
@ ROM_ASCII16_8
Definition: RomTypes.hh:15
@ ROM_HARRY_FOX
Definition: RomTypes.hh:27
@ ROM_R_TYPE
Definition: RomTypes.hh:77
@ ROM_NORMAL8000
Definition: RomTypes.hh:61
@ ROM_WIZARDRY
Definition: RomTypes.hh:83
@ ROM_NORMAL
Definition: RomTypes.hh:58
@ ROM_KONAMI
Definition: RomTypes.hh:33
@ ROM_MATRAINK
Definition: RomTypes.hh:42
@ ROM_PLAYBALL
Definition: RomTypes.hh:76
@ ROM_PAGE0123
Definition: RomTypes.hh:74
@ ROM_RAMFILE
Definition: RomTypes.hh:78
@ ROM_MITSUBISHIMLTS2
Definition: RomTypes.hh:51
@ ROM_ASCII8_2
Definition: RomTypes.hh:10
@ ROM_PAGE012
Definition: RomTypes.hh:70
@ ROM_PAGE0
Definition: RomTypes.hh:65
@ ROM_MSXTRA
Definition: RomTypes.hh:53
@ ROM_MIRROREDC000
Definition: RomTypes.hh:50
@ ROM_GENERIC_8KB
Definition: RomTypes.hh:23
@ ROM_KOEI_32
Definition: RomTypes.hh:32
@ ROM_HOLY_QURAN2
Definition: RomTypes.hh:29
@ ROM_MSXWRITE
Definition: RomTypes.hh:54
@ ROM_ASCII8_8
Definition: RomTypes.hh:12
@ ROM_DOOLY
Definition: RomTypes.hh:18
@ ROM_KONAMI_SCC
Definition: RomTypes.hh:34
@ ROM_REPRO_CARTRIDGE1
Definition: RomTypes.hh:35
@ ROM_HOLY_QURAN
Definition: RomTypes.hh:28
@ ROM_ASCII8
Definition: RomTypes.hh:9
size_t size(std::string_view utf8)
std::string_view name
Definition: RomInfo.cc:113
constexpr uint32_t operator()(std::string_view str) const
Definition: RomInfo.cc:158