MCPcopy Index your code
hub / github.com/aksiksi/gbc

github.com/aksiksi/gbc @v0.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1 ↗ · + Follow
256 symbols 621 edges 15 files 95 documented · 37%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

gbc

Rust

A Gameboy Color (GBC) emulator written in Rust. This is intended as a learning project.

Quick Start

1. Download

Visit the Releases page and download the latest version for your OS.

2. Run

Run a ROM:

gbcemu run [path_to_rom]

Run with -h to view all flags and options.

3. Play

Controls:

  • Arrows for direction keys
  • S: A button
  • A: B button
  • Enter: start button
  • Shift: select button

Emulator keys:

  • *: reset the emulator
  • O: draw basic tile outline (toggle)
  • P: pause (toggle)

Games Tested

  • [x] Dr. Mario (DMG, no ROM banking)
  • [x] Tetris World (DMG, no ROM banking)
  • [x] Kirby's Dream Land (DMG, MBC1)
  • [x] Tetris World DX (GBC, MBC1)
  • [x] Super Mario Bros. Deluxe (GBC, MBC5)
  • [x] Pokemon Yellow (GBC, MBC5)
  • [x] Donkey Kong Country (GBC, MBC5)
  • [x] Dragon Warrior Monsters (GBC, MBC5)
  • [x] The Legend of Zelda: Link's Awakening DX (GBC, MBC5)

Details

Project Structure

The emulator is divided into two crates:

  1. lib: the main library for emulating a Gameboy
  2. emu: the emulator frontend GUI (using SDL)

Tests

There are two types of tests:

  1. Functional tests: verify the basic functions of the CPU and peripherals
  2. Integration tests: run existing test ROMs and ensure that they pass

These tests run on every commit to the repo.

Building

Due to the SDL dependency, you have to install some dependencies before you can build the emulator. Note that SDL is automatically built as part of the Rust-SDL2 build script, but the script needs a few tools:

  1. CMake
  2. C compiler (MSVC, GCC, Clang)

Since we statically link against libsdl on all platforms to avoid having to ship the DLL with the emulator, you do not need to install SDL for the build.

Windows

  1. Install the VSC++ build tools: https://visualstudio.microsoft.com/visual-cpp-build-tools/
  2. Install rustup (this also installs rustc and cargo): https://www.rust-lang.org/tools/install
  3. Install CMake: https://cmake.org/download/
  4. cargo build

The full build in release mode (including SDL) on a 10 core Windows VM takes ~1 min.

Debugger

The emulator comes with a simple GDB-like debugger CLI. Note that the debugger is not included by default.

To build the emulator with debugger support:

cargo build --manifest-path emu/Cargo.toml --features debug

As soon as you run the emulator, it will jump into the REPL. The following commands are available:

  • n: Step to the next instruction.
    • n <num>: Skip the next num instructions.
  • info [r]egs: Dump all registers.
  • p <addr>: Print the byte at the specified memory address.
  • b <addr>: Set a breakpoint on an instruction address. Note that you can have multiple active breakpoints.
  • info [b]reak: List all breakpoints that have been set.
  • disable <index>: Disable the breakpoint with the given index.
  • d <index>: Delete the breakpoint with the given address.
  • r: Continue running the emulator until the next breakpoint is hit.
  • [l]ist: Disassemble the next five instructions, starting from the current one.
    • [l]ist <count>: Disassemble the next count instructions, starting from the current one.
  • [h]ist: Dump the last five executed instructions.
    • [h]ist <count>: Dump the last count executed instructions.

Extension points exported contracts — how you extend this code

MemoryRead (Interface)
Generic traits that provide access to some memory. `A` is the address size, and `V` is the value size. [9 implementers]
lib/src/memory.rs
MemoryWrite (Interface)
(no doc) [9 implementers]
lib/src/memory.rs
RegisterOps (Interface)
A trait that defines basic register operations. [2 implementers]
lib/src/registers.rs
HalfCarry (Interface)
Small trait that abstracts computation of half-carry between two numbers [2 implementers]
lib/src/cpu.rs

Core symbols most depended-on inside this repo

write
called by 111
lib/src/ppu.rs
read
called by 95
lib/src/ppu.rs
set
called by 67
lib/src/cpu.rs
execute
called by 51
lib/src/cpu.rs
get_cpu
called by 16
lib/src/cpu.rs
push
called by 15
lib/src/cpu.rs
clear
called by 11
lib/src/registers.rs
carry
called by 11
lib/src/registers.rs

Shape

Method 177
Function 33
Class 23
Enum 19
Interface 4

Languages

Rust100%

Modules by API surface

lib/src/cpu.rs51 symbols
lib/src/ppu.rs47 symbols
lib/src/cartridge.rs42 symbols
lib/src/memory.rs26 symbols
lib/src/registers.rs19 symbols
lib/src/joypad.rs14 symbols
lib/src/instructions.rs13 symbols
lib/src/lib.rs11 symbols
lib/src/timer.rs7 symbols
lib/src/debug.rs7 symbols
emu/src/main.rs7 symbols
lib/src/dma.rs5 symbols

For agents

$ claude mcp add gbc \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact