Sunday, December 13, 2009

Cocktail Arcade Cabinet: Software

I recently built a cocktail arcade cabinet from scratch.  I talked about fabrication previously, and I'd like to outline the software I've got on it for those who are interested.  It wasn't an dead-simple setup since emulators all have different interfaces, but I ended up with a setup that's relatively streamlined.


Goals

It's important to figure out what emulators you want.  I had decided that I wanted the 8-bit and 16-bit consoles, as well as MAME.  I don't have any analog controls, so anything requiring that was out of the question.  My primary goal was a cabinet that would play Donkey Kong, but I wanted the ability to play other things as well.  My final list of emulators was as follows:
Hurdles

I ran into a number of problems, but figured out hacks to solve them all.  The big problems I faced were:
  1. Running emulators on a vertical monitor.  Mame is good about this, since a lot of classic games were designed for vertical monitors.  However, almost all the other emulators encounter a DirectDraw error when you try to go into fullscreen mode on a vertical monitor.  Whatever could the solution be?
  2. Hiding menus. This is a result of not being able to run in full screen mode.  I wanted to make sure it wasn't obvious I was using Windows.  This meant no title bars, no Windows sounds, no Windows boot stuff, and no Windows menus.
  3. Doing everything from the arcade controller.  It was most helpful to have a shift key built into the controller I bought.  If you're hacking a keyboard to make your controllers, keep in mind that a shift, control, or alt key could be very useful.  Barring that, key combinations can be used, but you'll have to be sneaky since you'll be pressing all kinds of buttons while you're playing and you don't want to accidentally run a script or something.  For my setup, all my hotkeys use the Shazam (shift) feature of the KeyWiz controller.  I have a magic Shazam key that is only used when hotkeying (see a photo here).
  4. Quick startup.  I didn't want to wait for my cabinet to boot every time I decided to play.  System standby is quick to shut down and quick to start up, but Windows doesn't have any good built-in "do this when coming out of standby" functionality.  I found a solution for that, though.
Support Software

When all was said an done, I had installed the following software on my cabinet:
  1. Atomic FE Ultimate - for my main menu.  Atomic FE is really quite slick, but a little touchy.  I tried to set it up from scratch, but ran into too many problems.  Luckily, LaDite over at the Atomic FE site has put together Atomic FE Ultimate, a pre-configured version of Atomic FE with everything you need to build out an arcade menu.  
  2. AutoHotKey - Simply the most awesome piece of software you can get for making magic happen at the press of a key.  
  3. DropBox - If you don't know about it, get it immediately.  It takes a folder on your computer and syncs it with all your other computers.  I configured MAME to save screenshots in my DropBox folder.  I've been having a Kong-Off with a friend, and we email screenshots of our latest high score to each other.  DropBox is really useful for this since all I do is press the screenshot button and a screenshot is essentially sent to my other PC.
  4. KeyWiz Uploader - for setting my arcade controller config.  I use the "B" configuration.
  5. ATI Catalyst Configurator.  I use this to rotate my display in cases where I can't do it with other software.  It gives you the ability to rotate using hotkeys, and this was very handy.  I used CTRL+ALT+[0,1,2] to rotate between landscape mode, facing 1st-player vertical, and facing 2nd-player vertical.  More on that below.
The Configuration

The first step is to get Atomic FE running.  Working with Atomic FE can take a little getting used to, so I ended up configuring a single emulator completely to learn about Atomic FEs idiosyncrasies, and then I configured the rest of my emulators.  I suggest starting with MAME since it doesn't require any tweaks to get working.  It "just works".  At least, compared to the rest of the emulators I used.

