Git Product home page Git Product logo

gbc's Introduction

gbc

Rust

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

donkey_kong_country

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
  • X: start button
  • Z: select button

Emulator GUI keys:

  • K: save emulator state
  • L: load emulator state
  • ;: reset the emulator
  • O: draw basic tile outline (toggle)
  • P: pause (toggle)

Note: these are replaced with buttons in the WASM version.

Games Tested

  • Dr. Mario (DMG, no ROM banking)
  • Tetris World (DMG, no ROM banking)
  • Kirby's Dream Land (DMG, MBC1)
  • Tetris World DX (GBC, MBC1)
  • Super Mario Bros. Deluxe (GBC, MBC5)
  • Pokemon Yellow (GBC, MBC5)
  • Donkey Kong Country (GBC, MBC5)
  • Dragon Warrior Monsters (GBC, MBC5)
  • The Legend of Zelda: Link's Awakening DX (GBC, MBC5)
  • Pokemon Gold (GBC, MBC3+RTC)
    • Hits glitch after intro (#3)
  • Shantae (GBC, MBC5)
    • Not working, stuck on blue screen

Details

Project Structure

The emulator is divided into three crates:

  1. lib: main library for emulating a Gameboy
  2. emu: emulator frontend GUI written using SDL2 (runs on macOS, Windows, and Linux)
  3. emu-wasm: lib compiled to WASM and running on a Canvas2D in JS

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.

gbc's People

Contributors

aksiksi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gbc's Issues

Pokemon Gold: Invalid data written to VRAM

Right after the player first appears, some tiles get invalid tile attributes written to bank 1 of VRAM. The data should have been written to bank 0. For some reason, these invalid writes to the tile map area only occur for 3 lines worth of tiles. Also, the failure is intermittent, even for the same save state.

gbcemu_lowG4G9HlZ

In BGB, writing to the tilemap takes place in this function:

0x20E6: ld de, 0xC3A0
...
0x20F5: ld (0xFF4F), a ; VRAM bank 1
...
0x2101: ldi (hl), a ; write to tilemap
...
0x210F: ld (0xFF4F), a ; VRAM bank 0
...
0x2111: ret

The callstack to get here is:

??: rst 08
0x0008: jp 0x2E27
0x2E27: ld (0xD156), a
...
0x2E31: call 0x2E48
0x2E48: jp (HL) ; passed in prior to rst
??: call 20C3
0x20C3: call 20E6

Work on sound support

This may require a re-write of the core Gameboy to use an event scheduler instead of a lock-step emulation approach.

Failing CGB Acid2 test

The two tests that are failing are:

  • Window internal line counter
  • Background to OAM Priority (bit 7)

Can't run games

So when I use the terminal and start gbcemu with that command + path [.\gbcemu.exe opus5.gb] it gives me an error like this "Found argument 'opus5.gb' which wasn't expected, or isn't valid in this context"

The game is in the same folder. Is there a right way to put this argument in?

Make state persistence more efficient

On write to cart RAM, mark the memory as "dirty". Modify the is_persist_required() method to check the dirty flag for the RAM.

To achieve this, we need separate state for the RAM and RTC. Otherwise, RAM would be cleared out when RTC is persisted but RAM is not dirty.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.