/gameboy-emulator

Gameboy Emulator written in Rust

Primary LanguageRust

Continuous Integration

CorrodedBoy, a Gameboy Emulator written in Rust

CorrodedBoy is a Gameboy (DMG) Emulator written in Rust. The emulator has two available frontends: one native frontend using SDL2, and a web frontend (through WASM) written using Svelte. The emulator is decently accurate, but lacks certain CPU and GPU cycle accuracies.

Tetris 1 Tetris 2 Legend of Zelda Pokemon Red

Functionality

Tetris, Dr Mario and Super Mario Land, The Legend of Zelda: Link's Awakening and Pokemon Red have been tested and work well. Most other DMG games should also work.

Implemented parts:

  • Complete CPU implementation, lacking certain cycle accuracies. Passes the blargg cpu_instrs and instr_timing test ROMs, but not the mem_timing.
  • Complete GPU implementation, passes Acid2 test rom
  • Complete sound implementation
  • Interrupts
  • Timer
  • Joypad input
  • ROM-only, MBC1 and MBC3 rom support
  • Optional bootrom
  • Savestates using Serialization
  • CPU debugging tool
  • Native frontend (using SDL2)
  • Web frontend (through WASM, Canvas, WebAudio)

Test roms

Passing blargg cpu_instrs and instr_timing. Large refactor needed to pass mem_timing. Passes Acid2 GPU test (except for sprite x-ordering which has been intentionally left out due to planned future Gameboy Color support).
Blargg CPU Instr Acid2

Frontend options

Native

Uses SDL2 in Rust for Graphics, Input and Sound.

Web

Compiles the emulator core to WASM and uses wasm-pack to create a NPM module interface to the emulator. This module is then used to create a Javascript frontend, which uses Canvas and WebAudio.

Build instructions

Native

cargo build --release --package corroded-boy
Run:
./target/release/corroded-boy

Web

cd frontend_web/site
npm install
Run (dev):
npm run dev
Build:
npm run build
The site will now be available under site/public

Key bindings

Key Action
W Up
S Down
A Left
D Right
Space or Z A
Shift or X B
Enter Start
Shift Select
Ctrl Speedup
P Pause/unpause
O Toggle audio
F1 Save Game
F2 Screenshot

Future work

  • Implement proper frequency modulation audio sync for web frontend
  • MBC RTC support (for Pokemon Gold)
  • Implement halting bug correctly
  • Implement proper FIFO GPU pipeline
  • Gameboy Color support

Resources

https://www.youtube.com/watch?v=HyzD8pNlpwI
https://gbdev.io/pandocs/
https://gbdev.gg8.se/wiki/articles/Main_Page
http://imrannazar.com/GameBoy-Emulation-in-JavaScript
https://izik1.github.io/gbops/