RHDL includes a cycle-accurate Game Boy emulation system — a complete implementation of the original DMG hardware with Game Boy Color support, featuring the SM83 CPU, pixel processing unit (PPU), audio processing unit (APU), and multiple memory bank controllers.

Running the Emulator

# Load a ROM
rhdl examples gameboy --rom game.gb
 
# Demo mode
rhdl examples gameboy --demo
 
# Force Game Boy Color mode
rhdl examples gameboy --rom game.gbc --gbc
 
# Enable audio
rhdl examples gameboy --rom game.gb --audio

System Architecture

ComponentDescription
SM83 CPUZ80-variant processor at 4.194 MHz
PPUPixel Processing Unit, 160x144 display
APUAudio Processing Unit, 4 sound channels
Memory64KB address space with bank switching
CartridgeMBC1–MBC5 mapper support
TimerConfigurable timer with interrupt
SerialSerial link interface
JoypadButton input interface

Display

DMG Mode

  • 160x144 pixels
  • 4 shades of gray
  • 8x8 pixel tiles
  • Background, window, and sprite layers
  • 40 sprites total, 10 per scanline

GBC Mode

  • 160x144 pixels
  • 32,768 colors (15-bit RGB)
  • Separate palettes for BG and sprites
  • Double-speed CPU mode (8.388 MHz)

Audio System

The APU produces sound through 4 channels:

ChannelTypeFeatures
CH1Square waveFrequency sweep, envelope
CH2Square waveEnvelope (no sweep)
CH3Programmable wave32 samples, 4-bit
CH4NoiseLFSR-based, envelope

All channels are configurable through memory-mapped registers.

Memory Map

AddressDescription
3FFFROM Bank 0 (16KB)
7FFFROM Bank N (switchable)
9FFFVideo RAM (8KB)
BFFFExternal RAM (cartridge)
DFFFWork RAM (8KB)
FE9FSprite Attribute Table (OAM)
FF7FI/O Registers
FFFEHigh RAM (127B)
$FFFFInterrupt Enable Register

Cartridge Mappers

MapperFeatures
No MBC32KB ROM only
MBC1Up to 2MB ROM, 32KB RAM
MBC2Up to 256KB ROM, built-in RAM
MBC3RTC, up to 2MB ROM, 32KB RAM
MBC5Up to 8MB ROM, 128KB RAM

Simulation Backends

Multiple backends available for different performance needs:

# HDL simulation (most accurate)
rhdl examples gameboy --mode ruby --rom game.gb
 
# IR-level (faster)
rhdl examples gameboy --mode ir --sim compile --rom game.gb
 
# Verilator (fastest)
rhdl examples gameboy --mode verilog --rom game.gb

Performance

BackendSpeedNotes
IR Compiler~1.27 MHz~30% of real-time
Verilator>4.19 MHzExceeds real hardware speed

HDL Components

examples/gameboy/hdl/
├── gameboy.rb           # Top-level system
├── cpu/                 # SM83 CPU
│   ├── cpu.rb           # CPU core
│   ├── decoder.rb       # Instruction decode
│   ├── alu.rb           # ALU
│   └── registers.rb     # Register file
├── ppu/                 # Pixel Processing Unit
│   ├── ppu.rb           # PPU core
│   ├── fetcher.rb       # Tile/sprite fetcher
│   └── fifo.rb          # Pixel FIFO
├── apu/                 # Audio Processing Unit
│   ├── apu.rb           # APU core
│   ├── square.rb        # Square wave channels
│   ├── wave.rb          # Programmable wave
│   └── noise.rb         # Noise generator
├── memory/              # Memory subsystem
│   ├── mmu.rb           # Memory management
│   └── dma.rb           # DMA controller
└── cartridge/           # Cartridge mappers
    ├── mbc1.rb
    ├── mbc3.rb
    └── mbc5.rb

Next Steps