Compiling the Full MAME 0.167 on a Raspberry Pi 2

Successfully compiled the full and complete version of MAME 0.167 on a Raspberry Pi 2.

Why would I want to compile the full version of MAME?  Because it’s the latest version and is continually being updated with more accurate emulation of old hardware.  A lot of the emulation I want is from the early 1980’s and it successfully emulates games and computers of this era at 100%.   Plus it has some really powerful imgtools to work with emulated disks and cassette/cartridge files for the computer emulations.

I’m an old programmer who came from programming my CoCo (TRS-80 Color Computer) in BASIC then I learned 6809 Assembly language.  I have given learning ‘C’ many tries over the years but I always have problems compiling my code once my programs start getting big.  I waste more time fighting with compiling than I do writing my programs in these structured languages, so please don’t think I’m a guru at compiling ‘C’ source code.

I used the help from Steve Boswell and his site listed here and some good compiling info for the Raspberry Pi here and more specifically SDL2 on a Raspberry Pi here.

The MAME source code compiles on the Raspberry Pi 2 without any modification to the source code. You just have to make sure you have the proper libraries installed on the Pi and you give it enough RAM to compile and you are good to go.  It does take a long time to compile, the first “tiny” test build takes 31 minutes.  The main mame compile afterwards took 5 hours and 32 minutes using the make -j4 option which uses all four of the Pi 2 cores.  This is on my Pi 2 overclocked on “Medium” @ 900Mhz.  I did a brand new install of the latest Raspbian build called “Jessie” to a Class 10 – 16 GB microSD card. This version of Raspbian comes with GCC 4.9.

As always update apt:

 sudo apt-get update
 sudo apt-get upgrade

Install the required libraries:

 sudo apt-get install libjpeg-dev
 sudo apt-get install libtiff-dev
 sudo apt-get install build-essential libfreeimage-dev libopenal-dev libpango1.0-dev libsndfile-dev libudev-dev libasound-dev libwebp-dev automake
 sudo apt-get install libgl1-mesa-dev
 sudo apt-get install libqt5widgets5
 sudo apt-get install libqt5qml*
 sudo apt-get install libqt5open*

Install the latest SDL 2.0.4 from https://www.libsdl.org/index.php (under SDL Mercurial):

 cd
 wget https://www.libsdl.org/tmp/SDL-2.0.4-9901.tar.gz
 tar zxvf SDL-2.0.4-9901.tar.gz
 cd SDL-2.0.4-9901
 ./autogen.sh
 ./configure --host=armv7l-raspberry-linux-gnueabihf --disable-pulseaudio --disable-esd --disable-video-mir --disable-video-wayland --disable-video-x11 --disable-video-opengl
 make -j4
 sudo make install

Install the True Type Font handling of SDL:

 cd
 wget http://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.12.tar.gz
 tar zxvf SDL2_ttf-2.0.12.tar.gz
 cd SDL2_ttf-2.0.12
 ./autogen.sh
 ./configure
 make -j4
 sudo make install

Now the main event – get the latest version of MAME and extract it into the mame directory (it is double zipped):

 cd
 wget https://github.com/mamedev/mame/releases/download/mame0167/mame0167s.zip
 mkdir mame
 unzip mame0167s.zip -d mame
 cd mame
 unzip mame.zip

 

Before going crazy and compiling the whole thing lets do a small test and compile the “tiny” subset of games. This will make sure we have the libraries we need and everything else is in place to compile this monster of a program, this took 31 minutes:

 make -j4 NOWERROR=1 SUBTARGET=tiny NO_X11=1 NO_OPENGL=1

While it’s compiling you will see a lot of warnings about assigning UINT8 to UINT32, this is normal – for example:

 ../../../../../src/tools/imgtool/modules/amiga.c: In function ‘imgtoolerr_t set_hash_table(imgtool_image*, int, const UINT32*)’:
 ../../../../../src/tools/imgtool/modules/amiga.c:895:45: warning: cast from ‘UINT8* {aka unsigned char*}’ to ‘UINT32* {aka unsigned int*}’ increases required alignment of target type [-Wcast-align]
 copy_integer_array_be((UINT32 *) &buffer[24], ht, TSIZE);

