Xarcade2Jstick - Map your Xarcade Tankstick to Game Pads and use it with RetroPie

IMG_2165_480The Xarcade Tankstick is a nicely designed and very robustly constructed arcade game controller. It offers buttons and joysticks for two players together with start and coin buttons, an arcade trackball, and dedicated pinball buttons.

Being asked, if RetroPie could have in-built support for the Xarcade Tankstick I started to dig into this controller which, in the end, lead to the development of Xarcade2Jstick, a user-space daemon that lets the Tankstick register as two individual game pads on a Linux computer. It integrates seamless in a RetroPie installation and, thus, makes the usage of a Tankstick with RetroPie extremely easy.

The next part describes the motivation for the work on Xarcade2Jstick. Afterwards the functionalities and architecture of Xarcade2Jstick are explained. It is described how to download, build and install the driver. After that, details about the support of Xarcade2Jstick by the RetroPie and especially the RetroPie-Setup Script are given.

The user-space driver Xarcade2Jstick

Motivation

The Linux kernel registers the joysticks and the buttons of the Xarcade Tankstick as a single USB keyboard device. If you are connecting the according USB connector for the arcade trackball with your host machine, the kernel registers it as an USB mouse.
Because a keyboard is probably the most basic input device for a computer and every emulator supports the keyboard as input device this approach gives the user a huge amount of freedom regarding the configuration and application of the Tankstick when used with emulators. There is, however, at least one situation, in which it would be of advantage when the Tankstick would be registered as, say, two game pad devices instead of a single keyboard. More specifically, I came into this situation when I thought about a way for switching automatically to the Tankstick as input device when it is connected to a computer with a RetroPie installation: The front-end EmulationStation looks for game pad devices for its assisted input configuration. Also, all emulated systems that rely on the RetroArch emulator make use of the auto-configuration functionality. This function loads an input configuration depending on the currently connected game pads. Last but not least some other emulators like PiFBA come with a ready-to-go game pad configuration.

These points were the motivation for developing Xarcade2Jstick. The next section describes the functions and also gives a brief overview about its software architecture.

Functionalities and Architecture

The use cases for the Xarcade2Jstick daemon are as following:

  • Detect a connected Xarcade Tankstick
    When starting, the tool detects a connected Xarcade Tankstick.
  • Map Xarcade Tankstick event to game pad event
    The tool listens to the events of the Tankstick and maps every received event to an according game pad event.
  • Map alternative function event to keyboard event
    If certain button combinations are pressed on the Tankstick, alternative keyboard events are generated.

The following diagram shows the dependencies between the modules:
xarcade2jstick1The Xarcade Tankstick is abstracted by the module "input_xarcade". The input_xarcade" module, in turn, is using the Linux "input" module. These modules are responsible for capturing the original keyboard events from the Tankstick. Most of the keyboard events are mapped to corresponding game pad events. Certain key combinations are mapped to keyboard presses: COIN1+Start1 is mapped to TAB and COIN2+START2 is mapped to ESC. These virtual game pad and keyboard presses are abstracted by the modules "uinput_gamepad" and "uinput_kbd". These two modules are using the Linux "uninput" module for realizing these user-space input events.

The following diagram shows the program flow of Xarcade2Jstick:
xarcade2jstick2

First of all, the Xarcade Tankstick is identified and opened exlusively by Xarcade2Jstick. Afterwards, two game pads and a keyboard are registered via the uinput module. Then the main loop is started. It consists of reading the events of the Xarcade device and of mapping the events to the virtual game pads and the keyboard.

Installation and Usage

The following installation and usage manual is taken from the Github site of the tool:

Downloading

If you would like to download the current version of Xarcade2Jstick from its Github repository, you can use this command:

git clone https://github.com/petrockblog/Xarcade2Jstick

Building and Installation

To build Xarcade2Jstick follow these commands:

cd Xarcade2Jstick
make

If everything went fine you can install with the command

sudo make install

Installation as Service

You can install Xarcade2Jstick as daemon with this command:

sudo make installservice

Usage

Xarcade2Jstick looks for an Xarcade device when it is started. That means you need to connect your Xarcade before Xarcade2jstick is started. When using Xarcade2jstick as a service, you could shutdown the RPi, connect the Xarcade and start your Rpi again.

Uninstalling the service and/or the binary

You can uninstall the daemon with this command:

sudo make uninstallservice

You can uninstall the binary with this command:

sudo make uninstall

Support in the RetroPie-Setup Script

If you would like to use Xarcade2Jstick in combination with a RetroPie installation you have at least two options:

  1. You can follow the steps as described above from the terminal. Xarcade2Jstick can easily be built and installed with the Makefile that comes with its sources.
  2. You can use the RetroPie-Setup Script for downloading, building, and installing Xarcade2Jstick. The RetroPie-Setup Script got updated recently to support the Xarcade2Jstick configuration from within the "Setup" menu. Furthermore, it contains a configuration file for the auto-config functionality of RetroArch.

