RetroArch on OpenElec

I’ve been working on trying to get RetroArch to work natively on OpenElec for over a month now as the cores are distro agnostic but RetroArch itself is not. My first step was to get a working native toolchain to compile RetroArch with for OpenElec, done. The next step was to get a working or semi-working addon for OpenElec, with a little bit of borrowed code and a lot of my own and tweaks, done. Later I would like to try to get the toolchain portable for use by others especially to try to get it build-bot capable. For now here are test builds for those running x86_x64 builds of OpenElec.

https://www.dropbox.com/sh/91sakv0qdyxjx9f/AAAKWBfDHBtIQtNfnp4rlyXea?dl=0

RetroArch-2015-09-19 Final update, shaders still don’t work due to a Puthon 3 issue but ttsemek has a version with working cg shaders than you can check out here: http://libretro.com/forums/showthread.php?t=1866&p=26610&viewfull=1#post26610

To get an idea of what I have done, here is the code for both retroarch.cfg and rgui.sh

## Skeleton config file for RetroArch

rgui_browser_directory = "/storage/emulators/retroarch/content"
assets_directory = "/storage/emulators/retroarch/assets"
savefile_directory = "/storage/emulators/retroarch/saves"
savestate_directory = "/storage/emulators/retroarch/saves"
libretro_info_path = "/storage/emulators/retroarch/cores"
system_directory = "/storage/emulators/retroarch/system"
rgui_config_directory = "/storage/emulators/retroarch/config"
joypad_autoconfig_dir = "/storage/emulators/retroarch/autoconfig"
video_shader_dir = "/storage/emulators/retroarch/shaders"
video_filter_dir = "/storage/emulators/retroarch/filters/video"
audio_filter_dir = "/storage/emulators/retroarch/filters/audio"
screenshot_directory = "/storage/emulators/retroarch/screenshots"
game_history_path = "/storage/emulators/retroarch/retroarch-content-history.txt"
overlay_directory = "~/.kodi/addons/emulator.retroarch/overlays"
content_directory = "/storage/emulators/retroarch/content"
libretro_directory = "/storage/emulators/retroarch/cores"
libretro_path = ""
config_save_on_exit = true
video_driver = "gl"
video_fullscreen = true
video_vsync = true
audio_enable = true
audio_driver = alsa
audio_device = hw:0,0
input_autodetect_enable = true
#!/bin/sh
ADDON_DIR=$HOME/.kodi/addons/emulator.retroarch
ADDON_FILES=/storage/emulators/retroarch
ADDON_CORES=$ADDON_DIR/cores
RA_CONFIG=/storage/.config/retroarch
LD_LIBRARY_PATH=$ADDON_DIR/lib

if [ ! -d $ADDON_FILES ]; then
  mkdir -p $ADDON_FILES/content
  mkdir -p $ADDON_FILES/cores
  mkdir -p $ADDON_FILES/saves
  mkdir -p $ADDON_FILES/screenshots
  touch $ADDON_FILES/retroarch-content-history.txt
fi

