# 2555jaa/gameboy-emulator architecture

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

- Interactive diagram: https://gitdiagram.com/2555jaa/gameboy-emulator
- Repository: https://github.com/2555jaa/gameboy-emulator

## Overview

This repository is a single-file Windows Game Boy (DMG) emulator. Its intended workflow is to start the program with an optional ROM path, load the ROM, initialize hardware, and load saved state; emulation then uses CPU, memory, graphics, and timer logic to produce a display. The source excerpt confirms startup calls and several internal interactions, but omits the main loop, input handling, rendering presentation, and save-state implementation, so those connections are not asserted.

Main entry points: [`gb.c`](https://github.com/2555jaa/gameboy-emulator/blob/main/gb.c) (Program startup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_startup["Startup and ROM"]
  node_startup["Program startup<br/>[gb.c]"]
  node_rom_loader["ROM loader<br/>[gb.c]"]
  node_hardware_init["Hardware initialization<br/>[gb.c]"]
  node_save_state["Save-state handling<br/>[gb.c]"]
end

subgraph group_core["Emulation core"]
  node_cpu["CPU execution<br/>[gb.c]"]
  node_memory["Memory bus and mapper<br/>[gb.c]"]
  node_ppu["PPU rendering<br/>[gb.c]"]
  node_timer["Timer<br/>[gb.c]"]
end

subgraph group_interface["Windows interface"]
  node_win_interface["Windows display and input<br/>[gb.c]"]
end

node_user(("Player"))
node_rom_file["Game ROM"]

node_user -->|"launches"| node_startup
node_startup -->|"loads ROM"| node_rom_loader
node_rom_file -->|"reads bytes"| node_rom_loader
node_startup -->|"initializes"| node_hardware_init
node_startup -->|"loads state"| node_save_state
node_cpu -->|"reads and writes"| node_memory
node_memory -.->|"provides video memory"| node_ppu
node_timer -.->|"updates registers"| node_memory
node_ppu -.->|"presents frames"| node_win_interface
node_user -.->|"provides input"| node_win_interface

click node_startup "https://github.com/2555jaa/gameboy-emulator/blob/main/gb.c"
click node_rom_loader "https://github.com/2555jaa/gameboy-emulator/blob/main/gb.c"
click node_hardware_init "https://github.com/2555jaa/gameboy-emulator/blob/main/gb.c"
click node_save_state "https://github.com/2555jaa/gameboy-emulator/blob/main/gb.c"
click node_cpu "https://github.com/2555jaa/gameboy-emulator/blob/main/gb.c"
click node_memory "https://github.com/2555jaa/gameboy-emulator/blob/main/gb.c"
click node_ppu "https://github.com/2555jaa/gameboy-emulator/blob/main/gb.c"
click node_timer "https://github.com/2555jaa/gameboy-emulator/blob/main/gb.c"
click node_win_interface "https://github.com/2555jaa/gameboy-emulator/blob/main/gb.c"

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_startup,node_rom_loader,node_hardware_init,node_save_state toneBlue
class node_cpu,node_memory,node_ppu,node_timer toneAmber
class node_win_interface toneMint
class node_user,node_rom_file toneIndigo
```

## Components

### Startup and ROM

- [Program startup](https://github.com/2555jaa/gameboy-emulator/blob/main/gb.c): `gb.c`
- [ROM loader](https://github.com/2555jaa/gameboy-emulator/blob/main/gb.c): `gb.c`
- [Hardware initialization](https://github.com/2555jaa/gameboy-emulator/blob/main/gb.c): `gb.c`
- [Save-state handling](https://github.com/2555jaa/gameboy-emulator/blob/main/gb.c): `gb.c`

### Emulation core

- [CPU execution](https://github.com/2555jaa/gameboy-emulator/blob/main/gb.c): `gb.c`
- [Memory bus and mapper](https://github.com/2555jaa/gameboy-emulator/blob/main/gb.c): `gb.c`
- [PPU rendering](https://github.com/2555jaa/gameboy-emulator/blob/main/gb.c): `gb.c`
- [Timer](https://github.com/2555jaa/gameboy-emulator/blob/main/gb.c): `gb.c`

### Windows interface

- [Windows display and input](https://github.com/2555jaa/gameboy-emulator/blob/main/gb.c): `gb.c`

### Other components

- **Player**
- **Game ROM**

## Connections

- Player → Program startup: launches (evidence: `gb.c`)
- Program startup → ROM loader: loads ROM (evidence: `gb.c`)
- Game ROM → ROM loader: reads bytes (evidence: `gb.c`)
- Program startup → Hardware initialization: initializes (evidence: `gb.c`)
- Program startup → Save-state handling: loads state (evidence: `gb.c`)
- CPU execution → Memory bus and mapper: reads and writes (evidence: `gb.c`)
- Memory bus and mapper → PPU rendering: provides video memory (evidence: `gb.c`)
- Timer → Memory bus and mapper: updates registers (evidence: `gb.c`)
- PPU rendering → Windows display and input: presents frames (evidence: `gb.c`)
- Player → Windows display and input: provides input
