Category Archives: Electronics

GP-Wiz40 MAX USB and MAME4All-Pi on RetroPie

So, as it stands with the September 2013 build of MAME4All-Pi, the code supported 16 joystick buttons. Now, under normal conditions, this would be just fine. However, I’m trying to get two players on the one GP-Wiz40 board — using all digital pins (no “joystick ports”).

After messing with the joystick stuff, I could get Linux to recognize and calibrate the sticks (which are actually digital – LOW=0, CENTER=127, HIGH=255). But no luck with MAME.

So, I fell back to the Source Code. Luckily, in the Google repository, I was able to find the changes needed (when they changed the code to support 16 buttons). So, if I could find all those changes, I could add more (with any luck).

And I ended up lucky!

Go to /opt/retropie/emulators/mame4all-pi/src

These files need to be updated:

/input.h
/inptport.h
/inptport.cpp
/rpi/minimal.h

I added 4 new buttons, bringing the total to 20.

One thing I just noticed: in inptport.h and inptport.cpp there is a READ_HANDLER that does up to 20 ports (boy, was I lucky). If I add more buttons, I’m probably going to mess with that. Not sure why that was already there — maybe they are using 4 for directions and 16 for buttons? Not sure. I’m just hacking the code, so don’t have a proper understanding of it. Either way, I didn’t touch that part, yet my new buttons are working. Go figure.

Once the source is updated, go to /opt/retropie/emulators/mame4all-pi/ and make clean and then make.

(Note that I was sick of permissions issues, so was a bad boy and just granted all users full access to the directory. You may need to do this, or try sudo. I was sick of getting stopped by “security” that I don’t need, so used the brute force approach.)

So, now I can have P1 and P2 have 8 control buttons each (U/D/L/R/A/B/X/Y) and I have four more lines for COIN, P1 Start, P2 Start (?), and probably ESC (close emulator). I’ll stick with 20 for now, since I’m sick of this little hornets nest and want to get to building the hardware!

 

 

GP-Wiz40 To Linux / RetroPie Joystick Mapping

Here is how the GP-Wiz40 maps to the Linux buttons. Note that the current build of MAME4ALL for Pi is limited to 16 buttons. There may be a way around this. This might change in the future. For now, it’s causing me problems. I’m hoping I can figure out how to get the actual analog stick ports to work — that would solve my problem.

I’ve included a column for what function I mapped to each button. You can do whatever you like. This worked for me.

GP-Wiz40_Linux_RetroPie_Mapping

Also, remember I’m trying to use only one of my GP-Wiz40 boards. First, it would be silly to waste another board. Second, I want to use only one USB port (so I can connect a keyboard for debugging, if needed, and not have a USB hub added to this mess.)

Update: I got the Linux values the hard way (don’t ask). The easier/proper way is to get the Linux jstest (joystick test) program. Which, for reasons unknown, isn’t included in the RetroPie build. To get it, go to the command line and install via:

sudo apt-get install joystick

You’ll then have access to jstest:
To see everything: jstest /dev/input/js0
To see events as they come in (easier when checking individual wires/buttons): jstest –event /dev/input/js0

