Raspberry supernintendo emulation, working recipe

After messing around with libretro-snes9x and not getting video through hdmi at all, I tried to compile retroarch and pocketsnes from scratch, ending with a working configuration.

Get retroarch:

$ git clone https://github.com/Themaister/RetroArch.git

Compile:

$ ./configure
$ make

If you get errors like these ones:

CC gfx/vg.c
gfx/vg.c: In function ‘vg_init’:
gfx/vg.c:102:4: error: too many arguments to function ‘vg->driver->update_window_title’
gfx/vg.c: In function ‘vg_frame’:
gfx/vg.c:390:4: error: too many arguments to function ‘vg->driver->update_window_title’

Just edit gfx/vg.c and change update_window_title(true/false) with update_window_title() at those lines mentioned above.

after that:

$ sudo make install

Compiled retroarch is at /usr/local/bin/retroarch

Get pocketsnes:

$ git clone https://github.com/ToadKing/pocketsnes-libretro.git

Compile:

$ make

This Makefile does not have an “install” target, so you have to copy library by hand:

$ sudo cp libretro.so /usr/lib/retroarch-pocketsnes.so

Configure RCB so this binaries are called, for instance:
config.xml

...

/usr/local/bin/retroarch
"%ROM%" -f -c ~/.config/retroarch/retroarch-snes.cfg
...

retroarch-snes.cfg

video_driver = "gl"
libretro_path = "/usr/lib/libretro-pocketsnes.so"
video_fullscreen = true
audio_enable = true
audio_out_rate = 48000
audio_driver = sdl
...

I’ll try with different drivers, but this configuration does work. Sound is not very good, but I’m affraid that, unless I overclock my RPi I will not get much better results. And I want my little berry to last very long…

Raspbian + XBMC + retroarch : Gamepad does not work!

I did buy a new brand gamepad for 21€ in Amazon and connected to my Raspberry Pi. Dmesg didn’t report many details about it, just:

[    3.342426] usb 1-1.2: new full-speed USB device number 4 using dwc_otg
[    3.476789] usb 1-1.2: New USB device found, idVendor=044f, idProduct=b326
[    3.502087] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    3.529629] usb 1-1.2: Product: GPX Gamepad
[    3.551359] usb 1-1.2: Manufacturer: Thrustmaster
[    3.582106] usb 1-1.2: SerialNumber: 00000001

Well, at least it exists for the kernel.

Executing retroarch-joyconfig:

$ sudo retroarch-joyconfig
Cannot find joystick at index #0, only have 0 joystick(s) available ...

Oh, my God, my wife is going to kill me!!!

Don’t panic, maybe I need a driver or something. I had tried an old Joystick before and everything was ok but its lacking of buttons and axises and some calibration problems made me go for a new gamepad.

This is the Joystick:

411evC+bYYL._AA160_This is a GP XID from Thrustmaster, and I had bought it with the promise of being XBox compatible, and I remembered something about XBox gamepads being compatible with retroarch. After some googling I found a driver for this devices:

http://pingus.seul.org/~grumbel/xboxdrv/

Developed by Ingo Ruhnke (thanks Ingo).

Installed with: apt-get install xboxdrv (it’t in raspbian repository, fortunately).

It has an user space part, so you have to run a command:

$ sudo xboxdrv
xboxdrv 0.8.4 - http://pingus.seul.org/~grumbel/xboxdrv/
Copyright © 2008-2011 Ingo Ruhnke <grumbel@gmx.de>
Licensed under GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under certain conditions; see the
file COPYING for details.

-- [ ERROR ] ------------------------------------------------------
No Xbox or Xbox360 controller found

Oh, no, I’m lost again!!!!

No, you have to RTFM. The FM is REALLY GOOD for this product, and you find some things like:

–device-by-id : force the driver to drive a device by vendor / productid

–type xbox360 : if you use the above parameter, you have to tell what kind of thing it is

–trigger-as-zaxis: it helped me to map the triggers, it tells the driver to manage the triggers as a Z axis instead of two independent axises.

So, with this command:

$ xboxdrv --silent --device-by-id 044f:b326 --type xbox360 --trigger-as-zaxis
xboxdrv 0.8.4 - http://pingus.seul.org/~grumbel/xboxdrv/
Copyright © 2008-2011 Ingo Ruhnke <grumbel@gmx.de>
Licensed under GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under certain conditions; see the
file COPYING for details.

Controller:        unknown
Vendor/Product:    044f:b326
USB Path:          001:004
Controller Type:   Xbox360

Your Xbox/Xbox360 controller should now be available as:
/dev/input/js0
/dev/input/event2

Press Ctrl-c to quit

Voila! It works, and now you can map the buttons and axises with retroarch-joyconfig. In my case, I obtained the following configuration:

# Defines axis threshold. Possible values are [0.0, 1.0]
# input_axis_threshold = 0.5
input_player1_joypad_index = "0"
input_player1_a_btn = "0"
input_player1_b_btn = "1"
input_player1_x_btn = "2"
input_player1_y_btn = "3"
input_player1_l_btn = "4"
input_player1_r_btn = "5"
input_player1_l2_axis = "-2"
input_player1_r2_axis = "+2"
input_player1_l3_axis = "-2"
input_player1_r3_axis = "+2"
input_player1_start_btn = "7"
input_exit_emulator_btn = "6"  # Added my hand, found the button with jset-gtk
input_player1_select_btn = "8"
input_player1_left_btn = "h0left"
input_player1_up_btn = "h0up"
input_player1_right_btn = "h0right"
input_player1_down_btn = "h0down"
input_player1_l_x_plus_axis = "+0"
input_player1_l_y_plus_axis = "+1"
input_player1_l_x_minus_axis = "-0"
input_player1_l_y_minus_axis = "-1"
input_player1_r_x_plus_axis = "+3"
input_player1_r_y_plus_axis = "+4"
input_player1_r_x_minus_axis = "-3"
input_player1_r_y_minus_axis = "-4"

You can experiment with different –type parameters (please, RTFM).

In my case, I added the xboxdrv execution to:

/home/pi/.xbmc/addons/script.games.rom.collection.browser/applaunch.sh

So it gets executed only when I need it. At the end of the script, I kill (pkill) the xboxdrv process.

Good luck with your gamepads!!

XBMC + ROM Collection Browser + retroarch: sound and joystick calibration

A new modification to applaunch.sh, so you calibrate and map the joystick and force mixer before launching the emulator.
Don’t take the arguments as is, they are just an example. Well, the amixer arguments force audio output to HDMI.


#!/bin/bash

# Check for arguments
if [ -z "$*" ]; then
echo "No arguments provided."
echo "Usage:"
echo "launcher.sh [/path/to/]executable [arguments]"
exit
fi

echo "Trying to stop xbmc "
sudo /etc/init.d/xbmc stop
# Deactivates HDMI output
sudo /opt/vc/bin/tvservice -o
# Activates HDMI output again
sudo /opt/vc/bin/tvservice -p

# Wait for the kill
sleep 1

# Joystick calibration and mapping
jscal -s 3,1,0,82,82,8388352,8134160,1,0,99,99,6882750,8388352,1,2,84,84,7254791,7063875 /dev/input/js0
jscal -u 3,0,1,6,4,288,289,290,291 /dev/input/js0
# Force audio output
amixer cset numid=3 2

echo "$@"

# Launch app - escaped!
"$@"

echo "Emulator terminated"

# Done? Restart XBMC
sudo /etc/init.d/xbmc start

XBMC – ROM Collection Browser – retroarch: problem with screen

When trying to setup ROM Collection Browser2.0.0  plugin in XBMC 2:12.0-1 under Raspbian 7.0, kernel 3.6.11, I had problems related to screen display.

At first, emulator was launched correctly, but xbmc stayed at the top left corner, on top of the game. After searching in forums and trying several things  I tried Solo mode, but the situation was worse, the emulator display didn’t even show up.

Digging in the Python and shell script code, I found this solution: launcher.py, when solo mode is selected, runs applaunch.sh script, but this script tries to kill xbmc.bin process. This does not seem to work, at least in my configuration, XBMC continues being displayed even it retroarch is launched.

My modified applaunch.sh script does a sudo /etc/init.d/xbmc stop (I have set up sudoers file) instead of killing the xbmc.bin process. In the first version this did not remove XBMC last displayed screen, and the emulator didn’t appear on screen. The trick is to deactivate the HDMI output and activate again, like this:

#!/bin/bash

# Check for arguments
if [ -z "$*" ]; then
echo "No arguments provided."
echo "Usage:"
echo "launcher.sh [/path/to/]executable [arguments]"
exit
fi

echo "Trying to stop xbmc "
sudo /etc/init.d/xbmc stop
# Deactivates HDMI output
sudo /opt/vc/bin/tvservice -o
# Activates HDMI output again
sudo /opt/vc/bin/tvservice -p

# Wait for the kill
sleep 1

echo "$@"

# Launch app - escaped!
"$@"

echo "Emulator terminated"

# Done? Restart XBMC
sudo /etc/init.d/xbmc start

This way xbmc disapears and the emulator appears. Not very fast, but it works. If someone finds another better way, I would like to know…