Getting Started with MAME on macOS - Part 7 - Advanced ROM Verification

Guide Emulators by sky

Logo de MAME

Now that we've covered the basics of ROM verification, let's dive into the details. This article will help you understand the structure of a ROM, how to "repair" them, including when there are small nuances.


1/ ROM Composition

Before seeing how to repair a ROM, let's look at how they are built. It's actually quite simple, as it is a zip file. It is therefore a compressed archive.

Inside this archive, you will find all the elements of the ROMs, all located at the first level.

Because it was too simple so far, let's look at the nuances related to clones and parents. ROM files are organized into three categories: merged, split merged, and non merged.

  • merged: All clone ROMs are grouped into the parent ROM. Each clone has its own subfolder. Ideally, clones only contain elements that differ from the parent ROM.
  • split merged: This is a bit of the historical format. Each parent ROM contains all its files. Each clone, on the other hand, is composed only of the elements that differ from the parent ROM. However, the clone has its own file.
  • non merged: Parents, as well as clones, all have the complete set of files necessary for their proper functioning.

The "non merged" format is practical when you only want a few games in your MAME collection and, as a knowledgeable enthusiast, you are looking for a particular version of one or another game. Thus, you don't have to worry about whether you have the correct parent ROM, etc.

However, as soon as you want a slightly larger collection, this format can quickly take up a lot of space on your disks since all elements are duplicated. In this case, it is preferable to switch to the split merged format. This way, you will save a lot of disk space.

Finally, over the years, the number of ROMs accepted by MAME has multiplied. With nearly 40,000 supported games, this can quickly result in many files in a single folder. While this poses no issue for macOS, for us, it can be complicated to find a ROM.

To address this issue a bit, it is preferable to use the merged format.

Don't worry, if your collection contains ROMs in three different formats, it will still work. It's just... a bit less neatly organized. However, be careful: it may happen that you have a merged version and a split version of the same clone. As far as I know, MAME checks both versions to retrieve the one considered correct. Be careful when cleaning up ROMs not to discard the correct version.

Finally, there is a fourth format, used only for ROM updates.

  • diff: this somewhat particular format only contains the elements that change between two versions. This can be useful when updating a version to update your collection without downloading the full ROMs. However, you will need to merge them for them to work. There are tools that do this job, but the goal here is to know how to do it manually. Moreover, since I haven't tested these tools yet, I won't be able to recommend any.


2/ Repairing ROMs

Repairing a ROM involves merging multiple versions while keeping only the correct elements each time to obtain a final correct version.

Whether you retrieve a ROM update in diff format or by searching for ROMs online, you will have multiple versions of the same game. If none of the versions are correct, it may be possible to repair and thus use the ROM by combining the elements of the different ROMs.

Repairing a ROM from multiple versions requires some rigor. Indeed, you will have multiple copies of the same elements and you must not make a mistake and keep only the correct ones.

The first thing to do is to find the missing, damaged, or obsolete elements. This is quite easy as they are all the lines displayed before the result when performing a verifyroms, which we covered in the first part of the article.

So if you test the ROM `sf2cems6b` with
mame -verifyroms sf2cems6b
and you get
sf2cems6b   : ms6_gal20v8a.u104 (343 bytes) - NOT FOUND
romset sf2cems6b [sf2ce] is bad
1 romsets found, 0 were OK.
you will need to find the piece `ms6_gal20v8a.u104`. If you have another ROM and the verification result gives
sf2cems6b   : ms6_gal20v8.u234 (343 bytes) - NOT FOUND
romset sf2cems6b [sf2ce] is bad
1 romsets found, 0 were OK.
despite their similarity in name, these are two different elements. You just need to take a piece from one and place it into the other or vice versa. To do this, simply decompress the two files, copy the relevant piece, and then recompress the ROM. Recompression can be done using the built-in macOS tool by right-clicking on the folder and selecting "Compress." It is preferable to set aside the original ROMs for two reasons. The first is that if you make a mistake, you will always have your original sources. The second is that during recompression, macOS will add a "2" to the end of the ROM title, so it will not be recognized by MAME. Basically, I encourage you to create a dedicated folder for editing ROMs. It may seem tedious, but the small effort required will limit many errors.


3/ Small nuances

Now let's look at the small nuances that might cause you trouble.

When a ROM is not functional, you must be very attentive to the error obtained.

So, if the result of the following verification

mame -verifyroms knightsb2

is