You can test out these games since they are freely released by the owners of these ROMs.  You can get a copy of these free ROMs from the MAME website here.  Once you have the ROMs you want to test do the following to run them.

For example if you downloaded the game Circus from the Mamedev.org/roms website and the file circus.zip is in your Downloads directory.  You would type the following (still in the mame directory where you compiled the mametiny version of MAME):

mkdir roms
mv ~/Downloads/circus.zip ~/mame/roms/

Once the circus.zip file is in the roms directory you can play the game with the following command:

./mametiny circus -scalemode hwblit

I’ve found that if you don’t tell MAME to use the option “-scalemode hwblit” none of the games run very fast.  But with this option a lot of the old early 80’s games play at 100% speed (see my small list of games and their playback speed down below).  Once you are happy that mametiny is working for you let’s get ready to compile the complete MAME version, as of version 0.162 it also includes the MESS emulator so when you are done you can also use MAME to emulate your favourite old computer.  First let’s give the Pi all the RAM and memory we can:

 sudo nano /boot/config.txt

Change gpu_mem=256 or whatever it is set at and make it gpu_mem=16, then hit CTRL-X and hit Enter

sudo nano /etc/dphys-swapfile

Change CONF_SWAPSIZE=100 to CONF_SWAPSIZE=2048, then hit CTRL-X and hit Enter

It is not good for your SD cards lifespan to keep it this way so don’t forget to change it back after you are done.  I do show you how to set it back to normal below.

sudo reboot

Once your Pi reboots it’s time to compile the complete version of MAME this includes building the tools to help if we are using the Emulator with disk and files for specific old computers this took 5 hours and 32 minutes:

 cd ~/mame
 make -j4 NOWERROR=1 TARGET=mame NO_X11=1 NO_OPENGL=1

To build the tools for using cassette and floppy images with mame’s computer emulation use:

 make -j4 NOWERROR=1 TOOLS=1 NO_X11=1 NO_OPENGL=1

After MAME is compiled you must allocate more RAM to the GPU before you can use it otherwise SDL will give an error when you try to run MAME.  We set the GPU back to normal in the steps below.

Once the compiling is all done lets switch our memory usage back to normal:

 sudo nano /boot/config.txt

Change gpu_mem=16 to gpu_mem=256, then hit CTRL-X and hit Enter

Now lets put he swap space back to normal to extend our SD cards lifespan

sudo nano /etc/dphys-swapfile

Change CONF_SWAPSIZE=2048 to CONF_SWAPSIZE=100, then hit CTRL-X and hit Enter

Now we reboot to take our new changes:

sudo reboot

Once the Pi 2 reboots we are ready to use the full version of MAME.  You will have to look elsewhere on the internet to find ROMs – I can’t help you with that other than the free ones from the mamedev.org website I mentioned above for the mametiny test.

Put your .zip or .7z (either will work fine) versions of your ROMs of old games and computers in the ~/mame/roms folder and play them with the command:

cd ~/mame
./mame coco3 -scalemode hwblit

Here’s some of the results of the complete version of Mame 0.167 compiled on the Rpi 2 and overclocked at Medium 900Mhz.

All games had backgrounds/overlays turned off & run with the following command:
./mame <gamename> -scalemode hwblit

 Game      Speed Percentage
 1942      73.72
 arkanoid  100
 armora    47.78
 asteroid  78.38
 berzerk   100
 ckong     100
 defender  99.98
 galaga    100
 joust     100
 invaders  100
 mooncrst  90.99
 mpatrol   100
 phoenix   98.35
 puckman   100
 robotron  100
 scramble  69.63
 spacduel  59.08
 starcas   91.43

I also successfully ran one computer emulation too:
coco3 – TRS80 Color Computer 3 Emulated and running a cartridge game called Dungeons of Dagorath at 99.99%

If you find a faster way to run the full 0.167 version of MAME on the RPi 2 please let me know in the comments below.

Cheers,
Glen

Advertisements
This entry was posted in Emulation and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s