maandag 26 mei 2014

XBMC With RetroArch

Hello all!

I have recently posted a video on YouTube showing my home setup which can be found here.
This video shows how I created a small PC powerfull enough to stream movies, tv shows, pictures, play emulation and many other things.

This blog post will be a guide how to setup the emulation portion in XBMC.

I will first cover some basics that are important to understand if you wish to set this up. If you want you can skip this section straight to the actual step by step guide, but if you run into an issue you might solve issues much quicker by reading the first section.

Basic information

Right now the easiest way to do this is to use the "Rom Collection Browser" addon. This addon does 2 things for you:
- launch a rom with the specified emulator using batch commands.
- scrape some popuplar game db sites for nice artwork/screenshots/box art to show the games in a very nice user interface.

Why windows?

XMBX runs great on linux, why would you run windows?
The answer here is quite simple. While I know some basic linux stuff, I'm nowhere capable of setting this up on a linux machine. It should be perfectly possible though.
I just prefer to plugin controllers (maybe install a driver) and stuff works. I bought a rather hefty HTPC to make sure I could run this kind of stuff. 

- Zotac ZBOX ID 83 -
- Added 8 GB ram and a samsung 12GB SSD

Maybe a bit expensive, but if you buy this you'll never look back. And it look nice in a living room (and is very quiet).

Understanding emulators, roms, RetroArch and libretro

The most simple method to play a rom is to download an emulator, download a rom, run the emulator and open the rom.
This is what the RBC (Rom Collection Browser addon) will do for you.
However, there is a new kid on the block (acctually not that new anymore): RetroArch.

Retroarch itself is not an emulator, it's a front end. For the non tech people, a front end means that it is an application that is not centered around actual implementation but rather on how to show it to the end user (in this case, that's you!).
If RetroArch is a front end, then what is the back end? That's libretro.
Libretro is a very interesting library that some great people created.
If I would need to compare libretro to something in our lives it would be easily explained with a shopping center.
Instead of having all kind of stores (emulators) all over the place and each with their own member cards, libretro is the shopping center that provides a building for all those stores to stay in, knowing that the shopping center enforces each shop to follow their rules (i.e. video, audio, gamepad settings).

So instead of having 5 emulator for 5 different systems (e.g. SNES, NES, GameBoy, Genesis, ...) we have just libretro that has 5 cores for each of those systems. RetroArch provides a nice window to make that powerful libretro available to each of us.

So what do we know now?
- We aren't using emulators, we will be using 1 program: RetroArch.
- Instead of launching an emulator, we will launch RetroArch with a specific core.
- Since Retroarch takes care of all the cores, we will only need to configure our video settings, audio settings and gamepad once!
- Retroarch will use your settings and pass it to each core when launching, so if you use a standard SNES like controller, the keys will automatically mapped no matter which core you use.

I hope this wall of text didn't scare you, I think it's a really interesting project which is still growing, so I wanted to make it more known. Back to the basic information!

Launching a rom using command line.

What the addon is designed for is lauching an emulator and passing a commandline argument as to which rom you were launching e.g:
> snes9x.exe "C:/roms/supermario.smc"

I don't know if that is the correct command to launch a rom in the Snes9x emulator, but you get the idea.

Since we will be using RetroArch the command is a little more complex. This is because not only the rom needed to launch but also the core. (You could do it without the core, but I'm pretty sure the last used core will be used which generally isn't what you want).

The format for Retroarch is:

> retroarch.exe -L "pathToCore" "pathToRom"

We will generally want to run an emulator in full screen so we will a "-f" parameter for fullscreen launching:

> retroarch.exe -f -L "pathToCore" "pathToRom"

Let's take it apart to understand what is being done:
"retroarch.exe" this runs the application, everything behind it are commandline parameters (in this case we have 3).
"-f" - The first parameter, this will run in full screen
"-L "pathToCore"" - The second parameter, -L will tell retroarch to use the specified core for launching a rom.
"pathToRom" - The third parameter, this is the full path to the rom that RetroArch must launch.

We will test this when we start the step by step setup.

Step by step guide

Well here it is, the actual guide how to set the whole thing up. This took me much time to research and fine tune so I hope I can save you a lot of time by writing it.
If something is unclear don't hesitate to give me feedback!

Not everything will be in the step by step guide but is still required:
- Installing windows 7
- Downloading and installing XBMC (13 as of writing)
- General knowledge of the Windows OS.

This guide will assume you have a system running Windows 7 with XBMC installed without the RCB addon installed.
You can download XBMC here.

