-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSupermodel dat maker.html
More file actions
308 lines (272 loc) · 10.9 KB
/
Supermodel dat maker.html
File metadata and controls
308 lines (272 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Supermodel dat maker</title>
<style>
body {
margin-left: 40px;
}
.hidden {
display: none;
}
.show {
display: inline;
}
.div {
margin-bottom: 60px;
}
</style>
</head>
<body>
<div class="div">
<p style="font-size:260%">Supermodel dat maker</p>
<pre id="output"></pre>
<button id="dlbutton" class="hidden">Download Supermodel.dat</button>
</div>
<div id="editorLink" class="hidden">
<p style="font-size:120%">Make Supermodel list only the ROMs you have by editing your Games.xml with this tool,</p>
<p><a href="https://github.com/ToBul/Supermodel-Games-xml-Editor.html">Games.xml editor</a></p>
</div>
<script>
/////////////////////////// Element stuff ///////////////////////////
const outputElement = document.getElementById('output');
const log = (message) => {
outputElement.textContent += message + '\n';
console.log(message);
}
const dlBtnElement = document.getElementById("dlbutton");
dlBtnElement.addEventListener("click", function () {
generateOutput();
});
function toggleHiddenElement(id) {
const showState = document.getElementById(id);
if (showState.className == "hidden") {
showState.className = "show";
} else {
showState.className = "hidden";
}
}
/////////////////////////// Data stuff ///////////////////////////
let datContent = "";
async function buildDat() {
const romsByCrc = await fetchMameFilesFromUrl();
if (Object.keys(romsByCrc).length) {
log(`${Object.keys(romsByCrc).length} Unique CRCs found\n`);
} else {
errorMessage();
alert(`Error creating CRC info\nRefresh the page to try again`);
return
}
await parseGamesxml(romsByCrc);
if (!datContent) {
errorMessage();
alert(`Error creating dat output\nRefresh the page to try again`)
return
}
log(`Operation finished\n`);
toggleHiddenElement(`dlbutton`);
}
async function fetchMameFilesFromUrl(content) {
const romsByCrc = {};
let RomsFound = 0;
const MameUrl = "https://raw.githubusercontent.com/mamedev/mame/master/src/mame/sega/";
const mameDrivers = ["model3.cpp", "segabill.cpp", "model2.cpp"];
const regex = /"(.*?)",\s*0x[0-9a-fA-F]+\s*,\s*0x([0-9a-fA-F]+)\s*,\s*CRC\(([0-9a-fA-F]{8})\)\s*SHA1\(([0-9a-fA-F]{40})\)/;
let len = mameDrivers.length;
for (let i = 0; i < len; i++) {
log(`Fetching content from: ${MameUrl + mameDrivers[i]}`);
const content = await getFileContent(MameUrl, mameDrivers[i]);
if (!content) {
errorMessage();
alert(`Error fetching ${mameDrivers[i]}\nRefresh the page to try again`);
return
}
else {
log(`Finding CRCs and collecting SHA-1 and size info from ${mameDrivers[i]}\n`);
const lines = content.split(/\r?\n/);
for (const line of lines) {
if (line.trimStart().substring(0, 8) == "ROM_LOAD") {
const match = line.match(regex);
if (match) {
RomsFound += 1;
const filename = match[1].toLowerCase();
const romNameArray = [filename];
const size = parseInt(match[2], 16);
const crc = match[3].toLowerCase();
const sha1 = match[4].toLowerCase();
const foundRom = romsByCrc[crc];
if (foundRom) {
if ((romsByCrc[crc].romNames.includes(filename)) == false) {
romsByCrc[crc].romNames.push(romNameArray);
}
} else {
const romInfo = {
romNames: romNameArray,
size: size,
sha1: sha1
}
romsByCrc[crc] = romInfo;
}
}
}
}
}
}
log(`${RomsFound} MAME ROMs parsed`);
return romsByCrc;
}
async function getFileContent(url, file) {
try {
const response = await fetch(url + file);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const fileContent = await response.text();
return fileContent;
} catch (error) {
console.error(`Error fetching ${file}`, error);
return null;
}
}
function errorMessage() {
document.write("<html><head><title>error</title></head><body>");
document.write("<h1>Error!</h1>");
document.write("<p>Refresh the page to try again.</p>");
document.write("</body></html>");
}
async function parseGamesxml(romsByCrc) {
const SupermodelUrl = "https://raw.githubusercontent.com/trzy/Supermodel/refs/heads/master/Config/";
const GamesXml = "Games.xml";
log(`Fetching content from: ${SupermodelUrl + GamesXml}`);
const content = await getFileContent(SupermodelUrl, GamesXml);
if (!content) {
errorMessage();
alert(`Error fetching ${GamesXml}\nRefresh the page to try again`);
return
} else {
log(`Parsing ${GamesXml} and adding SHA-1 and size info to the matching CRCs\n`);
const knownProblemCrcs = "e028d7ca 60aa9d76"; // mgtrkbad roms
const lines = content.split(/\r?\n/);
for (const line of lines) {
if (line.includes(`<game name=`)) {
if (datContent) {
datContent += `\t</machine>\n`;
}
const gameMatch = line.match(/"([^"]*)"/);
datContent += `\n\t<machine name="${gameMatch[1]}">\n`;
}
else if (line.includes(`<title>`)) {
const titleMatch = line.match(/>([^]*)</);
datContent += `\t\t<description>${titleMatch[1]} `;
}
else if (line.includes(`<version>`)) {
const versionMatch = line.match(/>([^]*)</);
datContent += `(${versionMatch[1]})</description>\n`;
}
else if (line.includes(`<year>`)) {
const trimLine = line.trim();
datContent += `\t\t${trimLine}\n\t\t<manufacturer>Sega</manufacturer>\n`;
}
else if (line.includes(`<region name=`)) {
const trimLine = line.trim();
const splitLine = trimLine.split('"');
if (line.includes(`required="false"`)) {
datContent += `\t\t<!--region name="${splitLine[1]}" required="false"-->\n`; // Keep reminding people
}
else {
datContent += `\t\t<!--region name="${splitLine[1]}"-->\n`;
}
}
else if (line.includes(`<file offset=`)) {
const splitLine = line.split('"');
const crcTrim = splitLine[5].replace("0x", "").toLowerCase();
if (romsByCrc[crcTrim])
{
if ((romsByCrc[crcTrim].romNames.includes(splitLine[3].toLowerCase())) == false) {
console.log(`\nMismatch in crc ${crcTrim}\nSupermodel name: ${splitLine[3]}\nMAME driver name(s): ${romsByCrc[crcTrim].romNames.join(", ")}`);
}
datContent += `\t\t<rom name="${splitLine[3]}" size="${romsByCrc[crcTrim].size}" crc="${crcTrim}" sha1="${romsByCrc[crcTrim].sha1}"/>\n`;
}
else {
if (knownProblemCrcs.includes(crcTrim) == false) {
let notFound = `\t\t<rom name="${splitLine[3]}" crc="${crcTrim}"/> <!-- ${`#`.repeat(16)} NOT FOUND IN MAME ${`#`.repeat(16)} -->\n`;
datContent += notFound;
const lineChar = `*`;
log(`${lineChar.repeat(52)} WARNING ${lineChar.repeat(52)}\n\nSupermodel is using a ROM not found in MAME, SHA-1 and size info will have to be added to the dat file manually.\n\n${notFound.trim()}\n\n${lineChar.repeat(113)}\n`);
}
}
}
}
}
}
function generateOutput() {
toggleHiddenElement(`dlbutton`);
toggleHiddenElement(`editorLink`);
// Old bad dumps of Magical Truck are no longer found in mame.
// Do a simple string replace to remove it.
let mgtrkbadFind =
`\n` +
`\t<machine name="mgtrkbad">\n` +
`\t\t<description>Magical Truck Adventure (Japan)</description>\n` +
`\t\t<year>1998</year>\n` +
`\t\t<manufacturer>Sega</manufacturer>\n` +
`\t\t<!--region name="crom"-->\n` +
`\t</machine>\n`;
const date = new Date();
const month = (`0` + `${date.getMonth() + 1}`).slice(-2);
const day = (`0` + `${date.getDate()}`).slice(-2);
let header =
`<?xml version="1.0" encoding="UTF-8"?>\n` +
`<datafile>\n` +
`\t<header>\n` +
`\t\t<name>Supermodel</name>\n` +
`\t\t<description>Sega Model 3 Emulator</description>\n` +
`\t\t<category>Arcade</category>\n` +
`\t\t<date>${date.getFullYear()}-${month}-${day}</date>\n` +
`\t\t<author>Supermodel dat maker.html</author>\n` +
`\t\t<url>https://github.com/ToBul/Supermodel-dat-maker.html</url>\n` +
`\t\t<comment>Matches Supermodel's Games.xml with mgtrkbad removed</comment>\n` +
`\t</header>\n`;
let footer =
`\t</machine>\n` +
`</datafile>`;
let datOutput = header + datContent.replace(mgtrkbadFind, "") + footer;
download(datOutput);
const info =
`mgtrkbad in Games.xml has been omitted from the dat as it does not exist in MAME.\n` +
`mgtrkbad is not a separate game, it's just the old corrupt ROMs that used to be in magtruck.\n\n` +
`To fully build the Supermodel ROM set you will need,\n` +
`model3 ROM set (Mame 0.263 onwards)\n` +
`stcc (from model2)\n` +
`segabill\n\n` +
`Although the dat produced will build ROMS to Supermodel's requirements with the correct\n` +
`parent and child splits, you may still get drive board problems in lemans24.\n\n` +
`lemans24 has 2 force feed back drive boards listed in the Games.xml.\n` +
`epr-18261.ic9 is from stcc.\n` +
`epr-19338a.bin is from scud.\n\n` +
`Supermodel does not yet emulate the stcc ROM as the commands from it are not understood but\n` +
`the scud ROM can be used in it's place. Users need to edit their Games.xml to select which\n` +
`drive board is used.\n\n` +
`Note that drive board emulation is not perfect!\n\n` +
`BTW:\n` +
`Changes or additions to the Model 3 ROM set will be increasingly rare.\n` +
`Most updates to MAME and Supermodel do not touch the ROM set.\n` +
`It should not be necessary to update your ROMs as often as some might think.`;
document.getElementById("output").textContent = info;
}
function download(datOutput) {
//creating an invisible element
let element = document.createElement('a');
element.setAttribute('href',
'data:xml;charset=utf-8, '
+ encodeURIComponent(datOutput));
element.setAttribute('download', "Supermodel.dat");
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
buildDat();
</script>
</body>
</html>