# drhelius/gearboy architecture

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

- Interactive diagram: https://gitdiagram.com/drhelius/gearboy
- Repository: https://github.com/drhelius/gearboy

## Overview

Gearboy is a cross-platform Game Boy, Game Boy Color, and Super Game Boy emulator. The main workflow is loading a ROM through a desktop, iOS, or libretro frontend, running it in the shared emulation core, and presenting video/audio while accepting input. The graph also preserves documented debugger/MCP, link-cable, save-state, rewind, run-ahead, shader, and barcode capabilities. Relationships are limited to indexed references, shown calls, or README statements; some feature links are dashed where implementation wiring was not sampled.

Main entry points: [`src/GearboyCore.cpp`](https://github.com/drhelius/gearboy/blob/master/src/GearboyCore.cpp) (Emulator core), [`platforms/shared/desktop/emu.cpp`](https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/emu.cpp) (Desktop emulator host), [`platforms/shared/desktop/application.cpp`](https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/application.cpp) (Desktop application), [`platforms/ios/Gearboy/RomListViewController.swift`](https://github.com/drhelius/gearboy/blob/master/platforms/ios/Gearboy/RomListViewController.swift) (iOS ROM library)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontends["User frontends"]
  node_desktop_entry["Desktop entry<br/>[main.cpp]"]
  node_desktop_app["Desktop application<br/>[application.cpp]"]
  node_ios_library["iOS ROM library"]
  node_ios_gameplay["iOS gameplay"]
  node_ios_settings["iOS settings"]
  node_ios_store[("iOS ROM store<br/>[DataStore.swift]")]
  node_ios_rom["ROM metadata<br/>[Rom.swift]"]
  node_ios_display_controls["Screen and controls"]
  node_ios_bridge["iOS emulator bridge<br/>[GearboyEmulator.h]"]
  node_libretro["Libretro core<br/>[libretro.cpp]"]
  node_libretro_api["Libretro API<br/>[libretro.h]"]
end

subgraph group_core["Emulation core"]
  node_core["Emulator core<br/>[GearboyCore.cpp]"]
  node_cartridge["Cartridge handling<br/>[Cartridge.cpp]"]
  node_memory["Memory and mappers<br/>[Memory.cpp]"]
  node_processor["CPU execution<br/>[Processor.cpp]"]
  node_video["Video rendering<br/>[Video.cpp]"]
  node_audio["Audio synthesis<br/>[Audio.cpp]"]
end

subgraph group_desktop["Desktop runtime"]
  node_desktop_emu["Desktop emulator host<br/>[emu.cpp]"]
  node_desktop_config[("Desktop configuration<br/>[config.cpp]")]
  node_desktop_gui["Desktop interface<br/>[gui.cpp]"]
end

subgraph group_features["Emulator features"]
  node_link["Link cable"]
  node_save_rewind["Save and rewind<br/>[rewind.cpp]"]
  node_runahead["Run-ahead<br/>[runahead.cpp]"]
  node_shader["Shader chain"]
  node_barcode["Barcode Boy<br/>[BarcodeBoy.cpp]"]
end

subgraph group_debug["Debug interfaces"]
  node_profiler["Profiler<br/>[Profiler.cpp]"]
  node_trace["Trace logger<br/>[TraceLogger.cpp]"]
  node_debugger["Desktop debugger UI<br/>[gui_debug.cpp]"]
  node_mcp["MCP server<br/>[mcp_manager.h]"]
end

node_user(("Player"))
node_mcp_client(("AI debugging client"))
node_libretro_frontend(("Libretro frontend"))

node_user -->|"launches"| node_desktop_entry
node_desktop_entry -->|"starts"| node_desktop_app
node_desktop_app -->|"updates"| node_desktop_emu
node_desktop_app -->|"uses"| node_desktop_config
node_desktop_app -->|"initializes"| node_desktop_gui
node_desktop_emu -->|"hosts"| node_core
node_desktop_gui -.->|"presents controls"| node_user
node_user -->|"chooses ROM"| node_ios_library
node_ios_library -->|"refreshes"| node_ios_store
node_ios_library -->|"lists"| node_ios_rom
node_ios_library -->|"opens gameplay"| node_ios_gameplay
node_user -->|"configures"| node_ios_settings
node_ios_gameplay -->|"uses views"| node_ios_display_controls
node_ios_gameplay -.->|"drives"| node_ios_bridge
node_ios_bridge -.->|"runs emulation"| node_core
node_libretro_frontend -->|"calls core API"| node_libretro
node_libretro -->|"implements API"| node_libretro_api
node_libretro -->|"uses shared core"| node_core
node_core -->|"loads cartridges"| node_cartridge
node_core -->|"configures memory"| node_memory
node_core -->|"runs CPU"| node_processor
node_core -->|"produces frames"| node_video
node_core -->|"produces audio"| node_audio
node_core -->|"profiles execution"| node_profiler
node_core -->|"logs execution"| node_trace
node_desktop_emu -->|"supports connection"| node_link
node_desktop_emu -.->|"supports states"| node_save_rewind
node_desktop_emu -.->|"supports prediction"| node_runahead
node_desktop_app -.->|"supports shaders"| node_shader
node_core -.->|"supports barcode input"| node_barcode
node_desktop_gui -.->|"exposes debugger"| node_debugger
node_debugger -.->|"inspects execution"| node_core
node_mcp_client -.->|"sends debug requests"| node_mcp
node_mcp -->|"controls emulator"| node_desktop_emu

click node_desktop_entry "https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/main.cpp"
click node_desktop_app "https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/application.cpp"
click node_ios_library "https://github.com/drhelius/gearboy/blob/master/platforms/ios/Gearboy/RomListViewController.swift"
click node_ios_gameplay "https://github.com/drhelius/gearboy/blob/master/platforms/ios/Gearboy/EmulationViewController.swift"
click node_ios_settings "https://github.com/drhelius/gearboy/blob/master/platforms/ios/Gearboy/SettingsViewController.swift"
click node_ios_store "https://github.com/drhelius/gearboy/blob/master/platforms/ios/Gearboy/DataStore.swift"
click node_ios_rom "https://github.com/drhelius/gearboy/blob/master/platforms/ios/Gearboy/Rom.swift"
click node_ios_display_controls "https://github.com/drhelius/gearboy/blob/master/platforms/ios/Gearboy/GameControlsView.swift"
click node_ios_bridge "https://github.com/drhelius/gearboy/blob/master/platforms/ios/Gearboy/GearboyEmulator.h"
click node_libretro "https://github.com/drhelius/gearboy/blob/master/platforms/libretro/libretro.cpp"
click node_libretro_api "https://github.com/drhelius/gearboy/blob/master/platforms/libretro/libretro.h"
click node_core "https://github.com/drhelius/gearboy/blob/master/src/GearboyCore.cpp"
click node_cartridge "https://github.com/drhelius/gearboy/blob/master/src/Cartridge.cpp"
click node_memory "https://github.com/drhelius/gearboy/blob/master/src/Memory.cpp"
click node_processor "https://github.com/drhelius/gearboy/blob/master/src/Processor.cpp"
click node_video "https://github.com/drhelius/gearboy/blob/master/src/Video.cpp"
click node_audio "https://github.com/drhelius/gearboy/blob/master/src/Audio.cpp"
click node_desktop_emu "https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/emu.cpp"
click node_desktop_config "https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/config.cpp"
click node_desktop_gui "https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/gui.cpp"
click node_link "https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/link_cable/link_cable_manager.cpp"
click node_save_rewind "https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/rewind.cpp"
click node_runahead "https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/runahead.cpp"
click node_shader "https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/ogl_shader_chain.cpp"
click node_barcode "https://github.com/drhelius/gearboy/blob/master/src/BarcodeBoy.cpp"
click node_profiler "https://github.com/drhelius/gearboy/blob/master/src/Profiler.cpp"
click node_trace "https://github.com/drhelius/gearboy/blob/master/src/TraceLogger.cpp"
click node_debugger "https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/gui_debug.cpp"
click node_mcp "https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/mcp/mcp_manager.h"

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_desktop_entry,node_desktop_app,node_ios_library,node_ios_gameplay,node_ios_settings,node_ios_store,node_ios_rom,node_ios_display_controls,node_ios_bridge,node_libretro,node_libretro_api,node_mcp_client,node_libretro_frontend toneBlue
class node_core,node_cartridge,node_memory,node_processor,node_video,node_audio toneAmber
class node_desktop_emu,node_desktop_config,node_desktop_gui toneMint
class node_link,node_save_rewind,node_runahead,node_shader,node_barcode toneRose
class node_profiler,node_trace,node_debugger,node_mcp,node_user toneIndigo
```

## Components

### User frontends

- [Desktop entry](https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/main.cpp): `platforms/shared/desktop/main.cpp`
- [Desktop application](https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/application.cpp): `platforms/shared/desktop/application.cpp`
- [iOS ROM library](https://github.com/drhelius/gearboy/blob/master/platforms/ios/Gearboy/RomListViewController.swift): `platforms/ios/Gearboy/RomListViewController.swift`
- [iOS gameplay](https://github.com/drhelius/gearboy/blob/master/platforms/ios/Gearboy/EmulationViewController.swift): `platforms/ios/Gearboy/EmulationViewController.swift`
- [iOS settings](https://github.com/drhelius/gearboy/blob/master/platforms/ios/Gearboy/SettingsViewController.swift): `platforms/ios/Gearboy/SettingsViewController.swift`
- [iOS ROM store](https://github.com/drhelius/gearboy/blob/master/platforms/ios/Gearboy/DataStore.swift): `platforms/ios/Gearboy/DataStore.swift`
- [ROM metadata](https://github.com/drhelius/gearboy/blob/master/platforms/ios/Gearboy/Rom.swift): `platforms/ios/Gearboy/Rom.swift`
- [Screen and controls](https://github.com/drhelius/gearboy/blob/master/platforms/ios/Gearboy/GameControlsView.swift): `platforms/ios/Gearboy/GameControlsView.swift`
- [iOS emulator bridge](https://github.com/drhelius/gearboy/blob/master/platforms/ios/Gearboy/GearboyEmulator.h): `platforms/ios/Gearboy/GearboyEmulator.h`
- [Libretro core](https://github.com/drhelius/gearboy/blob/master/platforms/libretro/libretro.cpp): `platforms/libretro/libretro.cpp`
- [Libretro API](https://github.com/drhelius/gearboy/blob/master/platforms/libretro/libretro.h): `platforms/libretro/libretro.h`

### Emulation core

- [Emulator core](https://github.com/drhelius/gearboy/blob/master/src/GearboyCore.cpp): `src/GearboyCore.cpp`
- [Cartridge handling](https://github.com/drhelius/gearboy/blob/master/src/Cartridge.cpp): `src/Cartridge.cpp`
- [Memory and mappers](https://github.com/drhelius/gearboy/blob/master/src/Memory.cpp): `src/Memory.cpp`
- [CPU execution](https://github.com/drhelius/gearboy/blob/master/src/Processor.cpp): `src/Processor.cpp`
- [Video rendering](https://github.com/drhelius/gearboy/blob/master/src/Video.cpp): `src/Video.cpp`
- [Audio synthesis](https://github.com/drhelius/gearboy/blob/master/src/Audio.cpp): `src/Audio.cpp`

### Desktop runtime

- [Desktop emulator host](https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/emu.cpp): `platforms/shared/desktop/emu.cpp`
- [Desktop configuration](https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/config.cpp): `platforms/shared/desktop/config.cpp`
- [Desktop interface](https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/gui.cpp): `platforms/shared/desktop/gui.cpp`

### Emulator features

- [Link cable](https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/link_cable/link_cable_manager.cpp): `platforms/shared/desktop/link_cable/link_cable_manager.cpp`
- [Save and rewind](https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/rewind.cpp): `platforms/shared/desktop/rewind.cpp`
- [Run-ahead](https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/runahead.cpp): `platforms/shared/desktop/runahead.cpp`
- [Shader chain](https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/ogl_shader_chain.cpp): `platforms/shared/desktop/ogl_shader_chain.cpp`
- [Barcode Boy](https://github.com/drhelius/gearboy/blob/master/src/BarcodeBoy.cpp): `src/BarcodeBoy.cpp`

### Debug interfaces

- [Profiler](https://github.com/drhelius/gearboy/blob/master/src/Profiler.cpp): `src/Profiler.cpp`
- [Trace logger](https://github.com/drhelius/gearboy/blob/master/src/TraceLogger.cpp): `src/TraceLogger.cpp`
- [Desktop debugger UI](https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/gui_debug.cpp): `platforms/shared/desktop/gui_debug.cpp`
- [MCP server](https://github.com/drhelius/gearboy/blob/master/platforms/shared/desktop/mcp/mcp_manager.h): `platforms/shared/desktop/mcp/mcp_manager.h`

### Other components

- **Player**
- **AI debugging client**
- **Libretro frontend**

## Connections

- Player → Desktop entry: launches (evidence: `README.md`)
- Desktop entry → Desktop application: starts (evidence: `platforms/shared/desktop/main.cpp`)
- Desktop application → Desktop emulator host: updates (evidence: `platforms/shared/desktop/application.cpp`)
- Desktop application → Desktop configuration: uses (evidence: `platforms/shared/desktop/application.cpp`)
- Desktop application → Desktop interface: initializes (evidence: `platforms/shared/desktop/application.cpp`)
- Desktop emulator host → Emulator core: hosts
- Desktop interface → Player: presents controls
- Player → iOS ROM library: chooses ROM (evidence: `platforms/ios/Gearboy/RomListViewController.swift`)
- iOS ROM library → iOS ROM store: refreshes (evidence: `platforms/ios/Gearboy/RomListViewController.swift`)
- iOS ROM library → ROM metadata: lists (evidence: `platforms/ios/Gearboy/RomListViewController.swift`)
- iOS ROM library → iOS gameplay: opens gameplay (evidence: `platforms/ios/Gearboy/RomListViewController.swift`)
- Player → iOS settings: configures (evidence: `platforms/ios/Gearboy/SettingsViewController.swift`)
- iOS gameplay → Screen and controls: uses views (evidence: `platforms/ios/Gearboy/EmulationViewController.swift`)
- iOS gameplay → iOS emulator bridge: drives
- iOS emulator bridge → Emulator core: runs emulation
- Libretro frontend → Libretro core: calls core API
- Libretro core → Libretro API: implements API (evidence: `platforms/libretro/libretro.cpp`)
- Libretro core → Emulator core: uses shared core (evidence: `platforms/libretro/libretro.cpp`)
- Emulator core → Cartridge handling: loads cartridges (evidence: `src/GearboyCore.cpp`)
- Emulator core → Memory and mappers: configures memory (evidence: `src/GearboyCore.cpp`)
- Emulator core → CPU execution: runs CPU (evidence: `src/GearboyCore.cpp`)
- Emulator core → Video rendering: produces frames (evidence: `src/GearboyCore.cpp`)
- Emulator core → Audio synthesis: produces audio (evidence: `src/GearboyCore.cpp`)
- Emulator core → Profiler: profiles execution
- Emulator core → Trace logger: logs execution
- Desktop emulator host → Link cable: supports connection
- Desktop emulator host → Save and rewind: supports states
- Desktop emulator host → Run-ahead: supports prediction
- Desktop application → Shader chain: supports shaders (evidence: `README.md`)
- Emulator core → Barcode Boy: supports barcode input (evidence: `README.md`)
- Desktop interface → Desktop debugger UI: exposes debugger (evidence: `README.md`)
- Desktop debugger UI → Emulator core: inspects execution (evidence: `README.md`)
- AI debugging client → MCP server: sends debug requests (evidence: `README.md`)
- MCP server → Desktop emulator host: controls emulator (evidence: `platforms/shared/desktop/mcp/mcp_manager.h`)
