Home Security Engineering Projects Research
http://blog.tornadovac.com

YAMB

This project is Yet Another Mame-box. :)

The objective was to put Mame onto a Raspberry Pi, route the pins to buttons and joystics, and put all the bits into a half-height arcade box. I wanted to do all of this with the least amount of thinking possible.

Some quick lessons learned:

Overview

I used the instructions at Adafruit as my general guide.

There are three essential components to the build:

Box Construction

I had no intentions to build a container for the game that would make a purist happy. Rather, I wanted something that approximated a box without having to do too much work. The kluge that resulted is perfectly functional if rudely implemented.

I downloaded a design off the web (I can't remember from where), pasted it to pine that I got from Home Depot, and used a jigsaw and my bandsaw to hack out the form. I found an old LCD monitor in my closet and bought coloured game switches from a local store. The joysticks were not as easy to come by locally. I ordered a pair like the one shown below from Robotshop.com:

The figure below shows the result of my handiwork from the front. There are two player stations (left and right), two buttons for 1 and 2 player, and a red button on the bottom which simulates the dropping of quarters into the slot (F5 in MAME). There is also a little red square button on the bottom which issues the "Escape" key to MAME to boot it out to the command prompt. I didn't really need that button since I plan to leave a wireless mini-keyboard in the box for when I need to do maintenance and it has its own escape key.

The black box on the top is a neat little speaker I found in a junk shop. It has a volume knob on the side. It sounds actually pretty good.

The ugly interior is shown below. And yes.... those are wood screws with washers holding the monitor against the board. :)

MAME Install

There really wasn't much to this. I went to the Github repo and blindly followed the README.

Configuring Buttons and Joystick

Adafruit has a life-saver utility called retrogame that can be used to interpret GPIO-connected switch events as keyboard inputs. This utility will run in the background, capture the button and joystick inputs, and feed them to the game currently being played.

Adafruit provides a configuration script that you can downloaded and execute on the Pi. It will fetch the source code and configure your GPIO based on a few key choices. However, none of the choices matched my configuration so I went directly to the Github site and downloaded the retrogame source. You can find it here.

The next step was to configure Retrogame to match the knobs and switches on gamebox to the GPIO. The code at Retrogame has evolved since I downloaded it. The keymap is now located in a config file external to the retrogame binary. But my version has the keymap embedded in the retrogame.c file (requiring a rebuild after modification). Here is my keymap:

	Input	Output
	{ 23,	KEY_LEFT },
	{ 22,	KEY_RIGHT },
	{ 17,	KEY_UP },
	{ 18,	KEY_DOWN },
	{  6,	KEY_LEFTCTRL }, // A/Fire/jump/primary
	{ 12,	KEY_LEFTALT }, //B/Bomb/secondary
	{  9,	KEY_SPACE },
	{ 26,	KEY_R },
	{ 20,	KEY_F },
	{  8,	KEY_D },
	{ 11,	KEY_G },
	{ 19,	KEY_A },
	{ 16,	KEY_S },
	{ 25,	KEY_Q },
	{  5,	KEY_1 },
	{  7,	KEY_2 },
	{ 15,	KEY_5 },
	{ 10,	KEY_ESC },
	{ -1,	-1 }

This keymap corresponds to the allocation of controls as shown in the figure below: