Kodi Community Forum

Full Version: Porting libretro cores to Kodi
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
See status of all game add-ons: Game_add-ons (wiki)

Here's my explanation of how to port libretro cores to Kodi.

For this example I'm going to use Mupen64Plus (game.libretro.mupen64plus from https://github.com/libretro/mupen64plus-libretro)

This will cover:

  1. Creating the add-on fluff
  2. Defining the controllers and their buttonmaps
  3. Adding the libretro core as a dependency
  4. Importing the add-in into Kodi's binary add-on build system.

1. Add-on fluff

This consists of four files:

CMakeLists.txt - the build system that imports the libretro core dependency

addon.xml.in - the add-on definition. The schema is still subject to change (the <platforms> tag isn't used and needs to be changed).

(optional) changelog.txt - this file is not required

icon.png - shown in the GUI. Try searching deviantart, and be nice and credit the author in the addon.xml description.

2. Controllers and button map

Kodi's controller add-ons allow independent button maps for each platform. The available controller add-ons can be found in the kodi-game-controllers repo.

game.libretro.mupen64plus uses the controller add-on game.controller.n64. Specify all the supported controllers by importing them in addon.xml:

Code:
<requires>
    <import addon="game.controller.n64" version="1.0.0"/>
</requires>

If a platform's controller doesn't exist in the game controllers repo, you have two options:
  • (preferred) Create a controller (see the game controllers readme) and send a pull request or host it yourself
  • Don't import a game controller add-on. The game add-on will receive input in the form of the default controller

Next, create resources/buttonmap.xml. This file maps the controller add-on to the "RetroPad" abstraction that libretro uses.

Code:
<buttonmap>
  <controller id="game.controller.n64" type="analog">
    <feature name="a" mapto="a"/>
    <feature name="b" mapto="b"/>
    <feature name="cup" mapto="x"/>
    <feature name="cdown" mapto="r3"/>
    <feature name="cright" mapto="l3"/>
    <feature name="cleft" mapto="y"/>
    <feature name="start" mapto="start"/>
    <feature name="up" mapto="up"/>
    <feature name="down" mapto="down"/>
    <feature name="right" mapto="right"/>
    <feature name="left" mapto="left"/>
    <feature name="leftbumper" mapto="l"/>
    <feature name="rightbumper" mapto="r"/>
    <feature name="z" mapto="l2"/>
    <feature name="analogstick" mapto="leftstick"/>
  </controller>
</buttonmap>

Create a <controller> element for each imported controller add-on. The type attribute corresponds to the libretro device type. Basically, if the controller has analog sticks, use the "analog" type. Otherwise, use the "joypad" type (as in game.libretro.genplus's buttonmap.xml)

The feature name is from the controller add-on's layout.xml.

The available "mapto" features are defined in LibretroTranslator::GetFeatureIndex().

3. Adding the libretro core as a dependency

Create depends/common/mupen64plus/mupen64plus.txt pointing to the libretro repo (use hash or "master"):

Code:
mupen64plus https://github.com/libretro/mupen64plus-libretro 1ec2a3a

Create depends/common/mupen64plus/windows-deps.txt with the following contents:

Code:
mingw

depends/common/mupen64plus/CMakeLists.txt - the build command needs to point to the libretro Makefile of libretro's Mupen64Plus repo. You might need to use make -f Makefile.libretro as in FCEUmm's CMakeLists.txt or make -C libretro as in Nestopia's CMakeLists.txt. Here, the Makefile is in the "libretro" directory. Notice the extra "libretro" in Nestopia's install() command in CMakeLists.txt:

Code:
#install the generated shared library
install(FILES ${PROJECT_SOURCE_DIR}/libretro/nestopia_libretro${CMAKE_SHARED_LIBRARY_SUFFIX}
    DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)

Finally, add any patches required directly to the folder with the .patch extension.

4. Importing the add-on to Kodi

As uncomfortable as the switch to Kodi's new CMake system was, it sure has its benefits. Adding a new add-on only requires a (github) target commit and list of platforms it should be built for. see project/cmake/addons/addons/game.libretro.mupen64plus

Build instructions can be found in RetroPlayer's readme.
nice thanks, for the description.
I'll try this with mupen64 - is it already possible to map analog axes?
i've mostly updated mupen64 already. analog sticks are still a TODO in the code
wow thanks - forgot to watch the kodi-game repos in github...
I tried yesterday evening CET and was able to drive mario's kart straight into the wall xD
If analog sticks are working I think there's good chance we can have some good time testing Wink
Please sticky this?

EDIT: And wiki it?
@nedscott ^^^
Can please someone simplify this for the noobs ,this is an amazing subject
(2015-04-15, 00:05)DolGuldur Wrote: [ -> ]Can please someone simplify this for the noobs ,this is an amazing subject

I don't think you intended this by your comment, but haphazardly you are making garbear's post sound too complicated and not well enough explained

I on the other hand, will likely never port a libretro core to Kodi. I will probably never do a pull request for Kodi (never have before, not likely to start anytime soon . . . just not my expertise at all). All that being said, I found the post/explanation very easy to follow. The links and examples were helpful, and surely overtime things may be added but it's a very good first pass. I don't usually follow this line of reasoning, but if that was too complicated to follow then you are probably just not the target audience (i.e. - not likely to ever port a core to kodi)

Realize that retroplayer will have a large number of cores for you to play most games already, this is really only dev stuff for devs in the dev area of the forum Wink
(2015-04-14, 23:26)natethomas Wrote: [ -> ]@nedscott ^^^

We need to get a notification thing for MyBB. I don't have tapatalk installed and only saw this thread by total chance :D
We have a wiki page for game add-ons now: Game_add-ons (wiki)
(2015-04-20, 08:47)garbear Wrote: [ -> ]We have a wiki page for game add-ons now: Game_add-ons (wiki)

Nice summary, thx for that!
This is pretty awesome. Where can I help out? Cool
I updated the OP to reflect the transition to importing libretro cores as binary add-on depends. I hope it's detailed enough in case anyone can help with porting the remaining cores (see kodi-game page 2 - anything older than 2015-06-17 still needs some work)
the icon.png and addon.xml gives me a 404-error.
lol, mupen64 doesn't have an icon.png

addon.xml 404 fixed, thanks
Pages: 1 2