Launch emulator script

retroarch

#1

Hi !

Using emulationstation on my Gameshell, I wanted to add a new system for diffrents rom hacks. So my system needs to be able to load roms for different consoles.

Retropie do it very well, but I made a little script wish allow to associate default retroarch core per game.

This is pretty simple. Instead of launch the core by the command

retroarch -L ~/apps/emulators/core_name.so yourgame

You can launch my script :

~/apps/emulators/launch.sh yourgame.ext

Note that zip roms are supported ! The script can check the extension of the file inside.

For now the script only manage gb, nes, snes and gba systems but it’s very easy to add anothers !

Just add a statement :

elif [ "$EXTENSION" == "ngpc" ]; then
  SELECTED_CORE="mednafen_ngp_libretro.so" 

for example for Neogeo Pocket Color. Of course you can select the core you want.

A file assoc.txt will be created by the script a looks like this as you laucnh your games :

/home/cpi/games/roms/hacks/Pokemon - Brown version.gb;gambatte_libretro.so
/home/cpi/games/roms/hacks/Super Mario Land - 2012.gb;gambatte_libretro.so
/home/cpi/games/roms/hacks/Pokemon 151 (Red Hack).gb;gambatte_libretro.so
/home/cpi/games/roms/hacks/Metroid/Metroid - MDbtroid.nes;nestopia_libretro.so
/home/cpi/games/roms/msu-1/The Legend of Zelda - A Link to the Past (MSU-1 Video)/alttp_msu.sfc;snes9x_libretro.so
/home/cpi/games/roms/msu-1/Zelda ALTTP Zelda3 Parallel Worlds v1-2-3 Euclid, SePH, Qwertymodo Audio Fix/zpw.sfc;snes9x_libretro.so
/home/cpi/games/roms/hacks/NES/The Legend of Zelda/Another Evil.nes;nestopia_libretro.so
/home/cpi/games/roms/hacks/NES/The Legend of Zelda/Ganon's Curse.nes;nestopia_libretro.so
/home/cpi/games/roms/hacks/NES/The Legend of Zelda/Ganon's Deception.nes;nestopia_libretro.so
/home/cpi/games/roms/hacks/NES/The Legend of Zelda/Ganon's Revenge.nes;nestopia_libretro.so
/home/cpi/games/roms/hacks/NES/The Legend of Zelda/Hyrule's Doom.nes;nestopia_libretro.so
/home/cpi/games/roms/hacks/GBC/Pokemon Prism (v0.94-b0226).gbc;gambatte_libretro.so
/home/cpi/games/roms/msu-1/The Legend of Zelda - A Link To The Past DX (MSU-1)/loz3-dx.sfc;snes9x_libretro.so
/home/cpi/games/roms/gba/Castlevania - Circle of the Moon (Europe).zip;gpsp_libretro.so
/home/cpi/games/roms/gba/Metroid - Fusion (Europe).zip;gpsp_libretro.so
/home/cpi/games/roms/gba/Street Fighter Alpha 3 (Europe).zip;gpsp_libretro.so
/home/cpi/games/roms/gba/Super Mario Advance 2 - Super Mario World (Europe).zip;gpsp_libretro.so
/home/cpi/games/roms/gba/Sword of Mana (Europe).zip;gpsp_libretro.so
/home/cpi/games/roms/gba/Tales of Phantasia (Europe).zip;gpsp_libretro.so
/home/cpi/games/roms/gba/Wario Land 4 (USA-Europe).zip;gpsp_libretro.so

You noticed that each game will be associated with the default core you mentionned in the statement. If you need to, you can change the core name for a specific game as you like.

When you start a game, the script looks in the assoc.txt file if a corresponding line exists. If yes it runs retroarch with the core whose name is mentioned after the semicolon

Of course the script is not perfect but I will update it for sure. So don’t be shy and feel free to give comments and suggestions :wink:

There you are :

 #!/bin/bash
FILE="/home/cpi/apps/emulators/assoc.txt"
ASSOC=0
SELECTED_CORE="null"
GAMETORUN=$1
SYSTEM=$2

# Check if there already an association of game/core in file assoc.txt
while IFS=';' read game core
do
	if [ "$game" == "$1" ]; then
		ASSOC=1
		SELECTED_CORE="$core"
	fi
done < $FILE

# Find the extension of the rom, even if it's zipped
FILENAME=$(basename "$GAMETORUN")
EXTENSION="${FILENAME##*.}"
if [ "$EXTENSION" == "zip" ]; then
  TEMP=`zipinfo -1 "$GAMETORUN"`
  TEMP2=$(basename "$TEMP")
  EXTENSION="${TEMP2##*.}"
fi

#default cores
if [ "$SELECTED_CORE" == "null" ]; then
	if [ "$SYSTEM" == "gb" ] || [ "$EXTENSION" == "gb" ] || [ "$EXTENSION" == "gbc" ]; then
	  SELECTED_CORE="gambatte_libretro.so"
	elif [ "$EXTENSION" == "nes" ]; then
	  SELECTED_CORE="nestopia_libretro.so"
	elif [ "$EXTENSION" == "smc" ] || [ "$EXTENSION" == "fig" ] || [ "$EXTENSION" == "sfc" ]; then
	  SELECTED_CORE="snes9x2005_plus_libretro.so"
	elif [ "$EXTENSION" == "gba" ]; then
	  SELECTED_CORE="gpsp_libretro.so"
	fi
fi

# if we didn't find a line in the assoc file we create it with the selected core
if [ "$ASSOC" == 0 ] && [ "$SELECTED_CORE" != "null" ]; then
	echo "$GAMETORUN;$SELECTED_CORE" >> $FILE
fi

# launch the game
retroarch -L ~/apps/emulators/"$SELECTED_CORE" "$GAMETORUN"

exit

Emulationstation on Gameshell