Skip to content

Repository files navigation

raylib-libretro 👾 Tests

libretro frontend to play emulators for Windows, Mac, Linux, and the Web with raylib. The raylib-libretro.h allows integrating any raylib application with the libretro API. Still in early development.

Screenshot of raylib-libretro

Features

  • Multi-System Emulator for NES, SNES, GB, GBA, SMS/GG, PlayStation
  • Shipped Cores: fceumm, snes9x, mgba, genesis_plus_gx, prboom, pcsx_rearmed, mednafen_psx_hw
  • Hardware-accelerated OpenGL rendering for GPU-rendered cores
  • Gamepad, Keyboard, On-Screen Controls
  • Audio
  • Fast Forward, Slow Motion, Rewind
  • Save Slots and SRAM
  • Shaders
  • Menu Themes
  • Core Options
  • Zip File Support

Cores

System Core Extensions
Nintendo Entertainment System (NES)** fceumm .fds, .nes, .unf, .unif
Super Nintendo (SNES) snes9x .smc, .sfc, .swc, .fig, .bs, .st
Game Boy / Color / Advance mgba .gba, .gb, .gbc, .sgb
Sega Genesis / Mega Drive / Master System / Game Gear genesis_plus_gx .bin, .gen, .smd, .md, .cue, .iso, .chd, .m3u, .sms, .gg, .sg
PC Engine / TurboGrafx-16 mednafen_pce_fast .pce, .cue, .ccd, .chd, .toc, .m3u
WonderSwan / WonderSwan Color mednafen_wswan .ws, .wsc, .pc2
Doom (PrBoom Engine) prboom .wad, .iwad, .pwad, .lmp, .m3u
PlayStation pcsx_rearmed .bin, .cue, .img, .mdf, .pbp, .toc, .cbn, .m3u, .ccd, .chd, .iso
PlayStation (HW) mednafen_psx_hw .cue, .toc, .m3u, .ccd, .exe, .pbp, .chd
PlayStation mednafen_psx .cue, .toc, .m3u, .ccd, .exe, .pbp, .chd

Usage

raylib-libretro [-L <core>] [game]
  • [game] can be a loose ROM file or a .zip archive
  • -L <core> is optional — path to the libretro core (.so/.dll/.dylib)

Example

raylib-libretro -L ~/.config/retroarch/cores/fceumm_libretro.so smb.nes
raylib-libretro -L ~/.config/retroarch/cores/fceumm_libretro.so smb.zip
raylib-libretro smb.nes

Compile

CMake is used to build raylib-libretro...

git clone http://github.com/robloach/raylib-libretro.git
cd raylib-libretro
git submodule update --init
mkdir build
cd build
cmake ..
make

Mac OSX

  • Make sure you have you have cmake/xcode-cli-tools installed
  • Run the above compile instructions
  • After installing RetroArch and some cores, you should be able to run the below:
    bin/raylib-libretro -L ~/Library/Application\ Support/RetroArch/cores/fceumm_libretro.dylib ~/Desktop/smb.nes

API Usage

See raylib-libretro-basic.c for an example of using the API:

InitLibretro("fceumm.so");
LoadLibretroGame("mario.nes");
while (!WindowShouldClose()) {
    UpdateLibretro();
    BeginDrawing();
        ClearBackground(BLACK);
        DrawLibretro();
    EndDrawing();
}
CloseLibretro();

API Reference

See the full API documentation for integration details, CMake setup, and function descriptions.

Quick Reference

bool InitLibretro(const char* core);
bool LoadLibretroGame(const char* gameFile);
bool IsLibretroReady();
bool IsLibretroGameReady();
void UpdateLibretro();
bool LibretroShouldClose();
void DrawLibretro();
void DrawLibretroTint(Color tint);
void DrawLibretroEx(Vector2 position, float rotation, float scale, Color tint);
void DrawLibretroV(Vector2 position, Color tint);
void DrawLibretroTexture(int posX, int posY, Color tint);
void DrawLibretroPro(Rectangle destRec, Color tint);
const char* GetLibretroName();
const char* GetLibretroVersion();
unsigned GetLibretroWidth();
unsigned GetLibretroHeight();
unsigned GetLibretroRotation();
double GetLibretroFPS();
float GetLibretroAspectRatio();
Texture2D GetLibretroTexture();
bool IsLibretroGameRequired();
void ResetLibretro();
void UnloadLibretroGame();
void CloseLibretro();
void SetLibretroVolume(float volume);
float GetLibretroVolume();
bool SetLibretroCoreOption(const char* key, const char* value);
const char* GetLibretroCoreOption(const char* key);
void* GetLibretroSerializedData(unsigned int* size);
bool SetLibretroSerializedData(void* data, unsigned int size);
void SetLibretroMessage(const char* msg, float duration);
bool DrawLibretroMessage();
const char* GetLibretroDirectory(int directory);

Development

Update the dependencies through git submodules...

git submodule update --recursive --remote --init --force

Use clang-format to apply coding standards...

clang-format -i *.h

Build for web with emscripten...

mkdir build
cd build
emcmake cmake .. -DPLATFORM=Web -DCMAKE_BUILD_TYPE=Release
emmake make

To build the Doxygen documentation...

doxygen .Doxyfile

Cores

Cores are downlownloaded straight from libretro's build bot, or libretro-wasm-cores.

Contributors

License

See the individual files to see which license applies.