Skip to content

A Game Boy emulator written in OCaml that runs in your browser 🐫 🎮

License

Notifications You must be signed in to change notification settings

linoscope/CAMLBOY

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build License: MIT

About

CAMLBOY is a Game Boy emulator that runs in the browser. It is written in OCaml and compiled to JavaScript using js_of_ocaml.

Try it out in our demo page!

Accompanied blog posts

Screenshots

Project goals and non-goals

Goals

  • Playable in the browser of middle-tier/high-tier mobile devices
  • Readable/maintainable code that follows OCaml's best practices

Stretch goals

  • Achieve stable 60fps in low-tier mobile devices
  • Serve as a benchmark target for various compile backends, similar to optcarrot in the Ruby world. Would be especially interesting if we can compare the performance of various JS/wasm backends, such as js_of_ocaml, Rescript, Melange, and ocaml-wasm.

Non-goals

  • Run all games with high accuracy
  • Optimize performance to the limit at the expense of code readability

Current state

  • Runs with "playable" FPS in middle-tier mobile devices. (It runs at 60FPS for most games in my Galaxy S9, a smartphone released in 2018)
  • Runs with ~1000FPS, with UI, in native
  • Supports headless benchmarking mode, both for native and web, that runs without UI
  • Passes various test ROMs such as Blargg's cpu_insrts.gb and instr_timing.gb (tests using Blargg's test ROMs can be found here, and tests using Mooneye's test ROMs can be found here).

Benchmark results

We ran the first 1500 frames of Tobu Tobu Girl in headless mode (i.e., without UI) for ten times each and calculated the average FPS. The error bars represent the standard deviation. See benchmark.md for details about the environment/commands used for the benchmark.1

First 1500 frames of Tobu Tobu Girl (in 60FPS)
First 1500 frames of Tobu Tobu Girl (in 1000FPS)

Architecture diagram

Here is a rough sketch of the various modules and their relationship. You can find details in the accompanied blog post.

Directory Structure

  • lib - Main emulator code
  • bin - UI code
    • web - Web
    • sdl2 - SDL2
  • test
    • unit_tests - Unit tests
    • rom_tests - Integration tests that use test roms
  • resource
    • games - Game roms
    • test_roms - Test roms used in rom_tests

TODO

  • Cartridge based save