danmons / mame_raspberrypi_cross_compile

MAME Cross Compile Environment
GNU General Public License v3.0
20 stars 2 forks source link

Cross compile MAME for ARM systems like Raspberry Pi on an x86_64 host

About

The MAME project now runs quite well on Raspberry 4 and 5 hardware running 64bit Raspberry Pi OS (itself a derivative of Debian) on an ARM CPU. See benchmarks here:

Compiling MAME on a Raspberry Pi 4 or 5, even with the largest 8GB RAM model available, can take a very long time. The biggest issue being RAM limitations, as running make -j4 can consume far more than 8GB RAM, causing the Pi to swap and crawl to a halt. Compiling with make -j2 works around this, but is slow. Compiling on a much faster x86_64 machine with lots of RAM is much more convienent.

This project uses crosstool-ng to build cross-compilation environments, and allow easy building of the latest MAME binaries for ARM on a fast x86_64 machine.

MAME forks supported

This project supports building the following versions of MAME:

Software versions supported

This repo always aims to build the latest stable release of MAME on the latest stable release of Debian Linux (currently Debian 12 Bookworm, released June 2023).

Support for older releases of either will come down to what software was provided by those distros, and the build-time and run-time requirements of MAME.

At time of writing, Debian 11 Bullseye and Debian 12 Bookworm environments both build and run the latest stable MAME.

Debian 10 Buster will only work with up to and including MAME 0.264 (released March 2024). Versions after this introduced a minimum requirement of SDL 2.0.14 and GCC 10.3, which require substantial manual and unsupported modifications to Debian 10 Buster installs. Additionally, Debian 10 Buster fell out of direct support from the Debian developers as of September 2022, and out of LTS support by volunteer security developers June 2024. It is recommended that users upgrade to a more recent distro. However, the legacy build tools for that system will remain in this repo for the time being, and will likely be removed when Debian 13 Trixie reaches stable release.

Non-Debian distros will very likely run these builds, as long as their internal software is the same or newer than the Debian versions specified. For a list of the software versions needed, see conf/list_ostools.txt.

Installation

Options

mame-cross-compile.sh command line arguments:

Mandatory arguments:

Optional arguments:

Example usage

To download necessary libraries, prepare the cross compile environments, and compile the latest version of MAME to run on a 64bit Raspberry Pi 3/4/5 or Orange Pi 5B running a very recent Debian or Ubuntu distro, you could run:

# Download libraries
./mame-cross-compile.sh -o download -r 12 -a arm64
# Prepare the crosstool-ng environment
./mame-cross-compile.sh -o prepare -r 12 -a arm64
# Compile MAME
./mame-cross-compile.sh -o compile -r 12 -a arm64

If all goes well, a file named something like mame_0.123_debian_12_bookworm_arm64.7z should appear in the build/output folder, and can be decompressed and run on a matching 64bit ARM system and distro.

Running MAME

Copy the .7z file over to your RPi (or other ARM board), decompress and run it. See the official MAME Documentation for further instructions.

You may need to install some extra packages/libraies on your RPi for this to work. I recommend:

sudo apt install -y libfreetype6 libsdl2-ttf-2.0-0 libsdl2-2.0-0 libqt5widgets5 libqt5gui5 libgl1

If you're not interested in compiling these, I build and release them shortly after ever mainline MAME update. Pre-build versions are here:

Compile speed

crosstool-NG can take a while to compile - 30 minutes to an hour per environment (2 environments built, one for 32bit, one for 64bit). However this only needs to be done once to create the build environment. For future versions of MAME, you can keep the existing environment.

MAME's compile time depends on how many cores you assign to the compiler. Be warned that this can consume quite a lot of RAM. It's recommended to install a tool like htop (sudo apt install -y htop) and monitor this as the compile runs. Watch the Mem (Memory/RAM) row, and if the green bar consumes 100%, and the Swp (Swap, or on-disk virtual memory swap) begins to grow rapidly, cancel the compile job immediately with Control+C.

In general, a little over 2GB per core is recommended, although that calculation is not linear due to 4-5 certain compile tasks taking lots of RAM, and many of the others being quite light. In my experiments a 4 core job needed 10GB of RAM and compiled in about 90 minutes, however a 10 core job ran well on 14GB of RAM and compiled in about 45 minutes. Results will vary for your exact hardware configuration and CPU type/generation.

Windows + WSL2

This project is tested and working on Windows 10/11 running WSL2 and the "Ubuntu-24.04" WSL2 environment (itself a convenient virtual machine environment running within Windows).

By default WSL2 will allow a VM to see all logical processors, however it will cap the VM to 50% of the system's physical memory. To change this, stop all runnig VMs by running wsl --shutdown within cmd.exe (not from within a WSL VM). The navigate to %UserProfile% (usually c:\Users\<username>) and create/edit the file .wslconfig. Note this file is prefixed by a period ('.') and has no extension. Within it, add/modify the following section:

[wsl2]
memory=14GB

I recommend making this number your system RAM minus 2GB (the above example is used on my 16GB RAM laptop). Note the Compile speed section section above, and in particular how to monitor your RAM so that you don't swap thrash and kill both your performance and hard disk.

What version of MAME should I run?

The latest version of MAME is always the best version of MAME. There has been a pervasive Internet rumour floating around for years that "older versions of MAME are faster", seemingly stemming from nearly 20 year old builds where 32bit internal rendering was added, which impacted ancient computers and operating systems of the day. In 2006 the best CPUs you could buy were single-core 32bit AMD and Intel chips ranging from around 1.5GHz up to 3GHz, albeit with the Pentium 4 "Netburst" architecture which was horribly slow. Today, a current gen Raspberry Pi 5 or Orange Pi 5 is faster, and almost all GPUs on the market now render in 32bit internally regardless of what old versions of software request.

MAME continues to see considerable improvements in accuracy and quality, and running ancient builds is never recommended. For example, see here in MAME 0.231 in 2021 where a critical game logic bug in the well known "Contra" arcade version was fixed that dramatically changes gameplay in certain sections. MAME 0.245 improved the performance of Cave (famous Japanese shmup developer) games by around 20%. 0.254 greatly improved accuracy of Cave titles even further.

Going backwards to ancient versions of MAME to seek performance improvements rarely works as people expect. Generally speaking it causes endless heartache trying to find older ROM sets, or people find that older builds introduce bugs that were fixed later on, or their favourite games are missing entirely.