Difference between revisions of "Arcade Machine"
(→Writing our own input driver) |
|||
Line 137: | Line 137: | ||
− | Example | + | Example config.h: (See the repository for one with lots of comments) |
− | + | Note that the INPUT_PATH is incorrect for the arcade machine. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | |||
+ | #include "config_functions.h" | ||
+ | |||
+ | /* -------------------------------------------------------------------------- */ | ||
+ | /* ----------------------------- FIRST SECTION ----------------------------- */ | ||
+ | /* -------------------------------------------------------------------------- */ | ||
+ | |||
+ | #ifndef H_GLOBAL_MAP | ||
+ | #define H_GLOBAL_MAP | ||
+ | |||
+ | /* Set up amount of joysticks here */ | ||
+ | #define JOYCOUNT 2 | ||
+ | |||
+ | /* Set up event to read from */ | ||
+ | #define INPUT_PATH "/dev/input/by-path/platform-i8042-serio-0-event-kbd" | ||
+ | |||
+ | #endif | ||
+ | |||
+ | /* -------------------------------------------------------------------------- */ | ||
+ | /* ----------------------------- SECOND SECTION ----------------------------- */ | ||
+ | /* -------------------------------------------------------------------------- */ | ||
+ | |||
+ | #ifdef H_CONFIGURE_JOYSTICKS | ||
+ | #ifndef H_CONFIGURE_JOYSTICKS_SEEN | ||
+ | #define H_CONFIGURE_JOYSTICKS_SEEN | ||
+ | |||
+ | |||
+ | /* Configure first joystick. | ||
+ | * | ||
+ | * Here we just tell the program what keys event we will expose and what | ||
+ | * keys we want to use. | ||
+ | * | ||
+ | * If a key is not enabled here, it will never be passed. | ||
+ | */ | ||
+ | |||
+ | /* We want to send ABS and KEY events */ | ||
+ | JOYSTICK_SET_OPT(EV_ABS, UI_SET_EVBIT, 0) | ||
+ | JOYSTICK_SET_OPT(EV_KEY, UI_SET_EVBIT, 0) | ||
+ | |||
+ | /* Hats: | ||
+ | * We set the absmax and absmin; otherwise the hats make no sense. | ||
+ | */ | ||
+ | JOYSTICK_ADD_KEY(ABS_HAT0X, UI_SET_ABSBIT, 0) | ||
+ | JOYSTICK_SET_LIM(absmax, 1, ABS_HAT0X) | ||
+ | JOYSTICK_SET_LIM(absmin, -1, ABS_HAT0X) | ||
+ | JOYSTICK_ADD_KEY(ABS_HAT0Y, UI_SET_ABSBIT, 0) | ||
+ | JOYSTICK_SET_LIM(absmax, 1, ABS_HAT0Y) | ||
+ | JOYSTICK_SET_LIM(absmin, -1, ABS_HAT0Y) | ||
+ | |||
+ | /* XXX: ALWAYS SET BTN_JOYSTICK TO EXPOSE A JOYSTICK EVENT */ | ||
+ | JOYSTICK_ADD_KEY(BTN_JOYSTICK, UI_SET_KEYBIT, 0) | ||
+ | |||
+ | /* Buttons. */ | ||
+ | JOYSTICK_ADD_KEY(BTN_0, UI_SET_KEYBIT, 0) | ||
+ | JOYSTICK_ADD_KEY(BTN_1, UI_SET_KEYBIT, 0) | ||
+ | JOYSTICK_ADD_KEY(BTN_2, UI_SET_KEYBIT, 0) | ||
+ | JOYSTICK_ADD_KEY(BTN_3, UI_SET_KEYBIT, 0) | ||
+ | |||
+ | /* Second joystick ; same comments as first one */ | ||
+ | JOYSTICK_SET_OPT(EV_ABS, UI_SET_EVBIT, 1) | ||
+ | JOYSTICK_SET_OPT(EV_KEY, UI_SET_EVBIT, 1) | ||
+ | |||
+ | JOYSTICK_ADD_KEY(ABS_HAT0X, UI_SET_ABSBIT, 1) | ||
+ | JOYSTICK_SET_LIM(absmax, 1, ABS_HAT0X) | ||
+ | JOYSTICK_SET_LIM(absmin, -1, ABS_HAT0X) | ||
+ | |||
+ | JOYSTICK_ADD_KEY(ABS_HAT0Y, UI_SET_ABSBIT, 1) | ||
+ | JOYSTICK_SET_LIM(absmax, 1, ABS_HAT0X) | ||
+ | JOYSTICK_SET_LIM(absmin, -1, ABS_HAT0X) | ||
+ | |||
+ | JOYSTICK_ADD_KEY(BTN_JOYSTICK, UI_SET_KEYBIT, 1) | ||
+ | |||
+ | JOYSTICK_ADD_KEY(BTN_0, UI_SET_KEYBIT, 1) | ||
+ | JOYSTICK_ADD_KEY(BTN_1, UI_SET_KEYBIT, 1) | ||
+ | JOYSTICK_ADD_KEY(BTN_2, UI_SET_KEYBIT, 1) | ||
+ | JOYSTICK_ADD_KEY(BTN_3, UI_SET_KEYBIT, 1) | ||
+ | |||
+ | #endif | ||
+ | #endif | ||
+ | |||
+ | /* -------------------------------------------------------------------------- */ | ||
+ | /* ----------------------------- THIRD SECTION ----------------------------- */ | ||
+ | /* -------------------------------------------------------------------------- */ | ||
+ | |||
+ | #ifdef H_JOYMAP | ||
+ | #ifndef H_JOYMAP_SEEN | ||
+ | #define H_JOYMAP_SEEN | ||
+ | |||
+ | /* First joystick */ | ||
+ | |||
+ | /* HAT */ | ||
+ | KEYMAP(KEY_UP, ABS_HAT0Y, EV_ABS, 0, -) | ||
+ | KEYMAP(KEY_DOWN, ABS_HAT0Y, EV_ABS, 0, +) | ||
+ | KEYMAP(KEY_LEFT, ABS_HAT0X, EV_ABS, 0, -) | ||
+ | KEYMAP(KEY_RIGHT, ABS_HAT0X, EV_ABS, 0, +) | ||
+ | |||
+ | /* Red buttons */ | ||
+ | KEYMAP(KEY_LEFTCTRL, BTN_0, EV_KEY, 0, +) | ||
+ | KEYMAP(KEY_LEFTALT, BTN_1, EV_KEY, 0, +) | ||
+ | KEYMAP(KEY_SPACE, BTN_2, EV_KEY, 0, +) | ||
+ | |||
+ | /* Yellow button */ | ||
+ | KEYMAP(KEY_1, BTN_3, EV_KEY, 0, +) | ||
+ | |||
+ | /* Second joystick */ | ||
+ | |||
+ | /* HAT */ | ||
+ | KEYMAP(KEY_R, ABS_HAT0Y, EV_ABS, 1, -) | ||
+ | KEYMAP(KEY_F, ABS_HAT0Y, EV_ABS, 1, +) | ||
+ | KEYMAP(KEY_D, ABS_HAT0X, EV_ABS, 1, -) | ||
+ | KEYMAP(KEY_G, ABS_HAT0X, EV_ABS, 1, +) | ||
+ | |||
+ | /* Red buttons */ | ||
+ | KEYMAP(KEY_A, BTN_0, EV_KEY, 1, +) | ||
+ | KEYMAP(KEY_S, BTN_1, EV_KEY, 1, +) | ||
+ | KEYMAP(KEY_Q, BTN_2, EV_KEY, 1, +) | ||
+ | |||
+ | /* Yellow button */ | ||
+ | KEYMAP(KEY_2, BTN_3, EV_KEY, 1, +) | ||
+ | |||
+ | #endif | ||
+ | #endif | ||
== Games == | == Games == | ||
Revision as of 01:02, 5 December 2012
Projects | |
---|---|
Participants | Control-k, Maijin, Realitygaps, Wizzup |
Skills | Programming |
Status | Active |
Niche | Software |
Purpose | Fun |
Contents
Arcade Machine
We now own a <MODEL> Arcade Machine. The plan is to bring new life into the machine by putting a computer in there and hooking that computer to the joystick input and screens. The computer runs MAME and other emulators, such as Amiga or SNES emulators.
Getting it to work
There's a basic UvA machine in the Arcade Box; with Wake on Lan. Just send the WOL packet to the right mac address, which can be found on the machine:
00:21:70:03:31:1b
Here is an example command line that will turn on the machine (etherwake defaults to eth0, so wlan0 is specified)
sudo etherwake 00:21:70:03:31:1b -i wlan0
Or:
wakeonlan 00:21:70:03:31:1b
From: http://gsd.di.uminho.pt/jpo/software/wakeonlan/
Input
Arcade Machine input
The input can be read as PS2 (and USB); using a chip that we got alongside the Arcade Machine:
http://www.ultimarc.com/jpac.html http://www.ultimarc.com/jpac2.html
The Arcade Machine input exposes itself as a single keyboard over USB and PS/2. This is problematic for most games, with the exception of MAME and a few emulators.
The chip does not expose more than one HID, we will have to fiddle around a bit to get all the software to read from the input devices as two seperate devices. MAME is known to handle the basic PS2 input just fine (AFAIK), but for other emulators this can be a problem. Solutions include writing our own input driver or perhaps faking a device in X.
See the "Writing out own input driver" below for more details.
Basic instructions:
./disable_unusable_keyboard.sh cd uinput-mapper/ make sudo ./map
Other Input
We attached two PlayStation controllers, but I (Wizzup) am not a big fan of them. Regardless, there's a USB hub so feel free to plug in other controllers! It would be nice to have proper SNES ones.
This may be useful: https://www.thinkgeek.com/product/f08d/ and http://www.amazon.com/Classic-USB-Super-Nintendo-Controller-PC/dp/B002JAU20W Or we can make our own.
Coin Input
This should be handled by the Input over PS2/USB as well. It is probably mapped to a key.
Video
We replaced the built-in monitor with a TFT monitor.
Sound
The sound works and is connected to the computer as well.
Games
Emulators:
- ZSNES (SNES)
- UAE (Amiga)
- MAME
- ...
Writing our own input driver
Axes to axes, Buttons to buttons
Code: https://github.com/MerlijnWajer/uinput-mapper
Compile:
make
Run:
sudo ./map
Map:
- Creates two joystick input devices in /dev/input
- Both joystick devices are mapped sanely.
- HAT0X / HAT0Y seem to work now that we specified absmin and absmax.
Keys are mapped like this:
HAT -> HAT0X, HAT0Y Red Buttons, left to right: BTN_0, BTN_1, BTN_2 Yellow Button: BTN_3
Notes / Future usage:
- ./disable_unusable_keyboard.sh
- sudo ./uinput-mapper/map &
- Run your emulator/game
Key remapping
Remapping of keys is trivial, if you know a bit of C (preprocessor). Open up custom_map.h and edit to your liking
Note:
- Last argument to KEYMAP can be a statement or a function; which takes a single (value) argument and results in an integer.
- You cannot map INPUT keys other than those of type EV_KEY and you cannot map them to OUTPUT joystick keys other than the ones currently defined in the example.
- JOYCOUNT defines the amount of joysticks to create.
Do not forget to recompile:
make
Example config.h: (See the repository for one with lots of comments)
Note that the INPUT_PATH is incorrect for the arcade machine.
#include "config_functions.h" /* -------------------------------------------------------------------------- */ /* ----------------------------- FIRST SECTION ----------------------------- */ /* -------------------------------------------------------------------------- */ #ifndef H_GLOBAL_MAP #define H_GLOBAL_MAP /* Set up amount of joysticks here */ #define JOYCOUNT 2 /* Set up event to read from */ #define INPUT_PATH "/dev/input/by-path/platform-i8042-serio-0-event-kbd" #endif /* -------------------------------------------------------------------------- */ /* ----------------------------- SECOND SECTION ----------------------------- */ /* -------------------------------------------------------------------------- */ #ifdef H_CONFIGURE_JOYSTICKS #ifndef H_CONFIGURE_JOYSTICKS_SEEN #define H_CONFIGURE_JOYSTICKS_SEEN /* Configure first joystick. * * Here we just tell the program what keys event we will expose and what * keys we want to use. * * If a key is not enabled here, it will never be passed. */ /* We want to send ABS and KEY events */ JOYSTICK_SET_OPT(EV_ABS, UI_SET_EVBIT, 0) JOYSTICK_SET_OPT(EV_KEY, UI_SET_EVBIT, 0) /* Hats: * We set the absmax and absmin; otherwise the hats make no sense. */ JOYSTICK_ADD_KEY(ABS_HAT0X, UI_SET_ABSBIT, 0) JOYSTICK_SET_LIM(absmax, 1, ABS_HAT0X) JOYSTICK_SET_LIM(absmin, -1, ABS_HAT0X) JOYSTICK_ADD_KEY(ABS_HAT0Y, UI_SET_ABSBIT, 0) JOYSTICK_SET_LIM(absmax, 1, ABS_HAT0Y) JOYSTICK_SET_LIM(absmin, -1, ABS_HAT0Y) /* XXX: ALWAYS SET BTN_JOYSTICK TO EXPOSE A JOYSTICK EVENT */ JOYSTICK_ADD_KEY(BTN_JOYSTICK, UI_SET_KEYBIT, 0) /* Buttons. */ JOYSTICK_ADD_KEY(BTN_0, UI_SET_KEYBIT, 0) JOYSTICK_ADD_KEY(BTN_1, UI_SET_KEYBIT, 0) JOYSTICK_ADD_KEY(BTN_2, UI_SET_KEYBIT, 0) JOYSTICK_ADD_KEY(BTN_3, UI_SET_KEYBIT, 0) /* Second joystick ; same comments as first one */ JOYSTICK_SET_OPT(EV_ABS, UI_SET_EVBIT, 1) JOYSTICK_SET_OPT(EV_KEY, UI_SET_EVBIT, 1) JOYSTICK_ADD_KEY(ABS_HAT0X, UI_SET_ABSBIT, 1) JOYSTICK_SET_LIM(absmax, 1, ABS_HAT0X) JOYSTICK_SET_LIM(absmin, -1, ABS_HAT0X) JOYSTICK_ADD_KEY(ABS_HAT0Y, UI_SET_ABSBIT, 1) JOYSTICK_SET_LIM(absmax, 1, ABS_HAT0X) JOYSTICK_SET_LIM(absmin, -1, ABS_HAT0X) JOYSTICK_ADD_KEY(BTN_JOYSTICK, UI_SET_KEYBIT, 1) JOYSTICK_ADD_KEY(BTN_0, UI_SET_KEYBIT, 1) JOYSTICK_ADD_KEY(BTN_1, UI_SET_KEYBIT, 1) JOYSTICK_ADD_KEY(BTN_2, UI_SET_KEYBIT, 1) JOYSTICK_ADD_KEY(BTN_3, UI_SET_KEYBIT, 1) #endif #endif /* -------------------------------------------------------------------------- */ /* ----------------------------- THIRD SECTION ----------------------------- */ /* -------------------------------------------------------------------------- */ #ifdef H_JOYMAP #ifndef H_JOYMAP_SEEN #define H_JOYMAP_SEEN /* First joystick */ /* HAT */ KEYMAP(KEY_UP, ABS_HAT0Y, EV_ABS, 0, -) KEYMAP(KEY_DOWN, ABS_HAT0Y, EV_ABS, 0, +) KEYMAP(KEY_LEFT, ABS_HAT0X, EV_ABS, 0, -) KEYMAP(KEY_RIGHT, ABS_HAT0X, EV_ABS, 0, +) /* Red buttons */ KEYMAP(KEY_LEFTCTRL, BTN_0, EV_KEY, 0, +) KEYMAP(KEY_LEFTALT, BTN_1, EV_KEY, 0, +) KEYMAP(KEY_SPACE, BTN_2, EV_KEY, 0, +) /* Yellow button */ KEYMAP(KEY_1, BTN_3, EV_KEY, 0, +) /* Second joystick */ /* HAT */ KEYMAP(KEY_R, ABS_HAT0Y, EV_ABS, 1, -) KEYMAP(KEY_F, ABS_HAT0Y, EV_ABS, 1, +) KEYMAP(KEY_D, ABS_HAT0X, EV_ABS, 1, -) KEYMAP(KEY_G, ABS_HAT0X, EV_ABS, 1, +) /* Red buttons */ KEYMAP(KEY_A, BTN_0, EV_KEY, 1, +) KEYMAP(KEY_S, BTN_1, EV_KEY, 1, +) KEYMAP(KEY_Q, BTN_2, EV_KEY, 1, +) /* Yellow button */ KEYMAP(KEY_2, BTN_3, EV_KEY, 1, +) #endif #endif
Games
List of games:
Native
- Jamestown (works with joysticks)
- Syobon (not yet! Ubuntu didn't have it in their repo ☹)
Amiga
In UAE, just add the games as floppies.
- SWIV (Great shoot them up game)
- Pinball Fantasies
SNES
...
Other uses
- We can use it to control a variety of stuff. (light, sound)
- We can hook other consoles into it.
- ???