RetroPie is fully prepared to seamlessly work with Xarcade2Jstick.

Conclusion

If you would like the Xarcade Tankstick to be registered as two individual game pads on a Linux machine, the program Xarcade2Jstick might be a solution for you. It exclusively captures the original keyboard events and maps these to the corresponding game pad events. Furthermore, the Shift-key functionality is also made available by Xarcade2Jstick, so that virtual keyboard presses of TAB and ESC are still possible.
Xarcade2Jstick can easiliy be installed and can also be installed and configured with the RetroPie-Setup Script.

  • Miggy

    Does this only work with the Tankstick? What about the DualJoystick?

    • http://www.petrockblock.com/ petRockBlog

      For the development of Xarcade2Jstick I only had a Tankstick available. However, the keyboard outputs seem to be the same so that Xarcade2Jstick should also work with a DualStick.
      It would be great if you could test this out. In case it does not work out-of-the-box I could try to extend Xarcade2Jstick accordingly with your feedback!

  • RetroPiMan8

    Great work - thanks! I did run into some probs: ran though the install directions for Xarcade2Jstick and it it now works for certain systems (arcade), but not for others. Tried the Setup script afterwards, and although recognized, when auto-config ran, each button was "Timed Out". Also, for those that worked, COIN + Start are Exit commands for P1 and P2 - anyone else have these issues or are able to solve? Additionally, are there any ideas for hotkeys on the tankstick? Thanks again.

    • http://www.petrockblock.com/ petRockBlog

      There already comes a config-file with the RetroPie-Setup Script for the RetroArch-based emulators. So there should be no need for running the auto-config from within the Setup Script again. It might be overwritten now, though.

      For which systems is it working and for which not?

      • RetroPiMan8

        Seems like only only the arcade and master systems work. Others resort back to the keyboard controls. I am able to use the COIN 2 + Player2 exit command on some that are not recognizing the tankstick. Tried updating source/binaries which later showed "Enable Xarcade2Jstick" on the setup script. Tried that and then running the install commands again for Xarcade2Jstick but no luck. Any ideas?

      • RetroPiMan8

        To specify, only coin-insert and GG systems work, all else falls back onto the keyboard.

      • http://www.petrockblock.com/ petRockBlog

        The RetroArch-based emulators (e.g., SNES, NES, Genesis/Megadrive) should also work, if you have the file Xarcade-to-GamepadDevice.cfg (see https://github.com/petrockblog/RetroPie-Setup/blob/master/supplementary/RetroArchConfigs/Xarcade-to-GamepadDevice.cfg) located in /home/pi/RetroPie/emulators/RetroArch/configs/

      • Shibo

        I recently picked up an X-Arcade dual stick (2 player, not the tank stick) and have been having some config issues. I attempted to use the Xarcade2Jstick, but that did not appear to work for the dual stick controller. Additionally, configuring this seems rather troublesome on its own. I have most buttons working, but it is not perfect yet.

        I have seen other posts from you (or another mod), such as the post below, looking for help to possibly extend Xarcade2Jstick to support the dual stick and I would be happy to help.

        Another question though:
        I do see the Xarcade-to-GamepadDevice.cfg in the appropriate directory, does this override the config files you can setup in ~/RetroPie/configs/all/* when launching using an Xarcadestick or is it simply a reference file for (example) default values?

      • http://www.petrockblock.com/ petRockBlog

        Yes, the settings in Xarcade-to-GamepadDevice.cfg override the settings in ~/RetroPie/configs/all/retroarch.cfg. However, this is only a RetroArch function and works only, e.g., for SNES, NES, Genesis/Megadrive, FBA. You can see that this function is working when starting a ROM and the emulator says on the bottom screen that it is using Xarcade-to-... .

        For further work on the support for the DualStick, let us switch to the according forum post at http://blog.petrockblock.com/forums/topic/retropie-not-recognizing-xarcade-dual-tank-stick/#post-9953.

  • AnthonyG

    Ok, so I tried the commands above and got zilch, said there was no such thing as the link you have posted. Is there someplace else that this is hosted? I've downloaded things just fine from Github before but I guess this just doesn't work for me or is no longer there.

    To make a long story short, I have an X-Arcade Tankstick I'd like to mount my Raspberry Pi B+ in but I'm having some trouble getting all the controls to work, found out that Cave Story was pretty much just fine but Doom/etc just wasn't having it. This is my first little jog into both Raspberry Pi hardware and Linux software, I'm even having trouble getting Tightvnc to run on startup... I know, pretty bad.

    • AnthonyG

      Alright, apparently I can't get tightvnc to run on startup otherwise EmulationStation refuses to start and I was missing part of the link when trying to download the files. So...I got it, I think. Now I just have to hook up the controller and actually try it. If anyone else has got this to work (emulationstation control and in the individual emulators) I could probably use some help.

%d bloggers like this: