Building RetroArch and cores from scratch on Pocket C.H.I.P


#1

Greetings! I’m Auston, author of the Macifom NES emulator and an enthusiastic supporter of C.H.I.P.! For some reason I decided to forego sleep this evening and break in my new Pocket C.H.I.P. by building RetroArch and a few cores from scratch. I thought I might share the recipe as it’s an attractive alternative to Mednafen. C.H.I.P. OS being Debian-based, it was straightforward enough, though I stumbled upon some issues when configuring keyboard input and video.

EDIT: I’ve updated this to build both the SDL v1.2 and v2 drivers, as the former, while it has aspect ratio issues, is much quicker.
EDIT 2: Figured out a workaround for aspect ratio issues with the SDL v1.2 driver and updated my recommended settings for performant, scaled Game Boy video.
EDIT 3: Updated my screenshot to reflect the new recommended settings.

First, you’ll want to open Terminal and pull down the necessary tools and libraries:

sudo apt-get install build-essential git pkg-config libsdl2-dev libsdl1.2-dev

Next, clone the latest RetroArch sources from GitHub and build them. I’ve disabled a number of non-essential features to cut down the dependencies and build time.

git clone https://github.com/libretro/RetroArch.git
cd RetroArch
./configure --enable-sdl --disable--sdl2 --enable-floathard --enable-neon --disable-opengl --disable-gles --disable-vg --disable-fbo --disable-egl --disable-pulse --disable-oss --disable-x11 --disable-wayland --disable-ffmpeg --disable-7zip --disable-libxml2 --disable-freetype
sudo make install

Note: You can instead use --enable-sdl2 --disable-sdl to use SDL v2 and get automatic aspect ratio preservation at the cost of performance. RetroArch does’t seem to be able to support both versions in the same binary.

Once you’re built RetroArch, you can run it from Terminal simply by typing retroarch. Do that to ensure that it works and writes out a default config to ~/.config/retroarch/retroarch.cfg. Depending on which drivers you selected, you may notice that the screen is zoomed in and clipped and the menu doesn’t respond to keyboard input. If so, tap the Home button, select Terminal and hit Ctrl-C to kill RetroArch and continue.

The visual issues can be addressed by adjusting settings in ~/.config/retroarch/retroarch.cfg. I recommend the following for full-screen Game Boy emulation:

video_driver = "sdl"
input_driver = "sdl"
input_joypad_driver = "sdl"
video_scale = "1.000000"
video_fullscreen_x = "302"
video_fullscreen_y = "272"
video_fullscreen = "true"
video_windowed_fullscreen = "false"
video_scale_integer = "false"
video_smooth = "false"
input_keyboard_layout = "us"
audio_latency = "128"

Note: If you built with --enable-sdl2, use ‘sdl2’ in place of ‘sdl’ in the above lines and the specify the full ‘480’ for video_fullscreen_x. The SDL v2 renderer will preserve the proper aspect ratio for each emulated system, though performance suffers. Also, if you’re using SDL v2, you’ll need to set an environment variable to prevent it from rendering with OpenGL, which currently results in atrocious performance:

export SDL_RENDER_DRIVER="software"

With all of that behind us we’re ready to build and install the many emulation cores available in the libretro repository: https://github.com/libretro/
I chose the excellent Gambatte core supplying Game Boy and Game Boy Color emulation for my testing. To try it out, you need only do the following:

First, clone the gambatte-libretro repository and compile the module:

git clone https://github.com/libretro/gambatte-libretro.git
cd gambatte-libretro/libgambatte
make -f Makefile.libretro

This will produce a shared object file that you can reference when invoking RetroArch like so:

retroarch -L "/path/to/gambatte_libretro.so" my_rom_file.gbc

By default the arrow keys are used for the directional pad, Z and X act as action buttons and Return as Start.

Here’s The Legend of Zelda: Oracle of Seasons running smoothly on my Pocket C.H.I.P. using SDL v1.2 and the above settings.


Open GLES Retroarch
How do I configure a generic USB keypad for RetroArch?
Cave story? On chip
RetroArch - Self build cores or download them?
#2

I took a nap and then compiled the snes9x2010 core (better known as SNES9x 1.52) and was able to run Super Nintendo games at about half speed (~26fps).

git clone https://github.com/libretro/snes9x2010.git
cd snes9x2010
make -f Makefile.libretro
retroarch -L snes9x2010_libretro.so /path/to/rom.smc

Time to see what can be done about video performance.


NES Emulation with FCEUX
#3

Sweet!! Good to see people working on another emulation alternatives like some others are doing with Mednafen, Lakka?, and some more standalone emulators. If it actually runs snes roms at less than 30 fps, do you believe that they will run full speed with some optimizations and the coming gpu drivers are ready? I don’t refer to games with SFX/SFX2 chips because those ones are a little heavy even when I run them using Retroarch Gamecube but at least the other ones.


#4

My experience on iOS and OS X has been that drawing to the screen via a slow path with multiple inefficient copies and pixel format swizzling is often more costly than the emulation itself. I think there’s little doubt that a 1Ghz Cortex-A7 can handle semi-accurate (e.g. Snes9X 1.52+) SNES emulation with proper acceleration in place.


#5