knightsb2   : sound.code.512 (65536 bytes) - NOT FOUND (knights)
romset knightsb2 [knights] is bad
1 romsets found, 0 were OK.

The ROM `knightsb2` is a clone of `knights` and by looking at the line related to the missing file, you can see that in parentheses, the name of the parent ROM is indicated. This means the error comes from the parent, not the clone.

The same principle applies to BIOS files, so if the verification of the ROM neodrift

mame -verifyroms neodrift

returns the following error

neodrift    : sfix.sfix (131072 bytes) - NOT FOUND (neogeo)
romset neodrift [neogeo] is bad
1 romsets found, 0 were OK.

you should check the neogeo BIOS.

Let's look at another case with the following test:

mame -verifyroms popn1

which yields the following result for me:

popn1       : 803jaa11 - NOT FOUND
romset popn1 is bad
1 romsets found, 0 were OK.

You can obtain all popn1.zip ROMs, but you will never find the element 803jaa11 inside them. This is simply because the file 803jaa11 is a CHD and must be located in the CHD folder.

To fix this issue, it is necessary to place the CHD file in the correct folder.

 

4/ Finding Elements in Your Existing ROMs

Here is a useful tip. Sometimes, it is possible to fix a ROM by retrieving the missing element from a very similar ROM.

For example, taking the previous example again:

mame -verifyroms sf2cems6b

with the result:

sf2cems6b   : ms6_gal20v8.u234 (343 bytes) - NOT FOUND
romset sf2cems6b [sf2ce] is bad
1 romsets found, 0 were OK.

You just need to search through adjacent ROMs to sometimes find the element that is identical for both.

Thus, if I retrieve the piece ms6_gal20v8.u234 from the ROM sf2cems6a and place it in sf2cems6b, I obtain the expected result:

mame -verifyroms sf2cems6b
romset sf2cems6b [sf2ce] is good
1 romsets found, 1 were OK.

The method may seem a bit crude here, but it is possible to do this with more rigor and efficiency using MAME commands and some terminal tricks. Here’s the translation:

Here’s a simple step-by-step guide.

First, let’s retrieve the list of components for our non-functional ROM

mame -listroms sf2cems6b

The result is a complete list

