UAE with Xbox controllers

From time to time, I enjoy playing old Amiga games. Unfortunately, I have to resort to the use of Linux e-uae, which has not made any improvements since 2007.  There is no issue with e-uae insofar as how it runs, just that its UI and features are getting a bit stale.  For example, I cannot use my X-Arcade controller with it, unless I manually patch e-uae source code (which I did once upon a time AND submitted the patches to the author).  And using the generic /dev/input/js0 interface from the Linux xpad driver sucks, because you have to use the analog stick and not the D-pad buttons, which would be better because it matches the 4-way button joystick of those days.

In steps xboxdrv.  It offers a lot of extensible features over xpad, and supports a lot of Xbox controllers and their variants as well.  I use both the Microsoft and Afterglow branded versions of the 360 USB wired gamepads.  It should be first noted that this userspace driver runs “easier” if started with sudo (or root) and it likely requires a D-bus security policy file in /etc/dbus-1/system.d/org.seul.Xboxdrv.conf

<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" "">
  <!-- ../system.conf have denied everything, so we just punch some holes -->
  <policy context="default">
    <allow own="org.seul.Xboxdrv"/>

For the Amiga emulator, I setup two joystick controller configuration files:

# uae keymap configuration
# clear the default configuration, so we start empty
ui-clear = true

# joystick #1
X1 = ABS_X
Y1 = ABS_Y

back = KEY_F12+KEY_Q
start = KEY_F12+KEY_S
du = KEY_UP

… and the second is the same as the first, except its button mappings:

back = KEY_F12+KEY_Q
start = KEY_F12+KEY_S
dd = KEY_B
dl = KEY_F
dr = KEY_H
du = KEY_T

After the policy and configurations are in place, startup the userspace driver as:

$ sudo xboxdrv -d -D --detach -c uae/joymap1.ini --next-controller -c uae/joymap2.ini

… and plug-in both controllers.  You can inspect that it is working with:

$ sudo xboxdrv -L
 id | wid | idVendor | idProduct | Name
  0 |   0 |   0x0e6f |    0x0213 | Afterglow Gamepad for Xbox 360
  1 |   0 |   0x0e6f |    0x0213 | Afterglow Gamepad for Xbox 360

Very nice!  TV Sports: Football anyone?

One other thing worth mentioning.  One of my Afterglow gamepads seems to have quirky short in its USB cabling.  When it disconnects / reconnects, the xpad driver will re-enumerate it as a js2, js3, etc. and essentially the joystick input is of no use to the emulator.  With xboxdrv, the controller re-attaches as the same device, so the game play can continue without complete loss of the controller.