Skip to content

oscarcpozas/gb_emu_rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

If you really want to know how a particular computer works, there's no better way to learn than by emulating that computer. The goal of this project is to emulate the original Game Boy and Game Boy Color in Rust with 100% accuracy compared to the original hardware.

Reading emulator code isn’t easy—at least not for me. To really understand why things are implemented the way they are, you first need a solid grasp of how the original hardware works. And since some components don’t behave quite the way you might expect, the best way to understand, contribute to, or learn from this project is through the documentation. There, I explain each component and the reasoning behind the code in simpler terms, even if more in-depth documentation already exists elsewhere. I also walk through what a full console cycle looks like, from execution to rendering a frame on screen.

Check documentation here: https://oscarcpozas.github.io/gb_emu_rs

Quick set-up

How to run the emulator?

The emulator can run any Game Boy (.gb) game and most Game Boy Color (.gbc) games; you just need to pass the file name as an argument when running it:

cargo run --bin emu -- ./rom/legend_of_zelda.gb

How to generate CPU instructions?

The CPU instructions implemented in instr.rs are generated from a JSON file obtained here: https://gbdev.io/gb-opcodes/optables

You can regenerate the processor instructions by doing the following:

cargo run --bin instr-codegen ./instr-codegen/res/LR35902_opcodes.patched.json ./emu/src/instr.rs

How serve the book?

Documentation on how the emulator works and the decisions made are compiled here in the form of an mdBook. To build or serve the book, you need to have the tool installed.

mdbook build book
mdbook serve book

Accuracy tests

Blargg’s GB tests are a collection of ROMs designed to verify different parts of the emulated hardware, including CPU instructions and timing, graphics, sound, and a few well-known hardware quirks such as the OAM bug and the halt bug. I use them to measure how close the emulator is to accurate, full-system emulation.

🔴 FAILED 🔴 FAILED 🟢 PASSED
🔴 FAILED 🔴 FAILED 🔴 FAILED

References

Thanks to

JetBrains Logo (Main) logo.

About

A rust-based Game Boy emulator for learning and research purposes

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages