Skip to content

mpingram/gameboy-emu

Repository files navigation

gameboy-emu

A gameboy emulator written in Go.

How to build this project

Download and install the most recent version of Go from https://golang.org/dl/. Then clone this repo:

$ git clone https://github.com/mpingram/gameboy-emu

To run the tests:

$ go test [-v for verbose]

Currently the emulator isn't functional enough to do anything approximating 'running a game', so testing is just about all you can do with the binary :D

Documentation

The reason building this emulator is fun and not exhausting is the superb documentation work of the gameboy dev community, which has done pretty much all the hard parts between now and 1989.

Here's a list of some of the documentation referenced for this emulator:

And a meta-reference containing some of these docs, as well as other GB related info: https://github.com/gbdev/awesome-gbdev

Architecture

The emulator code is split into three main parts, the CPU, the PPU (Pixel Processing Unit), and the MMU (Memory Management Unit).

CPU

The CPU code is in charge of decoding and executing instructions for the Gameboy's CPU (a SHARP LR35902, which is very similar to the 8080 and Z80 procesors.) The process involves:

  1. Decoding CPU instructions: decode.go reads raw bytes from memory and interprets them as CPU instructions -- e.g. 0x3e 0x01 -> LD A, 0x01 ("Load 0x01 into register A")
  2. Executing the CPU instructions: execute.go takes a CPU instruction and its argument(s) and calls a function that manipulates the state of the CPU and MMU.

The current state of the CPU code is nearly somewhat functional -- most CPU instructions have been implemented, although currently there is no timing accuracy at all and there is in general a long way to go before the CPU is bug-for-bug accurate to the real gameboy.

MMU (Memory Management Unit)

The MMU is responsible for managing the Gameboy's 64KiB memory address space and providing access to the CPU and MMU. This simple role is complicated by a few quirks, including switchable memory banks, read-only areas of memory, and a complex interaction between the CPU and MMU's memory access in the video RAM. For an accessible overview of the complexities of the Gameboy's memory, see the Ultimate Gameboy Talk (also in documentation above)

The current state of the MMU is barely implemented. There's a basic interface to 64kb of memory, but none of the complexities are implemented yet.

PPU (Pixel Processing Unit)

The PPU is a real physical chip on the original Gameboy whose entire job is to display pixels to the Gameboy's LCD screen.

The PPU code in this repository is currently nearly somewhat functional. It can display the Nintendo logo!

About

A (sentimental) gameboy emulator written in Go.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages