How to compile MAME (Win32)



Compiling means rebuilding the actual executable program from its source code. MAME is almost fully written in C, with some assembler hacks in speed-critical places. The Win32 version of MAME is compiled with MinGW, which is the minimalist Win32 port of a C compiler called GCC and its libraries.

This particular how-to is written for MAME 0.61, but with a bit of luck you can compile other versions with the help of this page. This how-to tells how to compile the Win32 version of MAME, so if you need to compile MAME32 (practically the same, but with a GUI), take a look at http://www.hypertech.com/mame/ or http://www.mameworld.net/compile32/ (a little more recent).

The MinGW development environment will be installed to C:\MINGW and MAME sources will be placed into C:\MINGW\MAME. Before beginning, you should make sure that you do not have the directories c:\mingw\ and c:\download\ yet. If you do have them, rename them to another name or simply delete them (if you are sure that there aren't any important files in there).

Remember, when you type commands into the command prompt, you should avoid making typos ;-) In this how-to, filenames and other static text are marked with the color yellow and command lines or other information that you need to type in are marked with the color green. Last updated: 18th July 2002.


1. get unzip

First of all, most files that are transferred over the Internet are compressed, to minimize download times and bandwidth costs. You might already have a Windows-based uncompressing utility, but since compiling MAME is done in a command prompt, a different kind of utility is necessary. Download the following file into the directory c:\windows\command\ so that the utility is accessible from any directory.

File name File size Description
unzip.exe 140 kB This is the Info-ZIP uncompressing utility called UnZip/NT v5.41.


2. get mingw

Then you need the MinGW files. Make a new directory, for example c:\download\ and download the following files into that directory. Note that there may be newer versions of these files, but MAME is not verified to compile with any other versions of the following files.

File name File size Description
mingw_for_mame.zip 5517 kB This is the MinGW compile environment for use in Windows.


3. uncompress mingw

Next we will uncompress the MinGW files and set up some environment variables so that MinGW is functional. Open up a command prompt. You can find it either from under Start Menu - Programs, or you can simply select Run and type command.com into the dialog box. When you have it open, type cd \download and hit enter to change to the correct directory. After that, type

  • unzip mingw_for_mame.zip -d c:\ and hit enter

    to start uncompressing the MinGW files.

    If you do not see the message "1 archive was successfully processed.", re-download the archives. If you get a "Bad commmand or file name", verify once again that you have unzip.exe in c:\windows\command\


    4. set up mingw

    Next we will have to set up the environment variables. To make the changes permanent, we will have to edit AUTOEXEC.BAT, which is a file that always gets run before Windows starts up. Type edit \autoexec.bat and hit enter. There might be a lot of things in there, so do not touch anything else than what you are told to.

    Find the line which says something like PATH C:\WIN98;C:\WIN98\COMMAND (there might be some other directories defined after these two). Add ;C:\MINGW\BIN to the end of that line, so that it will look like PATH C:\WIN98;C:\WIN98\COMMAND;C:\MINGW\BIN (again, there might be something extra in there, leave them as they are). Take note that if you have added C:\DJGPP\BIN into that line, you should remove it. Now you can save the file (ALT-F then S) and quit (ALT-F then X) (These might differ depending on your language version of Windows). Then you will need to reboot your computer, to make the changes effective.

    With systems that don't use startup files (such as Windows NT, 2000 or XP), you can instead type edit c:\mingw\mingw.bat and write SET PATH=%PATH%;c:\mingw\bin into it. You'll have to run this file (simply type c:\mingw\mingw to run it) before being able to use MinGW.


    5. compile mame

    Now you can compile MAME. Download the source ZIP into c:\download\

    File name File size Description
    mame061s.zip
    5930 kB Source code archive of MAME 0.61.

    Go to the download directory by typing cd \download and uncompress the MAME sources by typing unzip mame061s.zip -d c:\mingw\mame\. Usually the MAME sources are compressed twice to squeeze them into an even smaller space. Go to the MAME source directory by typing cd \mingw\mame and uncompress the second zip by typing unzip *.zip

    When the uncompressing is done, you might want to delete the second zip by typing del mame.zip (This is not necessary if you are sure you have enough space on your drive). Then you can compile MAME. Type make and hit enter. This will finally compile MAME itself. If you want to compile the CPU optimized versions, type make I686=1 or make K6=1 instead of just make. It will take a lot of time, ranging from 15 minutes to an hour depending on your CPU speed, so go get yourself something to drink.

    When the compilation is done, you can type dir. You should see a brand new MAME.EXE in there.

    To be able to use MAME, you should make the directories that MAME expects to exist. Type md artwork, md cfg, md hi, md inp, md memcard, md nvram, md roms, md samples and md snap. You also need to make the INI file, by typing mame -cc (an abbreviation of -createconfig).

    Congratulations, you did it!


    6. a new mame appeared

    To successfully compile a new version of MAME, you should NOT uncompress a new set of sources over an old version of MAME. Instead, rename the MAME directory to another name or simply delete it totally (if you are sure that nothing important is there), and then uncompress the new set of sources to an empty directory.


    7. then what..

    Of course, the biggest advantage of building your own binary is the possibility to tinker around with the source files. For example, to try out drivers which are not fully working yet, take a look at the file src\driver.c with a normal text editor (like EDIT). The disabled drivers are marked with the text TESTDRIVER. Simply remove the TEST part from a driver you want to test, save the file and type make again. Remember, the license forbids you from redistributing binaries that contain games which are disabled in the official versions. Naturally, there should not be any reasons to redistribute such binaries since this page makes it easy for everybody to build their own binaries.

    You might notice that the UPX part takes an obscene amount of time. The simplest solution to avoid it is to just rename upx.exe to another name. If you do that, the make utility will give you an error and the file MAME.EXE is about 12 MB, but it will work fine.


    8. debug modes

    To include the debugger functionality in your MAME executable, edit makefile. Near the top you will see a text like "uncomment next line to include the debugger". Remove the # character from the next line, so that it only has DEBUG = 1 in that particular line. Save the file, type make clean and then make. To actually use the debugger, edit MAME.INI and find the line that says debug = no. Change it to debug = yes and save the file. In MAME, hit tilde ( ~ ) or key to the left of the key  1  to enter the debugger.