(js0 = joystick #1, js1 = joystick #2, etc,) The GP-Wiz40 gets auto detected under js0, at least in my environment. 🙂

next up: Seeing if jscal (joystick calibration) can help get the “normal” GP-Wiz40 joystick (analog) ports working — so I can free up four digitals per player. Here’s hoping.

Update #2: Well, I got calibration to work. But MAME still doesn’t see/find/accept the “analog” joystick pins. So, I’ll stick to pure digital. Remember the problem with that: MAME4ALL-PI only supports 16 buttons. So, I pulled down the source and modified the code so that it will do 20 (for now — just testing). The compile is running now. We’ll see if that works.

GP-Wiz40 MAX USB and RetroPie

Since I’m going to all the trouble to build a big screen movie setup in the backyard, I figured — games! And since I’m not a great fan of current games, I wanted retro.

With lucky happenstance, I ran across a Linux build for the Raspberry Pi (the $35 computer) that is designed for retro gaming in mind. Horray! It’s called RetroPie (and yes, there are others).

The current build is quite nice, with everything installed. But how to control it? I got some cheapie USB controllers (SNES style) that will work, but I wanted heavy duty. And what about MAME? That app, for all it’s greatness, is so bound to a keyboard. And I don’t want a keyboard on my back porch.

For past projects (not completed) I had purchased a couple of interface boards from GroovyGameGear. Their GP-Wiz 40 — a device that is seen as a game controller, and connects via USB. That would work great for controllers. (Again, from past projects, I have arcade quality sticks and buttons on hand, from X-Arcade.)

The other product I have of theirs is their KeyWiz — which emulates a keyboard. It’s a great product with a fatal flaw (in the case of the Raspberry Pi) — it uses a PS/2 port. No PS/2 port on the Pi. And that port is, unfortunately, as rare as hens teeth on current PCs.

KeyWiz would be perfect for MAME, since it acts like a keyboard, not a gamepad/joystick. However, the port limitation means I can’t use it.

So, back to the GP-Wiz 40. Good news: The EmulationStation front-end to the emulators pick it up fine. But what about the emulators themselves?

You really go down the rabbit hole with this stuff.  Here’s how it works:

  • EmulationStation is a pretty front end to start the emulators and games. It does not actually do the emulation. It’s your “TV GUI”.
  • RetroArch is a middle layer. It gets called from ES and handles the calling of the individual emulators. Why a middle layer? Well, for one, it makes coding front-ends easier. ES just has to interface with RA, not a bunch of individual emulators. And, you can choose to config controllers once — in RetroArch — and it passes those configs down to the emulators.
  • The emulators themselves. These are custom builds for the PI to take advantage of its meager resources. Keep “custom builds” in mind — because of the heartache these will cause (below).

I mapped the GP-Wiz 40 inputs to various controls in RetroArch. For example, Linux Joystick Button 4 = “A”, Button 5 = “B”, Button 16=”Select” and so on. For NES and SNES I needed 8 inputs (U/D/L/R/A/B/X/Y) for the usual controls, plus 2 more — for Select and Start.

That all worked fine. I got NES, SNES, and Atari 2600 working fine. Good progress. But what about MAME — for the arcade games?

Well, this was (and still is) a bear. For one, the mappings I setup in RetroArch didn’t seem to translate to the MAME emulator (MAME4ALL). Well, there are worse things, I guess. I can manually do the mappings within MAME.

Couple of issues:

  1. The config stuff is read-only. So if you change settings, they don’t stick after a MAME restart. Saw this with RetroArch, too. This is fixed by changing the ownership of the config files to the “pi” user. Something like “sudo chown pi retroarch.cfg” (sudo=act as admin, chown=change owner, pi=new owner, retroarch.cfg=file you want owner changed on).
  2. I could not, for the life of me, get MAME to recognize the joystick ports (analog, but can be used as digital). So, I had to go with pure digital.
  3. I could not get MAME to recognize all of the digital ports on the GP-Wiz 40. This really, really sucked.

Why did #3 suck so bad? Because MAME uses all those damn “insert coin” and “player one start” stuff to start a game. So, in addition to the regular buttons, I needed ports for that (remember, I don’t want a keyboard outside).

The GP-Wiz 40 has plenty of ports — so why didn’t MAME recognize them? Well, after seeing nothing in the documentation, I came across this is a change log: “Updated code to support 16 buttons”.

Shit.

Player 1: U/D/L/R/A/B/X/Y = 8 + Player 2 is another 8 — 16. I’m maxed out, because this custom build limited buttons.

So, I could get game controls in MAME, but can’t actually start a game. And so it stands right now. Either I have to figure out how to get the joystick analogs to work, freeing up 4 digitals for each user, or come up with some sort of magic hotkey. (In the SNES and NES emulators, since they can see more than 16 buttons, I have dedicated digital lines for Select and Start — and pressing them together exits the emulator.)

So, if you are wanting to use the GP-Wiz 40 for two players in RetroPie, keep this in mind: SNES and NES and Atari 2600 (the ones I tested and have games for) work fine. I’m using digital for the joystick, but since I have plenty of ports, no problem. MAME is the problem, with it’s limitation. Like I said, I’m still working on it, and I’ll post again if I come up with a solution.