Monday, July 29, 2019

How I created my MAME cab

Greetings all,

I have eight arcade game cabinets.  My wife informed me that I had reached my limit.  So in order to have more games, I needed to break down and build a MAME cab (which I hope will evolve into a MAME/Daphne cab in the future).

For whatever reason, the look of the monitor was really important to me.  So I found an existing 25" CRT monitor installed inside of a D&D "Tower of Doom" cab that had a control panel with a ton of buttons on it.  Not only did I like this game, but having 4 joysticks with 4 buttons each was what I needed for a good MAME experience.  The monitor had been tube swapped and recapped so was looking great.  So I brought it home and began working on it to MAME-ize it.

Another important factor for me was to be able to run JAMMA games inside of it in the future if I chose, so I didn't want to mess with the JAMMA harness or the extra kick harness (which was configured for D&D Tower of Doom).

Here are the links that I used for research:
https://ryanfb.github.io/etc/2017/11/11/converting_a_jamma_arcade_cabinet_for_mame.html
https://wiki.arcadeotaku.com/w/Kick_Harness#CPS2_-_3.2F4_Player_Harness
http://bencao74.blogspot.com/2017/05/retropie-15khz-crt-tutorial-for.html
https://www.retrorgb.com/rpi240p.html
https://choccyhobnob.com/compiling-mame-on-raspberry-pi/

I purchased a JPAC and an IPAC4 (which I probably didn't need) in order to get full inputs.  In hindsight, I probably could've got an IPAC2 (or whatever it's called) since I only needed to wire up controls for players 3 and 4.  However, despite the IPAC4 being overkill, it also made setup easier because I didn't need to remap the player 3 and player 4 inputs.




I also purchased a gert666 adapter and the latest Raspberry Pi (3b+ at the time of this writing, the 4 is still hard to obtain).  UPDATE: I can confirm that these instructions do NOT work on the Raspberry Pi 4.



The power supply for your Pi is important.  You can't just get any generic one (I got burned by this) or the voltage to the pi will drop at random spots and your games will go into slow motion mode randomly.  I can confirm that this power supply works well for my Raspberry Pi 3b+.

For audio, I went with this amp which may not have been the best choice because it's a stereo amp and JAMMA cabs are only mono.  I also added this 3.5mm to RCA and this ground loop isolator which was very necessary to reduce unwanted buzz/hum.  I still get some minor hum through my speakers, so I don't really know if my audio choice is to blame or not, but it mostly works and I don't notice the hum while playing games.  I powered the amp through the existing 12V line on the JAMMA power supply that came with the cab.  Not sure if this was the best choice.  I've got a lot to learn about analog audio.


To hook up players 3 and players 4, I referred to the kick harness section for D&D at this link.  I wired up my own connector to match what is on the D&D board, and secured the wires with heat shrink and a glue gun.  Now I feel safe that this thing isn't going to come loose, and if I ever acquire a real D&D JAMMA, I can plug it in and play without any other configuration.



Configuring the software for the Pi was probably the hardest part.

I installed the latest Raspbian ("Buster" at the time of this writing), enabled SSH/Wifi and disabled video overscan.

I tried RetroPi but was unsatisfied with the old version of MAME they included and the way they force input mapping.  So I decided to build the latest MAME from scratch instead.

At the time of this writing, the latest MAME version is 0.211 .

There are a few problems with building this version of MAME on the Pi but I was able to work around them:

  1. Uncomment "NOWERROR = 1" to not fail on warnings
  2. Uncomment "NO_USE_XINPUT = 1"
  3. Uncomment "NO_USE_XINPUT_WII_LIGHTGUN_HACK = 1"
Follow the build instructions here.   When building SDL, you only need to build SDL and SDL_ttf, not the rest of the optional libraries.  In order to build SDL_ttf, use at least v2.0.15 or else you will get errors about a missing freetype-config script.

I tried for several days to get cross-compiling working for MAME but eventually gave up and just followed choccyhobnob's instructions.  Building MAME on the Pi 3 takes forever (like 24-36 hours, literally).  I concluded that letting your pi churn away this long is probably still faster than messing around with cross compilation, so I'd just plan on waiting this long.

NOTE that you need to add "-video accel" to the mame command line to enable the hardware acceleration.  It seems to default to unaccelerated software mode which is too slow.


Once I had the software ready to go, I added this to /boot/config.txt to make the video output 15 khz 320x240 :

# MPO
disable_audio_dither=1
dtparam=audio=on
dtoverlay=vga666
enable_dpi_lcd=1
display_default_lcd=1
dpi_group=2
dpi_mode=87
audio_pwm_mode = 2
hdmi_timings=320 1 16 30 34 240 1 2 3 22 0 0 0 60 0 6400000 1 #240p

I then plugged the gert666 VGA adapter onto the pi, plugged its VGA output into the JPAC VGA input, then plugged the JPAC into the JAMMA harness.  I powered on the cab and got a nice big boot screen.



Running MAME in this res is problematic because it will downscale some games (like Capcom's 384x224) which looks pretty crappy.

I found a neat solution to this problem here.

By running games at 1600x240 or 1600x224 and turning off bilinear filtering, the display looks pretty dang good and you don't need to mess around with a ton of different configs (such as 320x224 or 384x224).  Besides, I couldn't get 384x224 to work on my monitor anyway, so I had to use 1600x224.

I created a few scripts to launch games at the proper resolution.  I haven't yet tried to setup a frontend because I've been trying to get the games looking great first.

My script (to_224.sh) to convert display to 1600x224:

#!/bin/bash

vcgencmd hdmi_timings 1600 1 70 150 215 224 1 10 14 16 0 0 0 60 0 32000000 1
fbset -depth 8 && fbset -depth 16 -xres 1600 -yres 224

My script (to_240.sh) to convert display to 1600x240:

#!/bin/bash

vcgencmd hdmi_timings 1600 1 70 150 215 240 1 4 3 15 0 0 0 60 0 32000000 1
fbset -depth 8 && fbset -depth 16 -xres 1600 -yres 240

My script to convert back to 320x240:

#!/bin/bash

vcgencmd hdmi_timings 320 1 16 30 34 240 1 2 3 22 0 0 0 60 0 6400000 1
fbset -depth 8 && fbset -depth 16 -xres 320 -yres 240

My script to launch Rastan (320x240) :

#!/bin/bash

./to_240.sh
cd code/mame
./mame rastan -video accel -noka -nofilter



My script to launch Golden Axe (320x224):

#!/bin/bash

./to_224.sh
cd code/mame
./mame goldnaxe -video accel -noka -nofilter



My script to launch Teenage Mutant Ninja Turtles (224 lines) :

#!/bin/bash

./to_224.sh
cd code/mame
./mame tmnt -video accel -noka -nofilter



My script to launch D&D Tower of Doom (384x224):

#!/bin/bash

./to_224.sh
cd code/mame
./mame ddtod -video accel -noka -nofilter




You get the idea.

Adding -noka tells MAME to fill the whole screen.  -nofilter tells MAME to disable bilinear filtering to give it that authentic CRT look.  The 1600 pixel width is enough so that the nearest neighbor scaling isn't noticeable (at least to my eyes).

Performance is very good all things considered.  All of the games I mentioned play at full speed except during some busy parts of the game.  Rastan looks especially good.  You'd never know that you weren't playing on the original JAMMA board.

I hope this helps someone :)

PS - You may notice black bars above and below my display.  This is due to the way I've adjusted the monitor pots.  There is some problems with the monitor when certain bright colors are displayed at the top and I decided I'd rather have the black bars rather than have to see the problems.  I don't think this is an issue with my Pi/JPAC config.

Nov 2020 Update:

I tried to go through these instructions again and found a few things I missed.  To setup wifi for a hidden network, follow the instructions you will find online but in your /etc/wpa_supplicant/wpa_supplicat.conf file, be sure to add "scan_ssid=1" or it will not find the hidden network!

To make wifi restart:

sudo wpa_cli -i wlan0 reconfigure

To make game(s) autostart:

Inside /etc/rc.local, add:

# MPO
cd /home/pi
exec ./game_loop.sh

Create a script at /home/pi/game_loop.sh with this:

#!/bin/bash

while :
do
        ./tmnt.sh
        sleep 1
        ./goldnaxe.sh
        sleep 1
done

Hope that helps!