Gekkio/mooneye-gb

A Game Boy research project and emulator written in Rust

Rust

971

704 commits

updated Mar 16, 2023

See the code

README

Mooneye GB

Mooneye GB is a Game Boy research project and emulator written in Rust.

Build Status

The main goals of this project are accuracy and documentation. Some existing emulators are very accurate (Gambatte, BGB >= 1.5) but are not documented very clearly, so they are not that good references for emulator developers. I want this project to document as clearly as possible why certain behaviour is emulated in a certain way. This also means writing a lot of test ROMs to figure out corner cases and precise behaviour on real hardware.

For documentation about known behaviour, see Game Boy: Complete Technical Reference

Looking for the mooneye-gb test ROMs? They are now part of Mooneye Test Suite.

Non-goals:

  • CGB (Game Boy Color) support. It would be nice, but I want to make the normal Game Boy support extremely robust first.
  • A debugger
  • A good user interface. Building native UIs with Rust is a bit painful at the moment.

Warning:

  • Project is WIP
  • Doesn't work properly without a boot ROM
  • The emulator is lagging behind hardware research. I don't want to spend time making short-lived and probably incorrect fixes to the emulator if I'm not sure about the hardware behaviour.

Performance

Always compile in release mode if you care about performance!

On a i7-3770K desktop machine I can usually run ROMs with 2000 - 4000% speed. Without optimizations the speed drops to 150 - 200%, which is still fine for development purposes.

Raspberry Pi with X11 desktop works but is too slow because there is no OpenGL acceleration.

The emulator is runnable on Android, but cross-compiling and packaging is a huge pain and touch controls would have to be implemented, so I'm not supporting Android at the moment.

Running the emulator

Requirements:

  • Rust 1.26
  • SDL2 development libraries for your platform must be installed

GUI

  1. cargo run --release
  2. Follow the instructions

Command-line

  1. Acquire a Game Boy bootrom, and put it to $HOME/.local/share/mooneye-gb/bootroms/dmg_boot.bin
  2. cargo build --release
  3. cargo run --release -- PATH_TO_GAMEBOY_ROM

On Windows, also download an SDL2 package containing SDL2.dll, and put it to target/debug and target/release.

Game Boy keys

Game BoyKey
DpadArrow keys
AZ
BX
StartReturn
SelectBackspace

Other keys

FunctionKey
Fast forwardShift
Toggle performance overlayF2

Test suite

Blargg's tests

Testmooneye-gb
cpu instrs๐Ÿ‘
dmg sound 2โŒ
instr timing๐Ÿ‘
mem timing 2๐Ÿ‘
oam bug 2โŒ
cgb sound 2

Notes:

  • cpu_instrs fails on MGB/SGB2 hardware and emulators emulating them correctly. The ROM incorrectly detects the device as CGB, and attempts to perform a CPU speed change which causes a freeze (STOP instruction with joypad disabled)
  • dmg_sound-2 test #10 can fail randomly on real hardware and seems to depend on non-deterministic behaviour.
  • oam_bug-2 fails on all CGB, AGB, and AGS devices
  • cgb_sound-2 test #03 fails on CPU CGB, CPU CGB A, and CPU CGB B

Mooneye GB acceptance tests

Testmooneye-gb
add sp e timing๐Ÿ‘
boot div dmg0โŒ
boot div dmgABCmgbโŒ
boot div SโŒ
boot div2 SโŒ
boot hwio dmg0โŒ
boot hwio dmgABCmgbโŒ
boot hwio S๐Ÿ‘
boot regs dmg0๐Ÿ‘
boot regs dmgABC๐Ÿ‘
boot regs mgb๐Ÿ‘
boot regs sgb๐Ÿ‘
boot regs sgb2๐Ÿ‘
call timing๐Ÿ‘
call timing2๐Ÿ‘
call cc_timing๐Ÿ‘
call cc_timing2๐Ÿ‘
di timing GS๐Ÿ‘
div timing๐Ÿ‘
ei sequence๐Ÿ‘
ei timing๐Ÿ‘
halt ime0 ei๐Ÿ‘
halt ime0 nointr_timing๐Ÿ‘
halt ime1 timing๐Ÿ‘
halt ime1 timing2 GS๐Ÿ‘
if ie registers๐Ÿ‘
intr timing๐Ÿ‘
jp timing๐Ÿ‘
jp cc timing๐Ÿ‘
ld hl sp e timing๐Ÿ‘
oam dma_restart๐Ÿ‘
oam dma start๐Ÿ‘
oam dma timing๐Ÿ‘
pop timing๐Ÿ‘
push timing๐Ÿ‘
rapid di ei๐Ÿ‘
ret timing๐Ÿ‘
ret cc timing๐Ÿ‘
reti timing๐Ÿ‘
reti intr timing๐Ÿ‘
rst timing๐Ÿ‘

Bits (unusable bits in memory and registers)

Testmooneye-gb
mem oam๐Ÿ‘
reg f๐Ÿ‘
unused_hwio GS๐Ÿ‘

Instructions

Testmooneye-gb
daa๐Ÿ‘

Interrupt handling

Testmooneye-gb
ie push๐Ÿ‘

OAM DMA

Testmooneye-gb
basic๐Ÿ‘
reg_read๐Ÿ‘
sources GS๐Ÿ‘

PPU

Testmooneye-gb
hblank ly scx timing GS๐Ÿ‘
intr 1 2 timing GS๐Ÿ‘
intr 2 0 timing๐Ÿ‘
intr 2 mode0 timing๐Ÿ‘
intr 2 mode3 timing๐Ÿ‘
intr 2 oam ok timing๐Ÿ‘
intr 2 mode0 timing spritesโŒ
lcdon timing GSโŒ
lcdon write timing GSโŒ
stat irq blockingโŒ
stat lyc onoffโŒ
vblank stat intr GS๐Ÿ‘

Serial

Testmooneye-gb
boot sclk align dmgABCmgbโŒ

Timer

Testmooneye-gb
div write๐Ÿ‘
rapid toggle๐Ÿ‘
tim00 div trigger๐Ÿ‘
tim00๐Ÿ‘
tim01 div trigger๐Ÿ‘
tim01ย ๐Ÿ‘
tim10 div trigger๐Ÿ‘
tim10๐Ÿ‘
tim11 div trigger๐Ÿ‘
tim11๐Ÿ‘
tima reload๐Ÿ‘
tima write reloading๐Ÿ‘
tma write reloading๐Ÿ‘

Mooneye GB emulator-only tests

MBC1

Testmooneye-gb
bits bank1๐Ÿ‘
bits bank2๐Ÿ‘
bits mode๐Ÿ‘
bits ramg๐Ÿ‘
rom 512kb๐Ÿ‘
rom 1Mb๐Ÿ‘
rom 2Mb๐Ÿ‘
rom 4Mb๐Ÿ‘
rom 8Mb๐Ÿ‘
rom 16Mb๐Ÿ‘
ram 64kb๐Ÿ‘
ram 256kb๐Ÿ‘
multicart rom 8Mb๐Ÿ‘

MBC2

Testmooneye-gb
bits ramg๐Ÿ‘
bits romb๐Ÿ‘
bits unused๐Ÿ‘
rom 512kb๐Ÿ‘
rom 1Mb๐Ÿ‘
rom 2Mb๐Ÿ‘
ram๐Ÿ‘

MBC5

Testmooneye-gb
rom 512kb๐Ÿ‘
rom 1Mb๐Ÿ‘
rom 2Mb๐Ÿ‘
rom 4Mb๐Ÿ‘
rom 8Mb๐Ÿ‘
rom 16Mb๐Ÿ‘
rom 32Mb๐Ÿ‘
rom 64Mb๐Ÿ‘

Mooneye GB manual tests

Testmooneye-gb
sprite priority๐Ÿ‘

Mooneye GB misc tests

Testmooneye-gb
boot div A
boot div cgb0
boot div cgbABCDE
boot hwio C
boot regs A
boot regs cgb

Bits

Testmooneye-gb
unused hwio C

PPU

Testmooneye-gb
vblank stat intr C

License and copyright

Mooneye GB is licensed under GPLv3+. Copyright (C) 2014-2020 Joonas Javanainen [email protected]

emulator
game-boy
gameboy
gameboy-emulator
rust

Gekkio/mooneye-gb

A Game Boy research project and emulator written in Rust

Rust

971

704 commits

updated Mar 16, 2023

See the code

README

Mooneye GB

Mooneye GB is a Game Boy research project and emulator written in Rust.

Build Status

The main goals of this project are accuracy and documentation. Some existing emulators are very accurate (Gambatte, BGB >= 1.5) but are not documented very clearly, so they are not that good references for emulator developers. I want this project to document as clearly as possible why certain behaviour is emulated in a certain way. This also means writing a lot of test ROMs to figure out corner cases and precise behaviour on real hardware.

For documentation about known behaviour, see Game Boy: Complete Technical Reference

Looking for the mooneye-gb test ROMs? They are now part of Mooneye Test Suite.

Non-goals:

  • CGB (Game Boy Color) support. It would be nice, but I want to make the normal Game Boy support extremely robust first.
  • A debugger
  • A good user interface. Building native UIs with Rust is a bit painful at the moment.

Warning:

  • Project is WIP
  • Doesn't work properly without a boot ROM
  • The emulator is lagging behind hardware research. I don't want to spend time making short-lived and probably incorrect fixes to the emulator if I'm not sure about the hardware behaviour.

Performance

Always compile in release mode if you care about performance!

On a i7-3770K desktop machine I can usually run ROMs with 2000 - 4000% speed. Without optimizations the speed drops to 150 - 200%, which is still fine for development purposes.

Raspberry Pi with X11 desktop works but is too slow because there is no OpenGL acceleration.

The emulator is runnable on Android, but cross-compiling and packaging is a huge pain and touch controls would have to be implemented, so I'm not supporting Android at the moment.

Running the emulator

Requirements:

  • Rust 1.26
  • SDL2 development libraries for your platform must be installed

GUI

  1. cargo run --release
  2. Follow the instructions

Command-line

  1. Acquire a Game Boy bootrom, and put it to $HOME/.local/share/mooneye-gb/bootroms/dmg_boot.bin
  2. cargo build --release
  3. cargo run --release -- PATH_TO_GAMEBOY_ROM

On Windows, also download an SDL2 package containing SDL2.dll, and put it to target/debug and target/release.

Game Boy keys

Game BoyKey
DpadArrow keys
AZ
BX
StartReturn
SelectBackspace

Other keys

FunctionKey
Fast forwardShift
Toggle performance overlayF2

Test suite

Blargg's tests

Testmooneye-gb
cpu instrs๐Ÿ‘
dmg sound 2โŒ
instr timing๐Ÿ‘
mem timing 2๐Ÿ‘
oam bug 2โŒ
cgb sound 2

Notes:

  • cpu_instrs fails on MGB/SGB2 hardware and emulators emulating them correctly. The ROM incorrectly detects the device as CGB, and attempts to perform a CPU speed change which causes a freeze (STOP instruction with joypad disabled)
  • dmg_sound-2 test #10 can fail randomly on real hardware and seems to depend on non-deterministic behaviour.
  • oam_bug-2 fails on all CGB, AGB, and AGS devices
  • cgb_sound-2 test #03 fails on CPU CGB, CPU CGB A, and CPU CGB B

Mooneye GB acceptance tests

Testmooneye-gb
add sp e timing๐Ÿ‘
boot div dmg0โŒ
boot div dmgABCmgbโŒ
boot div SโŒ
boot div2 SโŒ
boot hwio dmg0โŒ
boot hwio dmgABCmgbโŒ
boot hwio S๐Ÿ‘
boot regs dmg0๐Ÿ‘
boot regs dmgABC๐Ÿ‘
boot regs mgb๐Ÿ‘
boot regs sgb๐Ÿ‘
boot regs sgb2๐Ÿ‘
call timing๐Ÿ‘
call timing2๐Ÿ‘
call cc_timing๐Ÿ‘
call cc_timing2๐Ÿ‘
di timing GS๐Ÿ‘
div timing๐Ÿ‘
ei sequence๐Ÿ‘
ei timing๐Ÿ‘
halt ime0 ei๐Ÿ‘
halt ime0 nointr_timing๐Ÿ‘
halt ime1 timing๐Ÿ‘
halt ime1 timing2 GS๐Ÿ‘
if ie registers๐Ÿ‘
intr timing๐Ÿ‘
jp timing๐Ÿ‘
jp cc timing๐Ÿ‘
ld hl sp e timing๐Ÿ‘
oam dma_restart๐Ÿ‘
oam dma start๐Ÿ‘
oam dma timing๐Ÿ‘
pop timing๐Ÿ‘
push timing๐Ÿ‘
rapid di ei๐Ÿ‘
ret timing๐Ÿ‘
ret cc timing๐Ÿ‘
reti timing๐Ÿ‘
reti intr timing๐Ÿ‘
rst timing๐Ÿ‘

Bits (unusable bits in memory and registers)

Testmooneye-gb
mem oam๐Ÿ‘
reg f๐Ÿ‘
unused_hwio GS๐Ÿ‘

Instructions

Testmooneye-gb
daa๐Ÿ‘

Interrupt handling

Testmooneye-gb
ie push๐Ÿ‘

OAM DMA

Testmooneye-gb
basic๐Ÿ‘
reg_read๐Ÿ‘
sources GS๐Ÿ‘

PPU

Testmooneye-gb
hblank ly scx timing GS๐Ÿ‘
intr 1 2 timing GS๐Ÿ‘
intr 2 0 timing๐Ÿ‘
intr 2 mode0 timing๐Ÿ‘
intr 2 mode3 timing๐Ÿ‘
intr 2 oam ok timing๐Ÿ‘
intr 2 mode0 timing spritesโŒ
lcdon timing GSโŒ
lcdon write timing GSโŒ
stat irq blockingโŒ
stat lyc onoffโŒ
vblank stat intr GS๐Ÿ‘

Serial

Testmooneye-gb
boot sclk align dmgABCmgbโŒ

Timer

Testmooneye-gb
div write๐Ÿ‘
rapid toggle๐Ÿ‘
tim00 div trigger๐Ÿ‘
tim00๐Ÿ‘
tim01 div trigger๐Ÿ‘
tim01ย ๐Ÿ‘
tim10 div trigger๐Ÿ‘
tim10๐Ÿ‘
tim11 div trigger๐Ÿ‘
tim11๐Ÿ‘
tima reload๐Ÿ‘
tima write reloading๐Ÿ‘
tma write reloading๐Ÿ‘

Mooneye GB emulator-only tests

MBC1

Testmooneye-gb
bits bank1๐Ÿ‘
bits bank2๐Ÿ‘
bits mode๐Ÿ‘
bits ramg๐Ÿ‘
rom 512kb๐Ÿ‘
rom 1Mb๐Ÿ‘
rom 2Mb๐Ÿ‘
rom 4Mb๐Ÿ‘
rom 8Mb๐Ÿ‘
rom 16Mb๐Ÿ‘
ram 64kb๐Ÿ‘
ram 256kb๐Ÿ‘
multicart rom 8Mb๐Ÿ‘

MBC2

Testmooneye-gb
bits ramg๐Ÿ‘
bits romb๐Ÿ‘
bits unused๐Ÿ‘
rom 512kb๐Ÿ‘
rom 1Mb๐Ÿ‘
rom 2Mb๐Ÿ‘
ram๐Ÿ‘

MBC5

Testmooneye-gb
rom 512kb๐Ÿ‘
rom 1Mb๐Ÿ‘
rom 2Mb๐Ÿ‘
rom 4Mb๐Ÿ‘
rom 8Mb๐Ÿ‘
rom 16Mb๐Ÿ‘
rom 32Mb๐Ÿ‘
rom 64Mb๐Ÿ‘

Mooneye GB manual tests

Testmooneye-gb
sprite priority๐Ÿ‘

Mooneye GB misc tests

Testmooneye-gb
boot div A
boot div cgb0
boot div cgbABCDE
boot hwio C
boot regs A
boot regs cgb

Bits

Testmooneye-gb
unused hwio C

PPU

Testmooneye-gb
vblank stat intr C

License and copyright

Mooneye GB is licensed under GPLv3+. Copyright (C) 2014-2020 Joonas Javanainen [email protected]

emulator
game-boy
gameboy
gameboy-emulator
rust

Significant stargazers

(top 24 of 25)

Linda_pp

1,943 followers ยท starred Nov 2021

Maja Kฤ…dzioล‚ka

291 followers ยท starred Feb 2020

pyfisch

50 followers ยท starred May 2018

Nick Desaulniers

984 followers ยท starred Feb 2018