Downloading and configuring RetroArch

To download RetroArch you can google for "RetroArch megapack" and follow the links. At time of writing you can download it here.

Here you will pick the RetroArch megapack for 64 or 32 bit (usually it will be 64 bit unless you're on a very old pc). Make sure you pick the mega pack as it includes many cores. You may also update your local RetroArch directory with a new download now and then as the cores keep getting updated (or extra cores added).

If you wish to follow this guide with minimal complexity, I suggest unzipping the content of the zip file to "C:\RetroArch"


Now that we have RetroArch locally we will start it up, so use a file explorer and navigate to C:/RetroArch.

Setting up game controllers
First we will setup the game controller. You can skip this paragraph if you don't wish to do this now.
The people from RetroArch know this is usually a painful experience so they added an extra tool to help you do this. To setup a single game controller you can find the "retroarch-joyconfig.exe" file in the RetroArch folder and open it.
You will see a command window which asks you several questions and asks you to input the buttons on your game pad. Make sure your game pad is connected and working before you do this.

Configuring RetroArch
Start by launching "retroarch.exe", you will now see a nice looking console window. Pay attention to the welcome screen as it tells you how to navigate (on my system it used the arrows, X and W buttons.
To be honest, there is not a lot to configure here. You can navigate to "Settings" and then configure what you wish (like a second controller).
What you really want to do is test it. I'll test it with a SNES rom called "Secret of Evermore". This rom is located in at "C:/Roms/secret of evermore.smc".
Here is how you test it:
- run retroarch.exe
- navigate to "Load Content (detect core)"
- navigate to the rom location and select the rom
- pick a core. If more cores show up that means retroarch has multiple built-in "emulators" to emulate the rom. Pick one and test them all which suits you best. I'll describe which ones I'm using and why.

Once you selected a core the game should start running and your game pad should be working correctly. If that isn't the case you need to review the steps above again. On a side note, it's normal if the game runs in a window.

If the above is working correctly then everything is ready to let XBMC work with retroarch.

Rom Collection Browser

I will assume you know how to download and install an addon for XBMC, if not I suggest you read other (and better) guides to learn how.

RBC works with collections, for each console you will add a collection and how to run it. In this guide we will setup a collection for SNES games with the correct parameters to run them.

To make the setup as fluid as possible I'll ask you to open some directories to make it easier to add collections:
- open a folder showing the content of "C:/RetroArch/libretro". This is the folder that contains all the emulator cores, you will need the name of the one you wish to use.
- open your rom folder. If you haven't already, I highly recommend having roms in directories per system (SNES together, NES together etc). I didn't do that in this guide since I only wanted to show with a single rom file.

That's it, now you're all set to add your first ROM collection!

Open XBMC, install RCB and open it.
It will now ask you to create a configuration file, select yes.

RCB will present you with the following screen.

Choose the first option "Scrape game info and artwork online". This option will download all the art from external sites (so you will need internet connection for that). The other option is used to restore existing (already scraped) data and collections.

Now RBC will automatically assume you are adding a new collection and will present you with the system screen.

Adding a ROM collection

In the platform screen pick the platform you wish to add roms for, in this guide we'll use SNES.

The next screen will ask you for the emulator you wish to use. In this setup you will always use the same program: retroarch.exe so this is the same for each collection.
Navigate to your "retroarch.exe" file in the C:/RetroArch folder and click OK.

Next it will ask you for emulator params. If you have read the introduction section you have a pretty good idea what is needed here.

Initially it gives you this:


You will need to change that with:

-f -L "path to core" "%ROM%"

The %ROM% will always be substituted by RBC by the full path of the rom, so you can leave that

The "path to core" will be the full path to your emulator core. Remember that I asked to open a directory? You'll need that now, open the C:/RetroArch/libretro directory and find the core you wish to use. For SNES you can use the BSNES core: "bsnes_balanced_libretro.dll".

That would make our paramters:

-f -L "C:/RetroArch/libretro/bsnes_balanced_libretro.dll" "%ROM%" 

Make sure there are spaces between the parameters, this caused me some trouble because the core and rom had no space inbetween!

Next it will ask you the path to your SNES roms. In my (test) setup this is C:/Roms (remember, it's a good idea to split your roms into separate folders per system).
Navigate to the directory, open it and then click OK.

Once you selected the ROM directory, RCB will want to know which files are roms. This is done with an extension.
When we run SNES roms we know the roms will have the SMC extension so we type "*.smc" here (which translates to anything that ends with .smc as the * substitutes everything).
If you have multiple extensions like N64 roms you can add comma's between them like "*.n64, *.v64, *.z64".

So for the SNES collection, we'll add "*.smc".

The next step is setting an artwork directory, this is where RCB will save all images it downloads. I usually just use the same directory as my rom folder (and it defaults there as well), so just click OK.

That was the last step!
RCB will now ask you if you like to add more collections, for now choose NO, but if you are adding all your collections you might find it easier to add them all at once as the scraping takes quite long (much longer than XBMC scraping movies).

Once collections are setup we are presented with an import screen. This screen can be changed to how you want to scrape and which sites you will use for scraping.
The scraping mode is quite interesting as the scraper will get the wrong game for you quite often, there is a mode that shows you all the options it has found and you select the correct game. While this leaves you with an intact library with great art this takes a very long time. I did my collection over 3 hours (I can't recall the amount of roms I added though, about 300?)

For now we'll go with the defaults and choose for import games.

 RCB will now start scraping for your game information. This process can and will take quite some time so be patient and grab a coffee or so :).

 When it's done you will automatically get to the rom list, and say for yourself, isn't it pretty?
I love how RCB gives me such an interface. You can also customize how it shows these images but I forgot where.

Pressing left will give you the option to filter and or set favorites.
The context menu will give you the option to edit settings, add favorites etc. All the stuff you entered is still configurable in the edit rom collections portion.

When you press enter on the game XBMC should minimize, you should see a command prompt briefly and the game should run full screen with your controller(s) working.

That's all!

Well I hope I've been some help to people that like to setup something like this for themselves.
You may always leave feedback if you have any!

Further tweaks

This section contains further tweaks to enhance your experience with this setup. I will keep expanding this section as fit.

Stretch screen

I noticed that by default RetroArch doesn't stretch, maybe you don't like it, but I do with wide tv formats.

You can change this by opening retroarch.exe and navigating to:
Settings -> Video -> Aspect ratio
There you can choose the aspect ratio which fits your screen by pressing left and right. RetroArch will remember these settings the next time you launch a game from XBMC.

Using external storage for roms

If you have a nice network at home with a NAS or any kind of network space it's a great idea to run your games straight from that location. You can do this easily by mapping a network drive in windows.
You might run into some trouble with windows not always remapping drives on boot but I got around that with a little bat file that I created and remaps the drive again when you log into windows.

A huge plus is that RetroArch (like all emulators) stores save files and save states next to the rom. That means if you have a second setup like this (or a retro pie system) that is pointed to the same location, you start playing in one loction, save your game, move to the other location and load that save and play on! I think that's awesome.

Finding the cores

To find out which cores to use you can use retroarch.exe and navigate to "Core".
There you will find a list of all the systems your retroarch has cores for, it will also tell you the name of the core.
Then it's up to you to find the correspondig core in the libretro folder of your RetroArch directory.
Make sure you don't mistype anything or the game won't properly load.
It might be a good idea to try running the game trough the command prompt yourself typing the full command yourself e.g.  "-f -L "C:/RetroArch/libretro/core.dll" "C:/Roms/rom.smc". That way you can see what errors show up instead of the command window immediately closing.

Optional donate link:

7 opmerkingen:

  1. Can you help me set this up..I followed your tutorial step by step but still wont launch from Kodi..Help please, Thank you Duane...

    1. I'm sorry I didn't see your reaction sooner. Didn't thing questions would pop up here.
      Why don't you try launching from a command line first? just open start and type "cmd"
      then navigate to your retroarch folder (assuming it's on your C root)
      cd RetroArch
      then type your command completely
      retroarch.exe -f -L "C:/RetroArch/libretro/bsnes_balanced_libretro.dll" "C:/Roms/secret_of_evermore.smc"
      I used the paths used in the tutorial. See if you can get the game working like this first. If this fails we need to fix this first.

  2. Duane i thing this tutorial doesnt work with kodi..try advanced launcher instead..

    1. The tutorial should still work with Kodi as I upgraded to the latest one (Isengard) and still successfully run everything.
      Maybe something small has changed but the main way of setting things up still works.

  3. Seriously the algorithm for RCB seems to be something like
    (1) Send an API call with the filename to look up matching ROMs
    (2) Sleep for at least five minutes
    (3) If it doesn't match exactly, try a fuzzy look up
    (4) Sleep for another five minutes
    (5) Fail somehow and hang forever