ROMs required for driver "sf2cems6b".
Name Size Checksum ms6b.u0 262144 CRC(b6f3724b) SHA1(aa8eea819fdaf205ca068067a4624715a8cf6c8c) ms6b.44 279 CRC(5f05a861) SHA1(26b8cab0e66b596ef54768b2811c1c1939d3135c) ms6b.u196 1048576 CRC(435153d5) SHA1(3f6f318a9b3def8d62ee576dbaaef623d55c1c64) ms6b.u10 262144 CRC(c812b7b2) SHA1(23ed0e1bd8b2015b39ad5e452dff0e372df0d5c9) ms6.u70 1048576 CRC(baa0f81f) SHA1(5e55a5c4ad64be17089670a3d73c1c0d9082351b) ms6.u68 1048576 CRC(8edff95a) SHA1(8db35c5940dcc1f09f11be26051b2f98445d10e7) ms6.u69 1048576 CRC(468962b1) SHA1(fdfd2a7cbbcafaa37e972da425446d471e1e1dae) ms6.u64 1048576 CRC(8165f536) SHA1(8178fe2240c73c7283592aa31dd24aec5bf9429b) ms6.u19 1048576 CRC(39d763d3) SHA1(a2a0bddecaca6046785ccddfd20b8356a6ec36f0) ms6.u18 1048576 CRC(2ddfe46e) SHA1(517a76166d387375a75a36b2785de86898bdc777) ms6.u31 262144 CRC(35486f2d) SHA1(abdcfc73d2d42a7f3523e1a383c1ce5563c4fbd7) ms6.u29 262144 CRC(e4eca601) SHA1(acee4988f12a037a3b50f3923892fdac65f35805) ms6.u191 65536 CRC(08f6b60e) SHA1(8258fcaca4ac419312531eec67079b97f471179c) ms6.u210 262144 CRC(6cfffb11) SHA1(995526183ffd35f92e9096500a3fe6237faaa2dd) ms6.u133 65536 CRC(13ea1c44) SHA1(5b05fe4c3920e33d94fac5f59e09ff14b3e427fe) ms6_pal16l8.u173 260 NO GOOD DUMP KNOWN ms6_pal16l8.u176 260 NO GOOD DUMP KNOWN ms6_pal16l8.u177 260 NO GOOD DUMP KNOWN ms6_pal16l8.u178 260 NO GOOD DUMP KNOWN ms6_pal16l8.u183 260 NO GOOD DUMP KNOWN ms6_pal16l8.u198 260 NO GOOD DUMP KNOWN ms6_pal16l8.u218 260 NO GOOD DUMP KNOWN ms6_pal16l8.u231 260 NO GOOD DUMP KNOWN ms6_gal16v8.u6 279 NO GOOD DUMP KNOWN ms6_gal16v8.u95 279 NO GOOD DUMP KNOWN ms6_gal16v8.u96 279 NO GOOD DUMP KNOWN ms6_gal16v8.u107 279 NO GOOD DUMP KNOWN ms6_gal16v8.u125 279 NO GOOD DUMP KNOWN ms6_gal16v8.u139 279 NO GOOD DUMP KNOWN ms6_gal16v8.u151 279 NO GOOD DUMP KNOWN ms6_gal16v8.u245 279 NO GOOD DUMP KNOWN ms6_gal20v8.u15 343 NO GOOD DUMP KNOWN ms6_gal20v8.u16 343 NO GOOD DUMP KNOWN ms6_gal20v8.u20 343 NO GOOD DUMP KNOWN ms6_gal20v8.u21 343 NO GOOD DUMP KNOWN ms6_gal20v8.u39 343 NO GOOD DUMP KNOWN 343 NO GOOD DUMP KNOWN ms6_gal20v8.u40 343 NO GOOD DUMP KNOWN ms6_gal20v8.u104 343 CRC(67b56d29) SHA1(261ae6e968100d5a9c1ee68ea684bb2b1eef3cf8) ms6_gal20v8.u131 343 NO GOOD DUMP KNOWN ms6_gal20v8.u135 343 NO GOOD DUMP KNOWN ms6_gal20v8.u140 343 NO GOOD DUMP KNOWN ms6_gal20v8.u232 343 NO GOOD DUMP KNOWN ms6_gal20v8.u233 343 NO GOOD DUMP KNOWN ms6_gal20v8.u234 SHA1(f73ad0253a861d5306a09b1f97dfce622b19cdcf) ms6_gal20v8.u235 343 NO GOOD DUMP KNOWN ms6_gal22v10.u50 741 CRC(dc665408) SHA1(a7161a03add24a01d547189e9bfaf11474bbe878) ms6_gal22v10.u134 741 CRC(b66848bb) SHA1(edef02bc7fc0195f56cf815c1b862bee095951c8)

As you can see, the element ms6_gal20v8.u234 does not have a size or CRC but it does have a SHA1. To remind you, it's this SHA1 that MAME compares to verify that the ROM components are indeed the expected and correct ones.

Now let's use the same command to check in sf2cems6a. You should find the famous element ms6_gal20v8.u234. If it has a size and a CRC, it means it is present. If the SHA1 is identical for both, you'll be able to copy it to make the defective ROM work.

Now let's use macOS Terminal features to simplify the search. With the grep command, you won't have to retrieve all lines. Let the Mac do the searching for you. Here is the command:

mame -listroms sf2cems6a | grep ms6_gal20v8.u234

For information, the character | is typed with Option+Shift+L. And here is the result:

ms6_gal20v8.u234         343 CRC(2c16b7c6) SHA1(f73ad0253a861d5306a09b1f97dfce622b19cdcf)

grep returned only the line containing the text ms6_gal20v8.u234.

And since we're even lazier, we don't want to search through all the ROMs one by one but let the Mac do this unpleasant work for us. To do this, simply use the * character as a wildcard. This character will replace one or more characters in the ROM names.

Thus, I can make it search through all ROMs that start with "sf2ce".

mame -listroms "sf2ce" | grep ms6_gal20v8.u234

Note the double quotes around "sf2ce". Unfortunately, the result is not very satisfying

ms6_gal20v8.u234         343 CRC(2c16b7c6) SHA1(f73ad0253a861d5306a09b1f97dfce622b19cdcf)
ms6_gal20v8.u234             SHA1(f73ad0253a861d5306a09b1f97dfce622b19cdcf)
ms6_gal20v8.u234         343 CRC(2c16b7c6) SHA1(f73ad0253a861d5306a09b1f97dfce622b19cdcf)

Indeed, the element has been found, but we don't know in which ROM. We do know, however, that the second line corresponds to our defective ROM since the element is not present there.

Let's improve the command as follows:

mame -listroms "sf2ce*" | grep "ms6_gal20v8.u234|driver"

Thus, we search for either the element or the first line of the response containing the word "driver".

ROMs required for driver "sf2ce". ROMs required for driver "sf2ceb". ROMs required for driver "sf2ceblp". ROMs required for driver "sf2cebltw". ROMs required for driver "sf2ceds6". ROMs required for driver "sf2ceea". ROMs required for driver "sf2ceja". ROMs required for driver "sf2cejb". ROMs required for driver "sf2cejc". ROMs required for driver "sf2cems6a". ms6_gal20v8.u234         343 CRC(2c16b7c6) SHA1(f73ad0253a861d5306a09b1f97dfce622b19cdcf)
ROMs required for driver "sf2cems6b". ms6_gal20v8.u234             SHA1(f73ad0253a861d5306a09b1f97dfce622b19cdcf)
ROMs required for driver "sf2cems6c". ms6_gal20v8.u234         343 CRC(2c16b7c6) SHA1(f73ad0253a861d5306a09b1f97dfce622b19cdcf)
ROMs required for driver "sf2cet". ROMs required for driver "sf2ceua". ROMs required for driver "sf2ceub". ROMs required for driver "sf2ceuc". ROMs required for driver "sf2ceupl".

Thus, we know in which ROMs the search was performed and in which it was found.

You can perform searches as you wish using the wildcard anywhere in the ROM name, including at the beginning or in the middle of the name.

Just keep in mind that the wider your search across many ROMs, the longer it will take.

At the extreme, you can launch the search on all available ROMs, but if you have a fairly complete collection, you may have to wait several minutes, or even several tens of minutes, before seeing the end of the command. Moreover, you will obtain the complete list of your ROMs interspersed with one or two results that you will need to find again.

In the previous case, the elements were found in almost identical ROMs. But you should know that some components are generic and are found in a multitude of ROMs that have nothing to do with each other.

Once found, you can set them aside to retrieve them whenever necessary. Here is my small list of these elements:

  • 317-0034.key
  • 75585130_gal20v8c.ic29
  • ioc1.ic1
  • ioc1.ic7
  • u01508001100b.u20f

I will not hesitate to update this list if I come across other components that are found in multiple ROMs.


5/ Multiple Verification

If you can keep up, here is the final step of our advanced verification. We will see here how to perform grouped verifications to save even more time.

By launching the following command

mame -verifyroms

you will perform the verification of all your ROMs. And this will take some time.

Since functional ROMs are not of interest to me in this case, here is a modified command to retrieve only the defective ROMs:

mame -verifyroms | grep 'is bad'

Finally, as I do not plan to fix all my ROMs at once and do not want to re-run the command every time, I will register the result in a file.

mame -verifyroms | grep 'is bad' > verif_roms.txt

The results will be written in the text file verif_roms.txt, in the current directory. And the only result you obtain in the terminal is the final count, which should look something like this:

36691 romsets found, 36601 were OK.

With this result, I have 90 ROMs that are no longer valid and need to be fixed.

Now all you have to do is take the ROMs from the 90 lines of the file to verify and correct them one by one. Don’t forget to remove the corresponding lines as you go, so you don’t repeat the same verifications multiple times.

Can we still optimize this and save some time? The answer is yes.

There are two things to look at in our list. The first is that MAME tends to verify BIOS only after the ROMs. Often, updating the BIOS makes the ROMs that use them functional again.

You’ll find them easily at the end of the file. ROMs are tested in alphabetical order by filename, just like BIOS. Thus, the BIOS appear after an alphabetical break.

You can also test all ROMs linked to a BIOS at once to save time. For example, if you’ve just corrected your neogeo BIOS, you can test all the games in your list whose line ends with [neogeo].

mame -verifyroms garou mslug mslug2 neodrift

with the following result if everything goes well:

romset garou [neogeo] is good
romset mslug [neogeo] is good
romset mslug2 [neogeo] is good
romset neodrift [neogeo] is good
4 romsets found, 4 were OK.

You can then remove the lines corresponding to these 4 games.

Next, in the same vein, you need to look for clones and parents. If there are many of them present, it’s often the case that the parent is defective, and fixing it will also repair many, if not all, of the clones.

And there you have it, you now have all the tools to maintain your MAME ROM collection.

Related software

Reply on the forum

A question or a hands-on report? Open the discussion on the forum.

Reply on the forum