# ratsock6/retromu architecture

> Architecture diagram of the GitHub repository ratsock6/retromu, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ratsock6/retromu
- Repository: https://github.com/ratsock6/retromu

## Overview

RetroEmu emulates DMG and CGB handhelds, with a command-line runner and SDL frontend. The principal workflow is selecting a ROM, loading its cartridge metadata and controller, assembling the machine, executing CPU instructions through the memory bus, and presenting PPU frames while accepting input. Separate user-facing modes provide cartridge inspection, headless execution, screenshots, tracing, disassembly, and interactive debugging. The graph reflects documented capabilities and indexed references; unsampled implementation details are not inferred.

Main entry points: [`src/main.cpp`](https://github.com/ratsock6/retromu/blob/main/src/main.cpp) (Command entry), [`src/core/bus.cpp`](https://github.com/ratsock6/retromu/blob/main/src/core/bus.cpp) (Memory bus), [`src/core/gameboy.cpp`](https://github.com/ratsock6/retromu/blob/main/src/core/gameboy.cpp) (Machine facade), [`src/front/frontend.cpp`](https://github.com/ratsock6/retromu/blob/main/src/front/frontend.cpp) (SDL frontend)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry and tools"]
  node_cli["Command entry<br/>[main.cpp]"]
end

subgraph group_hardware["Emulated hardware"]
  node_cartridge["Cartridge loader<br/>[cartridge.cpp]"]
  node_mbc["Bank controllers<br/>[mbc.cpp]"]
  node_gameboy["Machine facade<br/>[gameboy.cpp]"]
  node_cpu["SM83 CPU<br/>[cpu.cpp]"]
  node_bus["Memory bus<br/>[bus.cpp]"]
  node_timer["Timer<br/>[timer.cpp]"]
  node_dma["DMA<br/>[dma.cpp]"]
  node_joypad["Console joypad<br/>[joypad.cpp]"]
end

subgraph group_graphics["Display and input"]
  node_ppu["PPU renderer<br/>[ppu.cpp]"]
  node_frontend["SDL frontend<br/>[frontend.cpp]"]
  node_ui["GUI widgets<br/>[ui.cpp]"]
end

subgraph group_inspection["Debug and validation"]
  node_disassembler["Disassembler<br/>[disassembler.cpp]"]
  node_debugger["Interactive debugger<br/>[debugger.cpp]"]
  node_tracer["Execution tracer<br/>[tracer.cpp]"]
  node_selftest["CPU self-test<br/>[cpu_selftest.cpp]"]
end

node_user(("User"))

node_user -->|"selects mode"| node_cli
node_cli -->|"loads ROM"| node_cartridge
node_cartridge -->|"creates controller"| node_mbc
node_gameboy -->|"loads cartridge"| node_cartridge
node_cli -->|"runs machine"| node_gameboy
node_gameboy -->|"steps CPU"| node_cpu
node_cpu -->|"accesses memory"| node_bus
node_bus -->|"dispatches access"| node_cartridge
node_bus -->|"dispatches access"| node_ppu
node_bus -->|"ticks and routes"| node_timer
node_bus -->|"dispatches DMA"| node_dma
node_bus -->|"dispatches access"| node_joypad
node_frontend -->|"runs frames"| node_gameboy
node_frontend -->|"updates buttons"| node_joypad
node_frontend -->|"draws interface"| node_ui
node_ui -->|"presents controls"| node_user
node_cli -->|"opens window"| node_frontend
node_cli -->|"starts debugger"| node_debugger
node_debugger -->|"decodes instruction"| node_disassembler
node_cli -->|"runs trace"| node_tracer
node_tracer -->|"traces machine"| node_gameboy
node_cli -->|"runs CPU checks"| node_selftest
node_selftest -->|"checks execution"| node_cpu

click node_cli "https://github.com/ratsock6/retromu/blob/main/src/main.cpp"
click node_cartridge "https://github.com/ratsock6/retromu/blob/main/src/core/cartridge.cpp"
click node_mbc "https://github.com/ratsock6/retromu/blob/main/src/core/mbc.cpp"
click node_gameboy "https://github.com/ratsock6/retromu/blob/main/src/core/gameboy.cpp"
click node_cpu "https://github.com/ratsock6/retromu/blob/main/src/core/cpu.cpp"
click node_bus "https://github.com/ratsock6/retromu/blob/main/src/core/bus.cpp"
click node_timer "https://github.com/ratsock6/retromu/blob/main/src/core/timer.cpp"
click node_dma "https://github.com/ratsock6/retromu/blob/main/src/core/dma.cpp"
click node_joypad "https://github.com/ratsock6/retromu/blob/main/src/core/joypad.cpp"
click node_ppu "https://github.com/ratsock6/retromu/blob/main/src/core/ppu.cpp"
click node_frontend "https://github.com/ratsock6/retromu/blob/main/src/front/frontend.cpp"
click node_ui "https://github.com/ratsock6/retromu/blob/main/src/front/ui.cpp"
click node_disassembler "https://github.com/ratsock6/retromu/blob/main/src/debug/disassembler.cpp"
click node_debugger "https://github.com/ratsock6/retromu/blob/main/src/debug/debugger.cpp"
click node_tracer "https://github.com/ratsock6/retromu/blob/main/src/debug/tracer.cpp"
click node_selftest "https://github.com/ratsock6/retromu/blob/main/src/debug/cpu_selftest.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_user toneBlue
class node_cartridge,node_mbc,node_gameboy,node_cpu,node_bus,node_timer,node_dma,node_joypad toneAmber
class node_ppu,node_frontend,node_ui toneMint
class node_disassembler,node_debugger,node_tracer,node_selftest toneRose
```

## Components

### Entry and tools

- [Command entry](https://github.com/ratsock6/retromu/blob/main/src/main.cpp): `src/main.cpp`

### Emulated hardware

- [Cartridge loader](https://github.com/ratsock6/retromu/blob/main/src/core/cartridge.cpp): `src/core/cartridge.cpp`
- [Bank controllers](https://github.com/ratsock6/retromu/blob/main/src/core/mbc.cpp): `src/core/mbc.cpp`
- [Machine facade](https://github.com/ratsock6/retromu/blob/main/src/core/gameboy.cpp): `src/core/gameboy.cpp`
- [SM83 CPU](https://github.com/ratsock6/retromu/blob/main/src/core/cpu.cpp): `src/core/cpu.cpp`
- [Memory bus](https://github.com/ratsock6/retromu/blob/main/src/core/bus.cpp): `src/core/bus.cpp`
- [Timer](https://github.com/ratsock6/retromu/blob/main/src/core/timer.cpp): `src/core/timer.cpp`
- [DMA](https://github.com/ratsock6/retromu/blob/main/src/core/dma.cpp): `src/core/dma.cpp`
- [Console joypad](https://github.com/ratsock6/retromu/blob/main/src/core/joypad.cpp): `src/core/joypad.cpp`

### Display and input

- [PPU renderer](https://github.com/ratsock6/retromu/blob/main/src/core/ppu.cpp): `src/core/ppu.cpp`
- [SDL frontend](https://github.com/ratsock6/retromu/blob/main/src/front/frontend.cpp): `src/front/frontend.cpp`
- [GUI widgets](https://github.com/ratsock6/retromu/blob/main/src/front/ui.cpp): `src/front/ui.cpp`

### Debug and validation

- [Disassembler](https://github.com/ratsock6/retromu/blob/main/src/debug/disassembler.cpp): `src/debug/disassembler.cpp`
- [Interactive debugger](https://github.com/ratsock6/retromu/blob/main/src/debug/debugger.cpp): `src/debug/debugger.cpp`
- [Execution tracer](https://github.com/ratsock6/retromu/blob/main/src/debug/tracer.cpp): `src/debug/tracer.cpp`
- [CPU self-test](https://github.com/ratsock6/retromu/blob/main/src/debug/cpu_selftest.cpp): `src/debug/cpu_selftest.cpp`

### Other components

- **User**

## Connections

- User → Command entry: selects mode (evidence: `README.md`)
- Command entry → Cartridge loader: loads ROM (evidence: `src/main.cpp`)
- Cartridge loader → Bank controllers: creates controller (evidence: `src/core/mbc.cpp`)
- Machine facade → Cartridge loader: loads cartridge (evidence: `src/core/gameboy.cpp`)
- Command entry → Machine facade: runs machine (evidence: `README.md`)
- Machine facade → SM83 CPU: steps CPU
- SM83 CPU → Memory bus: accesses memory
- Memory bus → Cartridge loader: dispatches access
- Memory bus → PPU renderer: dispatches access
- Memory bus → Timer: ticks and routes (evidence: `src/core/timer.cpp`)
- Memory bus → DMA: dispatches DMA (evidence: `src/core/dma.cpp`)
- Memory bus → Console joypad: dispatches access
- SDL frontend → Machine facade: runs frames
- SDL frontend → Console joypad: updates buttons (evidence: `src/front/frontend.cpp`)
- SDL frontend → GUI widgets: draws interface (evidence: `src/front/frontend.cpp`)
- GUI widgets → User: presents controls (evidence: `README.md`)
- Command entry → SDL frontend: opens window (evidence: `README.md`)
- Command entry → Interactive debugger: starts debugger (evidence: `README.md`)
- Interactive debugger → Disassembler: decodes instruction (evidence: `src/debug/debugger.cpp`)
- Command entry → Execution tracer: runs trace (evidence: `README.md`)
- Execution tracer → Machine facade: traces machine
- Command entry → CPU self-test: runs CPU checks (evidence: `README.md`)
- CPU self-test → SM83 CPU: checks execution (evidence: `src/debug/cpu_selftest.cpp`)
