Raspberry Pi MAME & MESS
2012-11-13 13:13 By Jason Birch
How to compile MAME (Arcade Game Emulator) & MESS (Computer System Emulator) source code to run on the Raspberry Pi.
MAME is an emulator which allows original arcade game software to be played on a desktop computer. All that is required is the source code for the MAME emulator, which needs to be compiled and linked on the system where it is to be run, and original ROM images, which is the software which ran originally in actual arcade machines.
The MAME software and each ROM image have a license agreement which legally needs to be adhered to. The license agreement for each ROM image is individual, the company which owns the ROM image is responsible for granting a license for the image.
The license agreement for the MAME emulator should be found with the source code and can also be found here: http://mamedev.org/legal.html
Raspberry Pi OS
In order for the Raspberry Pi to run it requires an OS on an SD card. These instructions have been written and tested with regard to the Arch Linux OS. The Arch Linux OS and instructions on how to write it to an SD card can be found on the official Raspberry Pi web site here: http://www.raspberrypi.org/downloads/
Place the SD card with OS image written to it, into the Raspberry Pi. And power on the Raspberry Pi. Login by typing the user 'root' and 'root' as the password because the password has not been set yet. The first thing to do is set a root password by typing 'passwd' and pressing enter. You will be prompted to enter a password for root and confirm the password.
In order for sound to work, the sound driver needs to be loaded when the root user logs in. Also to prevent the display going to sleep after a period of time, the setterm command is also added to the script. I would personally use a program called vi to edit text files, however for simplicity I would recommend using nano for people not familiar with vi. Create a login script using nano by typing the following, (^O means hold CTRL key while pressing O key):
setterm -blank 0
^O ENTER ^X
OS Package Update & Install
Before proceeding the OS and OS packages need to be updated to the current versions. Plug-in a network cable and ensure the network is connected by typing:
ip link set eth0 up
Update the current OS and packages by typing:
Now reboot the Raspberry Pi to ensure any kernel updates are running, by typing:
Install the development packages required to build source code by typing the following. Install all of the packages:
pacman -S base-devel
Install the video drivers for the Raspberry Pi:
pacman -S xf86-video-vesa
pacman -S xf86-video-fbdev
Install the audio drivers:
pacman -S alsa-lib
Install the SDL drivers. Install all of the packages:
pacman -S sdl
pacman -S sdl_sound
NOTE: If an error occurs whilst installing packages, try updating the package lists again with the command 'pacman -Syu'. Then retry installing the package.
The source code building process requires more than 256MB of RAM. I built the source code using a 256MB Raspberry Pi, to do this you will require a swap file to simulate more memory. I would recommend this even if you are using a 512MB version of the Raspberry Pi to be safe as, memory can be split between the CPU and the GPU. To generate a swap file, type the following:
dd if=/dev/zero of=/SWAP.SWP bs=1M count=256
NOTE: If the Raspberry Pi is rebooted at any time the swap file will be disabled by default and the command swapon /SWAP.SWP will have to be issued again to start using the swap file again. Also after building the software has completed successfully the swap file should be deactivated and removed by typing swapoff /SWAP.SWP ; rm /SWAP.SWP
Download MAME Source Code
There is a full set of source code with the configuration required for the Raspberry Pi, including a Raspberry Pi GPIO joystick driver, on GitHub. To download it type the following commands:
pacman -S unzip
If you use this set of source code you can now go straight to the compile and link section of this document as the configuration of the build has already been done.
Alternativly you can get the source code from the original location, if you do this the build configuration will need to be done and the Raspberry Pi GPIO joystick driver will not be present. To do this continue reading this section of the document.
Download the source code for XMAME from the following location onto your desktop computer as it requires an authentication code to be entered. If the source code is no longer available at this URL there are alternate locations which can be found by searching Google for XMAME:
Copy the source code onto the Raspberry Pi by typing the following command. On Windows you will required the Putty pscp command rather than scp which is a Linux command. pscp can be downloaded here: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html. Replace the IP address [IP_ADDRESS] (e.g. 192.168.1.100) in the command with the current one on the Raspberry Pi, which can be found typing 'ifconfig eth0 | grep inet'.
scp xmame-0.103.tar.bz2 root@[IP_ADDRESS]:/root/
Change to the home directory and uncompress the source code by typing the following.
tar -xf xmame-0.103.tar
Configure MAME Build
When building software for Linux, the process is usually very similar for any software package being built. First configuration options need to be set if required. In this case they do because XMAME is usually built for an Intel x86 processor. The Raspberry Pi has an ARM RISC processor. Edit the build configuration file by typing:
In the file find the text 'MY_CPU = i386' by typing ^W (^ means hold CTRL key while pressing W key), and then typing 'MY_CPU = i386' and press the enter key. Comment out the line by placing a '#' character at the start of the line, so the line looks like this:
#MY_CPU = i386
Find the text 'MY_CPU = risc_lsb'. Uncomment the line by removing the '#' character from the start of the line, so the line looks like this:
MY_CPU = risc_lsb
Find the text 'SOUND_ALSA = 1'. Uncomment the line by removing the '#' character from the start of the line, so the line looks like this:
SOUND_ALSA = 1
Find the text 'SOUND_SDL = 1'. Uncomment the line by removing the '#' character from the start of the line, so the line looks like this:
SOUND_SDL = 1
Find the text 'DISPLAY_METHOD = x11'. Comment out the line by placing a '#' character at the start of the line, so the line looks like this:
#DISPLAY_METHOD = x11
Find the text 'DISPLAY_METHOD = SDL'. Uncomment the line by removing the '#' character from the start of the line, so the line looks like this:
DISPLAY_METHOD = SDL
Save the file and exit nano by typing '^O ENTER ^X'.
Compile & Link
Compile and link the source code by typing the following. On a Raspberry Pi the build process takes ~7.5 hours. This can be significantly reduced by overclocking the Raspberry Pi.
NOTE: If the build has succeeded there will be a file called xmame.SDL in the directory, check by typing 'ls -lart'. If the file does not exist, check the swap file is active by typing 'swapon -s'. If the swap file is not active, activate it and recompile the source code. If the swap file is present the files in the /var/log directory are the first place to look to resolve the error, however at this point experience with Linux would be helpful. Once you think you have resolved the issue, just type make again and the compile will resume where it failed. Or if the fix requires the build to start from scratch type make clean first.
Starting a Game
First the xmame.SDL application needs to create it's own environment in /root/. To do this type './xmame.SDL'. Type 'ls -lart /root/.xmame/' this should list the files and directories the application created.
Copy the built application into the home directory by typing:
cp xmame.SDL ~/.xmame/
Also create a directory for ROMs by typing:
Download the ROM images which you are licensed to use from a site which can be found using a Google search, onto your desktop PC. Place them in the directory /root/.xmame/roms/ by using scp or pscp again as follows:
scp *.zip root@[IP_ADDRESS]:/root/.xmame/roms/
You should now be able to start one of the games by typing the following, where [ROM_NAME] is the name of a ROM zip file, excluding the .zip part of the filename. If you compiled the souce code without the Raspberry Pi GPIO joystick adapter you will need to remove the option -jt 6:
./xmame.SDL -rp /root/.xmame/roms/ -jt 6 -ef 2 [ROM_NAME]
This should start the game full screen with sound. Press '5' for credits and '1' for a one player game or '2' for a two player game. Typically cursor keys and CTRL, ALT and SPACE are the controls. Press the TAB key for options.
Configure & Compile & Run MESS
To configure compile and run MESS, the process is the same except in the build configuration file the following lines also need to be modified:
Find the text 'TARGET = mame'. Comment out the line by placing a '#' character at the start of the line, so the line looks like this:
#TARGET = mame
Find the text 'TARGET=mess'. Uncomment the line by removing the '#' character from the start of the line, so the line looks like this:
The MAME emulator performs well for simple games, more complex games can struggle. However over clocking the Raspberry Pi can make some of the more complex games run relatively smoothly. Over clocking should only configured if you fully understand the implications and risks. Information can be found here http://elinux.org/RPiconfig