Configuring MAME
  1. Run MameUI from windows.  Play around in the menus until is is configured such that when you run a game you can just play (no menu navigation required).  I had to set the following:

    1. Monitor rotation by 90 degrees.
    2. Automatically save state on exit (this also automatically loads it).
    3. screenshots saved to my DropBox folder.
    4. Cocktail mode dip-switches for two-player mode.  I didn't know about this until I started this project, but most older arcade games have a cocktail mode that will automatically rotate the display for the second player when it's their turn.  You can set this in the dip-switches section of each game, accessible while you're running the game.  
    5. Configure a proper exit button.  I didn't use escape because it is too generic (more on that later).  My MAME installation is configured to exit when I press F10, which happens to be the Shift-COIN button on my arcade controller.

  2. Create a main menu in Atomic FE.  This is where I list each emulator.
  3. Create a MAME option in the main menu you just created.  Selecting this option displays a list of MAME games on my system.  You can devise any arbitrary menu tree through Atomic FE, but I chose to go with a simple list of games for each emulator.  It's easy enough to change later if needed.  I think a lot of people end up sorting by genre.
  4. Make sure Atomic FE displays vertically, and your controller buttons are configured to step into and out of the Atomic FE menus.
  5. Try it out. Play with it. Tweak til it's perfect.
Dealing with Windows


After I got my MAME set up, I dug into hiding windows and working out how to put the system to sleep and have it start up Atomic FE when it woke up.  Hiding Windows is relatively easy, and there's a very nice "Hiding Windows" document over at BYOACWiki.  Now that I'm thinking of it, this information might be useful over there.  Another time, I suppose.  Anyways, I went with the following tweaks to hide Windows, and it took me less than an hour to do it all:
  1. Change the "Microsoft Windows" loading screen to a black image that says "Loading Arcade..." in retro text.
  2. Hide the desktop so no icons are shown.
  3. Turn off ALL sounds.  The windows startup sound was my specific issue, but I figured I'd shut everything off while I was in there.
  4. Make the taskbar auto hide.
  5. Configure Windows to automatically log in to my main user account.
Now for the hard part.  How do you get Atomic FE to automatically start up when the PC comes out of standby? AutoHotKey is the answer.  You can script ANY user actions with AutoHotKey.  The key, though, is that you can have it listen for a "coming out of standby" event.  AutoHotKey runs a master script when my system starts, and that listens for standby events.  When the PC comes out of standby, I do a few things:
  1. WAIT a little bit.  I have my script wait 5 seconds before doing anything.  When the system comes out of stand by, it takes a bit for everything to settle down.  this was particularly problematic with the next item...
  2. Write the key configuration to the KeyWiz controller.  If I didn't have the 5 second wait, sometimes KeyWiz Uploader would choke.  Also, you might expect that the KeyWiz would be able to preserve its configuration through shutdown and standby, since the documentation indicates that this is possible.  In my experience, though, I wasn't able to get it to save itself.  Instead, I have AutoHotKey run KeyWiz Uploader in silent mode (no menu is displayed) and it's all the same to me.
  3. Finally, start up Atomic FE, which DOES remember its configuration. All you have to do is run it.
The script that does this is here.  You'll most definitely have to tweak it to get it to work with your system, but it's a good starting point at least.  The actual script looks like this, though


