I've been playing around with simple command-line-tools in Linux in order to get a list of games using a certain video-resolution. There are probably more efficient ways of doing this, but I'm not very experienced with other solutions (like gawk, pearl/python-scripting) mentioned on the net for this issue, so i stuck mostly to "(e)grep", "sed" and my favourite editor "vi".
I could simply provide an already processed list, but since the gamelist of mame changes as time goes by, I decided to write down the things I did for those of you who might do something similar. This seems to be rather long, but that's only due to the fact that I try to explain everything in detail and noticed that not everything worked out as I planned it in the beginning. So in the end this became sort of a diary.
First of all i wrote the output of the full xml-list of groovymame to a file:
groovymame -listxml> groovymame_output.xml
The resulting file is rather big and I didn't want all information provided, so i used "egrep" to only pick out some of the lines:
egrep -o "<game\ .*|<description>.*|<year>.*|<manufacturer>.*|<display .*|<input.*|<control.*|<driver\ .*|</game>" groovymame_output.xml > groovymame_output_partial.txt
The "-o"-switch tells egrep to only output the exact pattern that was found and not the whole line that contained the pattern. In this example the difference is that the leading indention is removed.
In order to verify if the results a little, I tested how often these sections are found, which can be done with "egrep -c" ("-c" just counts the number of hits)
egrep -c "<game name=\"" groovymame_output_partial.txt
10630
egrep -c "<description" groovymame_output_partial.txt
10630
egrep -c "width=\"[[:digit:]]*\" height=\"[[:digit:]]*\"" groovymame_output_partial.txt
9479
While the number of hits for the short name and the full description was exactly the same, the number of hits for the resolution differed. I looked at the file again and noticed that some games do not list the resolution. Seems like these games are not yet supported but were already added for future releases of mame since their status is set to "preliminary".
More surprisingly some game-entries contain two <display>-tags. Some of them seem to consist of some dual-monitor setup, but as far as I can make out not all of them do. For example try
grep -B 1 -A 50 "Ghouls'n Ghosts" groovymame_output.xml
Sidenote: After creating the file "groovymame_output_re-lined.txt" (Read on a few lines to see how this is done) you can use the following command to get a full list of the 214 games containing two "<display"-lines:
grep "<display.*<display.*" groovymame_output_re-lined.txt | grep -o "<description>.*</description>"
As far as I noticed there are three types of statuses: "good", "imperfect", "preliminary". Additionally there are also clones listed which you might want to sort out as well.
But before I continue I will reformat the text-file in such a way, that all data-fields of each game are listed in one line (one line per game).
tr -d '\n' < groovymame_output_partial.txt | sed -e 's/<\/game>/<\/game>\n/g' > groovymame_output_re-lined.txt
This command-line consists of two commands: The "tr"-part removes all line-breaks and the "sed"-part adds one single line-break after each "</game>".
Now we can search for lines that for example contain the status "good" or "imperfect" and are no clones and redirect them into a new file
egrep "<driver status=\"(good|imperfect)\"" groovymame_output_re-lined.txt | grep -v "cloneof=" > groovymame_output_selection.txt
For me this resulted in a list of 3493 games. I'm a bit surprised that there are so many clones, which makes me a bit unsure that it's recommended to sort them all out. Can somebody maybe comment on this? Do clones sometimes yield advantages over the original versions? Also: Is it not too strict to sort out all preliminary games? Here are some statistics from my grep-results:
cat groovymame_output_re-lined.txt | wc -l
10630
egrep "<driver status=\"good\"" groovymame_output_re-lined.txt | wc -l
6079
egrep "<driver status=\"imperfect\"" groovymame_output_re-lined.txt | wc -l
1478
egrep "<driver status=\"preliminary\"" groovymame_output_re-lined.txt | wc -l
3073
egrep -v "cloneof=" groovymame_output_re-lined.txt | wc -l
5382
Unless I'm doing something wrong here, this means that half of the games are clones. Anyway, I will continue with the above specified selection of "groovymame_output_selection.txt".
We can now use this selection as a good source to do faster, further processing of our choice. For example I wanted to get a list of all resolutions that games use. Here is the command-line i used:
egrep -o "width=\"[[:digit:]]*\" height=\"[[:digit:]]*\"" groovymame_output_selection.txt | sort -ru
This line searches for lines containing the pattern
width="" height=""
with any amount of digits between the quotation-mark. The output of the egrep-command is then handed on to the "sort"-command, which because of the "-ru"-switch sorts the lines in reverse order and removes any duplicate lines. The sorting is not yet perfect, but forget about that for now.
You will get a list of ~206 resolutions. Browse the list a little and notice that there are some very low and rather high resolutions: 22, 64, 1024, 1280
I was curious what these games are about, so I built up a line that finds the description of these games:
egrep "(width|height)=\"(1280|1024|22|64)\"" groovymame_output_selection.txt | egrep -o "<description>.*</description>"
This line searches for lines containing "width"- or "height"-values of the above mentioned, suspicious resolutions.
The whole egrep-output is then handed on to another egrep-command that searches for "<description>.*</description>". The result is a compact list of the long name of all the games with the suspicious resolutions. I looked these games up and as far as I can tell , I can safely forget about these and concentrate on games with width- and height-values with exactly three digits.
Now lets list all resolutions again with this 3-digit-limitation:
egrep -o "width=\"[[:digit:]]{3}\" height=\"[[:digit:]]{3}\"" groovymame_output_selection.txt | sort -ru
This time the remaining resolutions are correctly sorted. You can as well sort for height if you want to:
egrep -o "width=\"[[:digit:]]{3}\" height=\"[[:digit:]]{3}\"" groovymame_output_selection.txt | sort -ru -k 2
Another example of what you can do is to search for games up to a width or height of "288", which is of interest to me because that's the resolution I can use in progressive modes on my scart-tv. This time I will go for the short name and not the full description and redirect the output into some file:
egrep "height=\"[12][0-8][0-8]\"" groovymame_output_selection.txt | egrep -o "name=\"[^\"]*\"" > up_to_288_games.txt
egrep "width=\"[12][0-8][0-8]\"" groovymame_output_selection.txt | egrep -o "name=\"[^\"]*\"" >> up_to_288_games.txt
That list will contain duplicate entries, which can be easily removed. Also I wanted to have nothing but the name itself (no name= and no quotes):
cat up_to_288_games.txt | sort -u | cut -b 7- | tr -d \" > up_to_288_games_cleaned.txt
And to see the number of games:
cat up_to_288_games_cleaned.txt | wc -l
3121
I didn't fully verify the result yet, but it should be correct to the most part of it.
Another list I wanted to have was one of only vertical games that fit the screen of my TV better when it's rotated by 90°. First I thought I can break it down to the resolution: a vertical game should be one, that has a bigger "height" than "width". But that's not right. I started to realize this when looking at games with the same height and width. For example for 480x480 these are "Crate Raider", "Spy Hunter" and "Turbo Tag". When looking at these games at mamedb.com, then you will see that "Spy Hunter" and "Turbo Tag" are vertical games, while "Crate Raider" is a horizontal game. I looked at the xml-data of these games and noticed that "Crate Raider" has a rotate value of "0", while the other two have a value of "90". So is that the key to find vertical games? To be honest I have been in doubt that this is correct for all games.
I took a look at the game "Raiden". I know that this is a vertical game. The resolution of the game is 256x224. Again a proof that vertical games do not necessarily have a greater height-value than width-value. The rotate-value however is "270".
I decided to create a list of all games that have a rotate-value of "90" or "270"
egrep "rotate=\"(90|270)\"" groovymame_output_selection.txt | wc -l
829
egrep "rotate=\"(90|270)\"" groovymame_output_selection.txt | grep -o "<description>.*</description>" > groovymame_output_rotated.txt
I compared a couple of the games with mamedb.com and the results seemed to be rather satisfying. I couldn't make out any horizontal game. However I am not sure if some vertical games are missing.
Remember that my file "groovymame_output_selection.txt" already sorted out all games with preliminary status and that were no clones of some other game. So the last file we created should contain only "good" and "imperfect" emulated vertical games without clones. If you want a purified list without the start- and end-flag of <description>, then use sed to cut these tags of:
sed -i -e 's/<description>//' -e 's/<\/description>//' groovymame_output_rotated.txt
Be careful with that "-i"-switch of sed. It stands for "inplace" and makes sed directly and permanently modify the specified file. Leave "-i" away and you can test the result as it will be shown on standard output. Or redirect the output to a new file like we did before.
Here is a slight variation in case you want to have the same list of games as zip-archives:
egrep "rotate=\"(90|270)\"" groovymame_output_selection.txt | egrep -o "name=\"[^\"]*\"" | cut -b 7- | sed -e 's/\"/\.zip/' > vertical-games-ziplist.txt
I tried more or less the same search with "rotate"-values of "0" and "180" and received 2653 games. Together with the above 829 games this gives a total of 3482 games. However "wc -l groovymame_output_selection.txt" shows a total of 3493. What's up with the 11 missing entries?
egrep -v "rotate=\"(0|90|180|270)\"" groovymame_output_selection.txt | egrep -o "<description>.*</description>"
Except for "Gamball" and "Dr.Who The Timelord" all these entries seem to be system-roms. I tried to run both games (m_gmball, m_bdrwho) which resulted in a segmentation fault of groovymame. So my decision was to forget about both games.
Edit: Skip the rest of this post. I made a dumb mistake which made me thought that the results are incorrect, but as far as I can tell by now they are pretty much fine.
Now back to the results of games with a rotate-value of "0" and "180": Already the very first games I looked up in the mamedb, showed that there are also vertical games among them. So my doubt was justified. Unfortunately I couldn't make out any more complex filtering that would help. For example a rotate-value of "0" and "180" AND higher/lower width-value than height-value didn't work as well.
Some games list a "htotal"- and "vtotal"-value, maybe that would help, but unfortunately only 1385 (of 3493) games list these values. So even in case they would help, this wouldn't bring up a complete list.
At the moment I am clueless. And since all this is becoming a quite long text, I decided to release it for now. Maybe someone got an idea. Feel free to ask any questions - as you might have noticed I somewhat enjoy stuff like this.