if [ -d $ADDON_DIR/assets ]; then
  mkdir -p $ADDON_FILES/assets
  cp -fr $ADDON_DIR/assets/* $ADDON_FILES/assets
  rm -fr $ADDON_DIR/assets

fi

if [ -d $ADDON_DIR/autoconfig ]; then
  mkdir -p $ADDON_FILES/autoconfig
  cp -fr $ADDON_DIR/autoconfig/* $ADDON_FILES/autoconfig
  rm -fr $ADDON_DIR/autoconfig
fi

if [ -d $ADDON_DIR/config ]; then
  mkdir -p $ADDON_FILES/config
  mkdir -p $RA_CONFIG
  mv -f $RA_CONFIG/retroarch.cfg $RA_CONFIG/retroarch.old >/dev/null
  mv -f $RA_CONFIG/retroarch-core-options.cfg $RA_CONFIG/retroarch-core-options.old >/dev/null
  mv -f $ADDON_FILES/config/retroarch.cfg $ADDON_FILES/config/retroarch.old >/dev/null
  cp -fr $ADDON_DIR/config/* $ADDON_FILES/config
  rm -fr $ADDON_DIR/config
  touch $ADDON_FILES/config/retroarch-core-options.cfg
  ln -s $ADDON_FILES/config/retroarch.cfg $RA_CONFIG/retroarch.cfg
  ln -s $ADDON_FILES/config/retroarch-core-options.cfg $RA_CONFIG/retroarch-core-options.cfg
fi

if [ -d $ADDON_DIR/filters ]; then
  mkdir -p $ADDON_FILES/filters
  cp -fr $ADDON_DIR/filters/* $ADDON_FILES/filters
  rm -fr $ADDON_DIR/filters
fi

if [ -d $ADDON_DIR/shaders ]; then
  mkdir -p $ADDON_FILES/shaders
  cp -fr $ADDON_DIR/shaders/* $ADDON_FILES/shaders
  rm -fr $ADDON_DIR/shaders
fi

if [ -d $ADDON_DIR/system ]; then
  mkdir -p $ADDON_FILES/system
  cp -fr $ADDON_DIR/system/* $ADDON_FILES/system
  rm -fr $ADDON_DIR/system
fi

touch /var/lock/kodi.disabled
systemctl stop kodi

$ADDON_DIR/bin/retroarch &
pid=$!
while kill -0 $pid >/dev/null
  do
    usleep 200000
  done

rm /var/lock/kodi.disabled
systemctl start kodi

Also don’t panic when launching RetroArch as it takes several seconds due to having to shut down then restart Kodi.

Thanks for a great addon! When installing the addon, shouldn’t the structure below ~/Emulators/ be setup by default? As of now the structure is empty, meaning that I need to create the structure by hand?

EDIT 1: Created the folders manually and added the .cfg file, so it’s working now. One problem persist though, when running retroarch-joyconfig, I get following error: “retroarch-joyconfig: error while loading shared libraries: libSDL2-2.0.so.0: cannot open shared object file: No such file or directory”.

EDIT 2:

libSDL2 installed with following sources: ftp://rpmfind.net/linux/opensuse/factor … x86_64.rpm ftp://rpmfind.net/linux/opensuse/factor … x86_64.rpm

But, question still remains regarding the Add-on: Shouldn’t the directories and config-files be correct upon installation?

//Magnus

Hi LordAshram, as usual great work – to avoid Openelec Kodi from shutting down & restarting every time you launch retroarch you could potentially utilize the snippet of code below, that way Kodi is put into a resumable state. It utilizes a bit more memory, but there is no hit on the CPU utilization.

Your code: " touch /var/lock/kodi.disabled systemctl stop kodi

$ADDON_DIR/bin/retroarch & pid=$! while kill -0 $pid >/dev/null do usleep 200000 done

rm /var/lock/kodi.disabled systemctl start kodi "

pgrep kodi.bin | xargs kill -SIGSTOP $ADDON_DIR/bin/retroarch -c $ADDON_FILES/config/retroarch.cfg $EXTRAFLAG -L $ADDON_CORES/$1_libretro.so “$2” & pgrep kodi.bin | xargs kill -SIGCONT

So I’ve edited the default.py to get the plugin to launch directly…

#os.system( "chmod a+rx " + __path__ )
#os.system( "%s '%s' "%(__path__,fn.replace("'", "'\\''")) )
#os.system( __rgui__ )

os.system( "/storage/.kodi/addons/emulator.retroarch/bin/rgui.sh" )

I know, it’s hackish, but I didn’t plan a lot of time for it. Either way, the kodi.log tells me that it can’t find “fn”, so the replace function just breaks. This way it just starts the shell script without building the string from variables.

Any update on this lordashram??

Sorry guys I had to have some extra unforeseen surgeries that has slowed me down while I am recovering. So the only useful thing I have down lately was work on some more boxart when I could, which I will post an update that thread when I get around to it. I will do more updates soon and incorporate some of the code changes mentioned here.

Also, I should have mentioned that running rgui.sh was very important to create all the needed files & folder structure to run this version of RA on OE/Kodi.

Thnaks for the info, and hope you have a speedy recovery!

Hi Lordashram, as usual thanks for all the work you’re doing with the OE build and yes please I hope your recovery is going well. Take all the time you need!

Focus on your recovery first m8 that’s way more important

Nice job on the files though. Still looking for a way to get it all right

It is working now :slight_smile: i had to edit the retroarch.sh I learned very much from your files m8 thanks

amazing work lordashram! It is nice to install as an addon :).

Has anyone managed to get shaders working on this one?

No not yet the last 2 versions have the error with the shaders and cause RA to crash. The last version to work with shaders is in his archieve file dated 26/11/14 i believe but thats based on RA ver 1.0.0.3 and no the newer 1.1 version

I was able to use shaders with the latest version from his dropbox but you cannot use cg shaders and have to use glsl shaders. I have not tested all the shaders but mostly i just use sabr-v3.0.glsl.

Really??, now that i wasnt aware of. I wounder why glsl shader work but cg ones do not. Can cg shaders be converted to glsl shaders i wonder!?

EDIT: I noticed the android build uses glsl shaders, ill give them a go.

This might help out Lordashram in figuring why his last few builds have failed for cg shaders i guess its Intel related!?

Ok have tried a few glsl shaders and they indeed work with Lordhasrams January build. (Great spot 188pilas!!!)

But im having issues getting his version to load a rom through advanced launcher program for OpenElec, i select a game to play but nothing happens. Have any of you guys managed to get it to work through Advanced Launcher???

Ive managed to get Lordhasrams latest build to work in OpenElec now, for some reason RA is looking for a ‘configs’ folder not ‘config’ folder as it should be, there shouldnt be no ‘s’ on the end.

But now when i quit out of a rom i sends me back to the kodi main page and not pack to the rom list. I have tried changing the end of the script in retoracrch.sh from…

touch /var/lock/kodi.disabled
systemctl stop kodi

$ADDON_DIR/bin/retroarch -c $ADDON_FILES/configs/retroarch.cfg $EXTRAFLAG -L $ADDON_CORES/$1_libretro.so "$2" &

pid=$!
while kill -0 $pid >/dev/null
  do
    usleep 200000
  done

rm /var/lock/kodi.disabled
systemctl start kodi

to…

pgrep kodi.bin | xargs kill -SIGSTOP
sleep 1
$ADDON_DIR/bin/retroarch -c $ADDON_FILES/config/retroarch.cfg $EXTRAFLAG -L $ADDON_CORES/$1_libretro.so "$2" &
while [ $(pidof retroarch) ];do
usleep 200000
done;
pgrep kodi.bin | xargs kill -SIGCONT

but once i do this then no games load in Advanced launcher!. I thought it was the line…

$ADDON_FILES/config/retroarch.cfg $EXTRAFLAG -L $ADDON_CORES/$1_libretro.so “$2” &

causing issues as the config didnt have an s at the end but added in configs and it still doesnt work. Anyone have any ideas?. Here the complete retroarch.sh script at the moment…

#!/bin/sh
ADDON_DIR=$HOME/.kodi/addons/emulator.retroarch
ADDON_FILES=/storage/emulators/retroarch
ADDON_CORES=$ADDON_DIR/cores
LD_LIBRARY_PATH=$ADDON_DIR/lib

if [ ! "$#" = "2" ];
then
  echo "Usage: `basename $0` core /path/to/romfile"
  echo "Example: `basename $0` snes9x /storage/mario.sfc"
  echo
  echo "Available cores:"
  echo " `ls -1 $ADDON_CORES/*.so  |  cut -d - -f 1 | cut -d / -f 7`"
  echo
  exit 1
fi

if [ ! -f $ADDON_CORES/$1_libretro.so ]; then
  echo "Core $1 not found, exiting."
  exit 1
fi

if [ ! -f "$2" ]; then
  echo "Rom file $2 not found, exiting."
  exit 1
fi

if [ -f "$2.cfg" ]; then
  echo "Config file for `basename "$2"` found, using."
  EXTRAFLAG="--appendconfig "$2.cfg""
fi

pgrep kodi.bin | xargs kill -SIGSTOP
sleep 1
$ADDON_DIR/bin/retroarch -c $ADDON_FILES/configs/retroarch.cfg $EXTRAFLAG -L $ADDON_CORES/$1_libretro.so "$2" &
while [ $(pidof retroarch) ];do
usleep 200000
done;
pgrep kodi.bin | xargs kill -SIGCONT

It turns out the issue i was having was cause by trying to edit the sh file by my FPT program, it needs to be edited via ssh and nano, now all working.

I have another question, i have noticed that Lordhasram’s latest build doesnt create a /storage/emulator/retroarch/ folder with all the sub folders inside. What needs to be edited to get RA to create these folders upon install???

indeed thanks m8 i downloaded the android shader version and they work nice find

You can download the cores from Linux and replace them so you have the latest cores

or add new ones ofcourse it tested it with one core (mednafen_psx)

I hope Lordashram gets back to working on this again once his health gets better