OnMessage(0x218, "func_WM_POWERBROADCAST")
/*
   http://www.autohotkey.com/forum/topic21697.html
   Source: http://weblogs.asp.net/ralfw/archive/2003/09/09/26908.aspx
*/
func_WM_POWERBROADCAST(wParam, lParam)
{
      ; wake up event
      If (lParam = 0 && wParam = 18) 
      {
      Sleep, 5000
      ; run keyWiz to write default key setup to arcade controller
      Run "C:\Program Files\KeyWiz Uploader3\KeyWiz_Uploader3.exe" /A /S /P B, C:\Program Files\KeyWiz Uploader3
      Sleep, 2000
      Run "E:\AtomicFE_v020Ult\AtoMic.exe"
   }
   Return
}
I determined the  lParam = 0 && wParam = 18 part empirically on my system. You'll note if you go to the link the my script that the original script watches for wParam = 8. This didn't work on my system for some reason (I'm running Windows XP 32-bit... I dunno).
The script I linked to above includes the rest of my tricks, except for how I get all my emulators to run on a vertical monitor in full screen mode. Each one is different and I had to configure them all manually. All the emulators I've worked with restore their state when they load though, so once you've got it configured, it should stay that way.

The only problem is that Atomic FE bugs out when the monitor is in vertical mode. If you run it when the monitor is in vertical mode, Atomic FE enters an infinite loop and all you get is a black screen. So you have to run Atomic FE in landscape mode, and then switch to vertical mode when you run your emulators (none of the ones I used had an video rotation feature. That would have been a better and easier solution).

I rotate my display by having Atomic FE run a batch script for each emulator instead of the actual emulator. In the main folder for each emulator I used, I create a file called "run.bat" that contained the command to rotate the monitor, the command to run that emulator (with command line arguments, as Atomic FE does), and after the emulator exits, a command to rotate the monitor back to landscape mode. For example, this is what my SNES script looks like:
@ECHO off E:\scripts\rotate1p.ahk call zsnesw.exe %* E:\scripts\rotatenormal.ahk exit
The "@ECHO off" line makes the commands execute silently in the command line (where the .bat file gets run).  "rotate1p.ahk" and rotatenormal.ahk" are scripts I wrote for AutoHotKey that handle rotating the display.  On my system, all those scripts do is send Ctrl+Alt+[0,1, or 2].  You can get them at the bottom in the master zip file.  The part that runs the emulator is the "call zsnesw.exe %*" line. "call" is used so the batch file waits for zsnesw.exe to finish executing before continuing, and the "%*" business is used to pass whatever parameters Atomic FE gives to zsnes. Finally, after everything is done, "exit" makes sure the command prompt window gets closed.

It's pretty complicated and a bit goofy, but it gets the job done.

How to Exit Anything

Ok, so I've explained how to get Atomic FE to run things, but having the emulators exit is a bit of a different matter. Some of them can be closed with Alt+F4, some require you to use Escape, others require something completely different (like Stella... Ctrl+Q? Seriously?). My solution for dealing with that is one master hotkey defined in my main AutoHotKey script. In my script, F10 is the master hotkey (look for the "~F10::" line). I do a quick check of which processes are running, and that determines with keypress to send. Atari running? Send CTRL+Q. Other things besides MAME running? Send Alt+F4. MAME running? Don nothing and let the key pass through the script (I configured MAME and zsnes to close on F10).

The really cool part of the script is that I can also check if Atomic FE is running. If it isn't running, the script will run it. If it IS running, and no other emulator is running, then the script will put the system to sleep. Pretty amazing stuff, and one of the many reasons AutoHotKey is so awesome.

In the end, the software all flows like the following state diagram:



Finishing Touches

So things can be run, things can be exited, and things can be played. But I ran into a couple errors here and there and added some hotkeys to my main script to handle them.

I added to my main AutoHotKey script the ability to trigger the KeyWiz command to write the arcade controller configuration. Once in a while KeyWiz fails to write the "B" configuration, and I'm left with an unconfigured arcade controller. It just so happens that the first three buttons of my controller are Alt+Ctrl+Space in this default mode. So I added a hotkey to my script that manually runs KeyWiz and uploads the "B" configuration when Ctrl+Alt+Space is pressed. The "B" configuration doesn't use these keys, so it can only be run when the controller is in its default mode.

Additionally, I added two hotkeys that send Alt+Tab and Alt+Tab+Tab for any cases where Atomic FE starts up, but doesn't have focus. This happened a lot while I was configuring it, but doesn't seem to any more. I think it was because I had other things running while I was testing. If only Atomic FE is running, it always seems to get focus.

And that's it! I'm sure I missed something, so feel free to comment here if you have questions (best for everyone), or email me at lukerymarz-at-gmail.com.  

If you're interested, you can grab all the AutoHotKey scripts and batch files I used here (50 KB).

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.