So I’ve done a bit more digging today and discovered a few interesting things:

  1. Not terribly surprising but mali_fbdev isn’t working in RetroArch with the included EGL / GLES libraries. Wedging in binaries from Odroid, also not surprisingly, didn’t work.
  2. For some reason SDL v1.2 is 20-50% faster than SDL v2 in RetroArch, especially when any sort of scaling is involved. Unfortunately, RetroArch refuses to preserve the aspect ratio of the game video when in fullscreen mode with the SDL v1.2 driver.
  3. Specifying either ‘sdl’ or ‘sdl2’ as the input_driver allows you to use Pocket C.H.I.P.'s built-in keyboard in RetroArch. ‘linuxraw’ is supposedly also supported but it aborts on launch in my build.

#6

some one managed to run emulationstation, I will try both now :


#7

BRILLIANT! If only i’d seen this in time to go into my review…

I had a go at building uae4arm but i’m no compiler settings expert and don’t know if i did an optimal job… I don’t suppose you’d consider doing the uae core next?


#8

So I’ve done a bit more digging today and discovered a few interesting things:

There are no mali drivers available yet so any GL operations will fail


#9

Thanks for your great work @macifom! I’ve adapted your instructions and put it up on the NTC blog. Keep up the great work!


#10

Thanks for the shout-out, @dcschelt! I have a few more projects up my sleeve :slight_smile: As a side note, I discovered that if you supply the SDL v1.2 renderer with video_fullscreen_x/video_fullscreen_y values smaller than the screen’s native size it centers the resulting image. So you can have good performance and a proper aspect ratio, though you’ll need to adjust your settings for each emulated console. I’ll add in a note in my post.


#11

Good find, @macifom. I’ll have to try this out on my install.


#12

and about https://retropie.org.uk/ ?
is for raspberry and debian, could run on pocket chip?


#13

@pietrondo, retropie appears to require GLES drivers for the Mali GPU. Unfortunately Next Thing and/or AllWinner haven’t released the binary drivers so we don’t have real hardware graphics acceleration yet.


#14

ok!
Because I’m trying it on my raspberry (zero) and is “very good”!
I’ll wait the mali driver


#15

I tried to follow the blog instructions but got stuck at the beginning. When I tried to download the git clone it asks for username and password. I tried entering my github username and password but nothing happens. I get a fatal error. Can someone help? Thanks a bunch. I’m a complete noobie to this but I want to learn.


[APT] Pocket Home (Marshmallow edition)
#16

I got it working, however I need a little help getting a USB keypad/gamepad to work. Anyone tried to map buttons on something that doesn’t get picked up by the built-in mapping function?


#17

Hi all,

First thanks to macifom for very helpful instructions. If you are interested, i just compile retroarch with the following cores:
cap32_libretro.so - AMSTRAD CPC
fceumm_libretro.so - NES
gambatte_libretro.so - GB/GBC
genesis_plus_gx_libretro.so - GENESIS / SMS / GAMEGEAR
gpsp_libretro.so - GBA (bios place into system folder)
gw_libretro.so - GAME AND WATCH
mame2000_libretro.so - Compatible with MAME 0.37b5 romset
mednafen_pce_fast_libretro_libretro.so - PC-ENGINE / CD
pcsx_rearmed_libretro.so - PSX
picodrive_libretro.so - GENESIS
prboom_libretro.so - DOOM (prboom.wad place into rom folder)
snes9x2002_libretro.so - SNES
snes9x2010_libretro.so - SNES
stella_libretro.so - ATARI 2600

I have made an archive containing RetroArch, Cores, Configuration and Dependencies. For install you can follow those instructions (ssh or directly on your pocketchip).

Get archive:
wget https://googledrive.com/host/0Byjn5VPgOpL1LXo1S3hNYVc4Tkk -O RetroArch-PCHIP.tar.gz

Unzip:
tar -xzvf RetroArch-PCHIP.tar.gz

Go to RetroArch folder:
cd RetroArch

Warning, make a copy of your existing config file retroarch.cfg (/home/chip/.config/retroarch/)
Install and configure (default SDL1.2, better performances):
./install.sh
(SDL2: ./install.sh sdl2)

Launching RetroArch:
./retroarch.sh

Additional informations:
RetroArch configs: /home/chip/.config/retroarch/
RetroArch cores: /home/chip/.config/retroarch/cores
Roms folder: /home/chip/Roms

Controls mapping:

  • pad
  • a = 8
  • b = 6
  • x = 5
  • y = 7
  • l = 3
  • r = 4
  • start = enter
  • select = rshift
  • escape = display menu

Thanks for your feedbacks.

You can find more informations here: http://www.open-consoles.com/t10108-retroarch-sur-pocketchip


Mednafen (Emulator) configuration (GBC/GBA/SNES/NES)
#18

Thank you so much for doing this.
It works brilliantly!


#19

If you are grabbing the latest source code from https://github.com/libretro/RetroArch.git, make sure to add the --disable-shaderpipeline flag to the ./configure command or it will not build.


#20

I have one question.
Where do I place the GBA bios?
I can’t find a system folder. I’ve tried placing it in other folders, but it still doesn’t seem to work.
I googled and it seemed like it needed to go into the Roms folder, but this didn’t work either.
Ray