An Ubuntu MAME cabinet part 1: high scores and shaders on Xenial


This post is intended to replace one I made years ago. It is a summary of simple terminal commands that can be run to compile the most recent stable version of MAME, modified for saved high score support and no nag screens, in the brand new 2016 LTS release of Ubuntu, Xenial Xerus (16.04). It also installs GLSL shaders that give MAME an old-school CRT look, when running on modern LCD screens thanks to OpenGL.

Why bother compiling?

The Web has plenty of advice for getting MAME running on Linux in general and Ubuntu in particular, normally relying on Cesare Falco's PPA for a relatively painless install. I prefer to compile from source because:

  • Specific ROM dumps can be hard to come by, and compiling makes it easy to choose (and stick with) a given MAME release best suited to your available ROMs. With a PPA, you typically get what it gives you.
  • We can tweak the source for nice things like hiscore saving support if we wish, and we do indeed wish that.
  • Compiling is actually really quick and easy, once you know which dependencies you need and what to do (hence this post).

Starting point: Installing Ubuntu Xenial (16.04)

I've used this method with a stock release day amd64 desktop .iso, available from from

When installing, I selected the options "Download updates while installing Ubuntu" and "Install third party software".

I created a user "emulation" with a password, but selected auto-signing in; I'll eventually be using this build in a cabinet and this will be a good enough starting point for later properly spawning a front-end automatically upon boot.

For a brand new install, it's pretty safe and sensible to update all packages to their freshest releases. If you are running this on an existing system, consider whether running this next line is sensible for your specific needs:

sudo apt-get update
sudo apt-get -y upgrade && sudo apt-get -y dist-upgrade

Preparing a build environment

On Xenial, build tools are quite up to date, so the following is sufficient to allow MAME to compile:

sudo apt-get -y install libsdl2-dev libsdl2-ttf-dev libfontconfig-dev qt5-default

Obtain the MAME source code

I'm using MAME 0.172 which was recently released. Download it as a .zip from GitHub and unpack it.

cd mame-mame0172/

When compiling, I found that the system wasn't immediately aware of quite how to connect with qt5, so I modified mame's makefile just a little, adding this line to the end:

echo "QT_HOME=/usr/lib/x86_64-linux-gnu/qt5/" >> makefile

Download the hiscore and no-nag patch

Although hiscore support is coming back to MAME via lua script, at this time the best method is still to apply MKChamp's patch, found at the BYOAC forum where it has been maintained for years. This also gives us the bypass for typing "ok" or waggling a stick each time a new game is started, and seeing useless loading messages.


Alter the windows line endings

Since the MAME code can contain files saved with Windows line endings (\r\n), this is now my preferred line ending fixer to prepare the MAME source for patching and compiling on a Linux machine:

find . -type f -not -regex ".*\.png" -print0 | xargs -0 perl -pi -e 's/\r\n?/\n/g'

Obtain hiscore.dat

At the time of writing, the correct hiscore.dat file that tells MAME how to handle high scores arrives inside a .zip that contains three files available from

unzip hiscore.dat

You also need to make a hi directory for the high scores to be saved into.

mkdir -p hi

With hiscore saving support for old games, not only does it become possible to retain high score tables in the long term, it's pretty easy to share your hiscores across other machines, and with other people too. By saving the hi directory in something like Dropbox, and sharing that folder with your friends, they can point their MAME installs to the same location and try and beat your scores.

Run the patch

patch -p0 < hi_172.txt

If that all went to plan, clean up:

rm hi_172.txt

Start the compile

…and use as many cores as your system has, while you go and prepare yourself a beverage. For more background to this, see the MAME documentation on compiling.

make -j $((1 + $(cat /proc/cpuinfo | grep -c processor)))

Once that completes you should have a mame or mame64 binary ready to run.

At first, though, it's going to look pretty terrible.

Screenshot of Raiden, slightly blurry

The first thing that you could do would be to add "prescale 3" to the config. This can go in mame.ini, or be invoked like ./mame64 -prescale 3 <game> on the command line. That sharpens things up considerably.

Screenshot of Raiden, crisp, bright sprite definition


Scanlines and that CRT feel

In the olden days, when using a non-interlaced screen such as an LCD, we could achieve a pretty decent scanlines effect without much fuss by the old scanlines.png file that used to be distributed with MAME.

Saving that file off my link above to artwork subdirectory and then creating our config will work:

./mame64 -effect scanlines.png -prescale 3 -cc


Screenshot of Raiden, crisp, sprite definition but covered by fine uniform scanline effect

...however it seems the world has moved on quite a bit since I last built a cabinet (circa MAME 0.127) and now it's all done in a much better way with shaders. On Windows, these use HLSL but here on Linux, it's handled using GLSL.

A frequently-referenced and easy-to-follow page on the WWW for installing these shaders is at, which also delivers some useful needed files in a tar.gz.

Read the page, then download and install the shader pack:

tar xzf mame_glsl_osd.tar.gz
rm mame_glsl_osd.tar.gz

Generate a config file for MAME

This one command will write you a mame.ini config file that uses opengl so the shaders will work, and sets up that file to take advantage of the shaders.

./mame64 -video opengl -gl_glsl -gl_glsl_filter 1 -glsl_shader_mame0 $(pwd)/osd/shader/glsl_plain -glsl_shader_mame1 $(pwd)/osd/CRT-geom -cc

Tweaks I make to the shaders

I found I preferred to further adjust the shader parameters. These suit me, your mileage may vary.

Overscan was too heavy

I fixed that with:

sed -i -e 's/\(overscan.*\)1.01,1.01\(.*\)/\11.00,1.00\2/' osd/CRT-geom.vsh

Simulated distance from viewer was too far

sed -i -e 's/ d = 3/ d = 2/' osd/CRT-geom.vsh

Tilt assumes horizontal orientation

The tilt doesn't convert well to vertical games, when playing on a fixed-monitor (mame.ini rotate 1, or default behaviour for a computer screen), so I just don't tilt at all.

sed -i -e 's/\(vec2 angle.*\)-0.15);/\10.001);/' osd/CRT-geom.vsh

Here's what the shaders do for me with the settings above:

Screenshot of Raiden with artificially rounded corners and slight bulging, interlaced effect resembling a CRT television screen


ROM files for various arcade hardware systems and games are readily available from your own physical supply of arcade cabinets and associated dumping equipment. For other suggested methods, see MAME's documentation.

I'm going to assume you have your own source of ROMs compatible with MAME 0.172, and you can install them where MAME can see them (in the roms subdirectory, by default).

If not, you can grab some ROMS which have been released for free, non-commercial use.

Here's one ROM to get you started:

wget -P roms

From here, you should be able to start playing with this:

./mame64 victory

You may omit the ROM name and head straight into MAME's own basic front end UI.


A word about art

Make sure you grab whatever MAME artwork you need as well, from great sites like progetto-SNAPS as well as various convenient torrents. The bezels are great to have for vertical games played with a horizontal monitor, and overlays make a world of difference to some very early games that relied on them to give games colour.

It turns this… Space Invaders in pure black and white raster sprites only …into this:Space Invaders playing within a wider colourful art surround, partially overlaying the play area


Coming soon: Setting up Attract Mode as a cabinet-friendly front end.