Giter Club home page Giter Club logo

camlboy's Introduction

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!

Screenshot

Project goals and non-goals

Goals

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

Stretch goals

  • Achive 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 expese 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)
  • Supports "headless" benchmarking mode, for both native and web, that runs without UI
  • Passes various test roms such as Blargg's cpu_insrts.gb and instr_timing.gb (tests agains Blargg's test roms can be found here, and tests agains 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 10 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.

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

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 bench marks 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/

Project 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

More screenshots

Resources

Source of built-in game ROMs:

camlboy's People

Contributors

linoscope avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.