All Projects → linoscope → CAMLBOY

linoscope / CAMLBOY

Licence: MIT license
A Game Boy emulator written in OCaml that runs in your browser 🐫 🎮

Programming Languages

ocaml
1615 projects
HTML
75241 projects

Projects that are alternatives of or similar to CAMLBOY

mealybug-tearoom-tests
🪲☕️ Game Boy emulator test ROMs
Stars: ✭ 40 (-90.22%)
Mutual labels:  gameboy, gameboy-emulator
Gopher Boy
🎮 A Game Boy emulator written in Go
Stars: ✭ 206 (-49.63%)
Mutual labels:  gameboy, gameboy-emulator
Gbemu
A Gameboy emulator in modern C++
Stars: ✭ 149 (-63.57%)
Mutual labels:  gameboy, gameboy-emulator
ostrich
A Game Boy Sound System player for macOS, written in Swift
Stars: ✭ 37 (-90.95%)
Mutual labels:  gameboy, gameboy-emulator
Rustyboy
A Gameboy emulator written in Rust.
Stars: ✭ 224 (-45.23%)
Mutual labels:  gameboy, gameboy-emulator
Gbemu
WebAssembly based Gameboy Emulator
Stars: ✭ 120 (-70.66%)
Mutual labels:  gameboy, gameboy-emulator
Jitboy
A Game Boy emulator with dynamic recompilation (JIT)
Stars: ✭ 190 (-53.55%)
Mutual labels:  gameboy, gameboy-emulator
Coffee Gb
Gameboy emulator in Java 8.
Stars: ✭ 953 (+133.01%)
Mutual labels:  gameboy, gameboy-emulator
Binjgb
Gameboy emulator implemented in C
Stars: ✭ 222 (-45.72%)
Mutual labels:  gameboy, gameboy-emulator
Mgba
mGBA Game Boy Advance Emulator
Stars: ✭ 3,355 (+720.29%)
Mutual labels:  gameboy, gameboy-emulator
emu-gameboy
A Gameboy emulator written in C++
Stars: ✭ 55 (-86.55%)
Mutual labels:  gameboy, gameboy-emulator
RGB
RGB (Rust Game Boy) is a simple emulator for the original game boy
Stars: ✭ 19 (-95.35%)
Mutual labels:  gameboy, gameboy-emulator
Cryboy
A Game Boy (Color) emulator written in Crystal
Stars: ✭ 68 (-83.37%)
Mutual labels:  gameboy, gameboy-emulator
Giibiiadvance
A GB, GBC and GBA emulator with GB Camera support.
Stars: ✭ 141 (-65.53%)
Mutual labels:  gameboy, gameboy-emulator
Wasmboy
Game Boy / Game Boy Color Emulator Library, 🎮written for WebAssembly using AssemblyScript. 🚀Demos built with Preact and Svelte. ⚛️
Stars: ✭ 963 (+135.45%)
Mutual labels:  gameboy, gameboy-emulator
Metroboy
MetroBoy - A playable, circuit-level simulation of an entire Game Boy
Stars: ✭ 169 (-58.68%)
Mutual labels:  gameboy, gameboy-emulator
Gameboy
🎮 Game Boy emulator written in Rust
Stars: ✭ 17 (-95.84%)
Mutual labels:  gameboy, gameboy-emulator
Vba M Nx
WIP full featured port of VBA-M for Nintendo Switch
Stars: ✭ 11 (-97.31%)
Mutual labels:  gameboy, gameboy-emulator
Goboy
Multi-platform Nintendo Game Boy Color emulator written in Go
Stars: ✭ 2,403 (+487.53%)
Mutual labels:  gameboy, gameboy-emulator
Awesome Gbdev
Contribute
Stars: ✭ 3,016 (+637.41%)
Mutual labels:  gameboy, gameboy-emulator

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

Screenshot

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
  • Audio Processing Unit (APU)
  • Rescript backend
  • MBC5
  • Game Boy Color mode

How to run

Prerequisite

Install opam, OCaml's package manager, if you haven't yet.

Basic setup

# Clone repository
git clone https://github.com/linoscope/CAMLBOY.git
# cd into repository
cd CAMLBOY
# Create local switch for the repository
opam switch create . 4.13.1
eval $(opam env)
# Install system packages required by opam packages (SDL, etc)
opam pin add camlboy.dev . --no-action
opam depext camlboy
# Install opam dependencies
opam install . --deps-only --with-test

How to run with UI

Run with SDL2 UI

# Build
$ dune build
# Usage: main.exe [--mode {default|withtrace|no-throttle}] <rom_path>
# For example:
$ dune exec bin/sdl2/main.exe -- resource/games/tobu.gb

Run with js_of_ocaml UI

# Build
$ dune build
# Serve `_build/default/bin/web` using some server. For example, run the following with python:
$ python -m http.server 8000 --directory _build/default/bin/web
# Now open `localhost:8000` in the browser

How to run benchmarks in headless mode

Benchmark for native build

# Usage: bench.exe [--frames <frames>] <rom_path>
# For example:
$ dune exec bin/sdl2/bench.exe -- resource/games/tobu.gb --frames 1500
ROM path: resource/games/tobu.gb
  Frames: 1500
Duration: 1.453315
     FPS: 1032.123098

Benchmark for js_of_ocaml build

First, follow the steps in "How to run with UI - js_of_ocaml frontend" above. Now open http://localhost:8000/bench.html?frames=<frames>&rom_path=<rom_path>. For example, if you open http://localhost:8000/bench.html?frames=1500&rom_path=./tobu.gb you should see something like this:

web-bench-example

How to run tests

# Run all tests:
$ dune runtest
# Run unit tests only:
$ dune runtest test/unit_tests/
# Run integration tests (tests that use test ROMs):
$ dune runtest test/rom_tests/

More screenshots

Resources

Source of built-in game ROMs:

Footnotes

  1. Note that we can not use this benchmark to compare the FPS with other Game Boy emulators. This is because the performance of an emulator depends significantly on how accurate it is and how much functionality it has. For example, CALMBOY does not implement the APU (Audio Processing Unit), so there is no point in comparing its FPS with emulators with APU support.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].