Retro Boy is a simple Game Boy emulator written in Rust that can be played on the web. Try it here.
Retro Boy is a cycle-accurate Game Boy emulator written in Rust. It uses wasm-pack
to translate the Rust code into WebAssembly so it can be played on the web. The web frontend then uses Web Audio API and HTML Canvas for audio and graphics. It also leverages the browser’s local storage to persist cartridge RAM data for battery-backed MBC cartridges.
- Accurate CPU that passes all JSON CPU tests
- Accurate audio emulation
- Graphics emulation built using a scanline-based renderer
- MBC1, MBC3, MBC5, and HuC1 support
- RTC support for MBC3 cartridges
- Cartridge RAM that persists to browser local storage for battery-backed cartridges
- Support for GameShark or GameGenie cheats
- A web frontend that supports:
- Fullscreen mode
- Pausing/resuming
- Selectable monochrome or color modes
- Customizable key map for game controls
- Management and enabling/disabling of game cheat codes
- A mobile-friendy responsive design
To compile the implementation to WebAssembly, you will first need to install wasm-pack with the command cargo install wasm-pack
if you haven’t done so already. Then, run sh ./build-wasm.sh
to build the core project and generate the Javascript binding code in the web frontend directory.
The web frontend for this emulator is a React/TypeScript app designed with Material UI. It is located in the frontends/web folder. The UI provides the ability to load a ROM as well as play, pause, or reset the emulator. It also provides a fullscreen mode.
To run the web frontend:
- Compile the Rust code to WebAssembly and generate the Javascript binding code as described in the “How to Compile to WebAssembly” section.
- When the binding code is generated, it will be added to the frontends/web/src/core directory.
- Run
yarn install
in the frontends/web directory to install all dependencies. - Run
yarn start
in the same directory to run the application locally.
7 Comments
turnsout
Looks like an awesome addition to the GB emulation world! I know GB Studio can export a web player—I wonder if this implementation has some advantages.
zeta0134
This is awesome! Very nicely done. I hear a few problems with the audio emulation, (mostly clicks that shouldn't be there) but it's been a long while since I had my head wrapped around Gameboy emulation. I'm not sure I know what's going wrong exactly.
I love how Rust+WASM is an enabler for showing off applications like this which would traditionally be restricted to a desktop environment. Here's my own, an NES emulator, using wasm-bindgen for the translation but otherwise a similar setup:
https://rustico.reploid.cafe/?cartridge=patreon/tactus-v0.7-…
It's so cool to work on a bit of homebrew, then be able to share a link with someone and have it "just work" in their browser. No weird tools, no shady sites, just my game and their feedback.
catapart
It plays really slow in Firefox, and there are also audio issues (they may be related?)
But in Chrome, this plays really well! Great work!
codecarter
This is sick. Nicely done
GaggiX
Given the topic, does anyone has some cool homebrew ROM for the gameboy?
GaggiX
Fun fact the emulator works fine on Ladybird too, even thought it's very slow now.
noeatnosleep
Avid millennial gamer here. Wasn't raised with games. Can someone recommend a good classic game to try?