# linkfy/gb_emu_1 architecture

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

- Interactive diagram: https://gitdiagram.com/linkfy/gb_emu_1
- Repository: https://github.com/linkfy/gb_emu_1

## Overview

This repository is a Rust Game Boy emulator: a user supplies a ROM and runs it through CPU execution, memory-mapped hardware, video rendering, and audio output, with joypad input during emulation. The CPU instruction module is a useful internal layer beneath the CPU dispatcher. A separate browser script tracks opcode-table progress; the supplied excerpts do not establish how its page is wired. The map reflects shown calls and documented behavior; unsampled implementation details and links are omitted where evidence is limited.

Main entry points: [`src/main.rs`](https://github.com/linkfy/gb_emu_1/blob/main/src/main.rs) (Emulation loop), [`src/memory.rs`](https://github.com/linkfy/gb_emu_1/blob/main/src/memory.rs) (Memory and controllers), [`src/cpu/mod.rs`](https://github.com/linkfy/gb_emu_1/blob/main/src/cpu/mod.rs) (CPU), [`src/cpu/instructions.rs`](https://github.com/linkfy/gb_emu_1/blob/main/src/cpu/instructions.rs) (Instruction operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Emulator runtime"]
  node_runner["Emulation loop<br/>[main.rs]"]
  node_rom["ROM loader<br/>[rom.rs]"]
  node_cpu["CPU<br/>[mod.rs]"]
  node_instructions["Instruction operations<br/>[instructions.rs]"]
end

subgraph group_hardware["Emulated hardware"]
  node_memory["Memory and controllers<br/>[memory.rs]"]
  node_input["Joypad state<br/>[input.rs]"]
  node_ppu["Video processor<br/>[ppu.rs]"]
  node_apu["Audio processor<br/>[apu.rs]"]
end

subgraph group_interface["User interface"]
  node_display["Window and display<br/>[main.rs]"]
  node_audio["Audio output stream<br/>[main.rs]"]
end

subgraph group_viewer["Opcode progress viewer"]
  node_progress["Opcode progress<br/>[progress.js]"]
end

node_user(("Player"))
node_browser_store[("Browser local storage")]

node_user -->|"starts emulator"| node_runner
node_runner -->|"loads ROM"| node_rom
node_runner -->|"steps CPU"| node_cpu
node_runner -->|"advances cycles"| node_ppu
node_runner -->|"advances cycles"| node_apu
node_runner -->|"reads buttons"| node_input
node_runner -->|"updates joypad"| node_memory
node_cpu -->|"dispatches opcodes"| node_instructions
node_cpu -->|"fetches data"| node_memory
node_instructions -->|"reads and writes"| node_memory
node_ppu -->|"reads display state"| node_memory
node_apu -->|"reads audio registers"| node_memory
node_runner -->|"presents frames"| node_display
node_runner -->|"starts stream"| node_audio
node_progress -->|"saves progress"| node_browser_store

click node_runner "https://github.com/linkfy/gb_emu_1/blob/main/src/main.rs"
click node_rom "https://github.com/linkfy/gb_emu_1/blob/main/src/rom.rs"
click node_cpu "https://github.com/linkfy/gb_emu_1/blob/main/src/cpu/mod.rs"
click node_instructions "https://github.com/linkfy/gb_emu_1/blob/main/src/cpu/instructions.rs"
click node_memory "https://github.com/linkfy/gb_emu_1/blob/main/src/memory.rs"
click node_input "https://github.com/linkfy/gb_emu_1/blob/main/src/input.rs"
click node_ppu "https://github.com/linkfy/gb_emu_1/blob/main/src/ppu.rs"
click node_apu "https://github.com/linkfy/gb_emu_1/blob/main/src/apu.rs"
click node_display "https://github.com/linkfy/gb_emu_1/blob/main/src/main.rs"
click node_audio "https://github.com/linkfy/gb_emu_1/blob/main/src/main.rs"
click node_progress "https://github.com/linkfy/gb_emu_1/blob/main/html_viewer/progress.js"

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_runner,node_rom,node_cpu,node_instructions toneBlue
class node_memory,node_input,node_ppu,node_apu,node_browser_store toneAmber
class node_display,node_audio toneMint
class node_progress toneRose
class node_user toneIndigo
```

## Components

### Emulator runtime

- [Emulation loop](https://github.com/linkfy/gb_emu_1/blob/main/src/main.rs): `src/main.rs`
- [ROM loader](https://github.com/linkfy/gb_emu_1/blob/main/src/rom.rs): `src/rom.rs`
- [CPU](https://github.com/linkfy/gb_emu_1/blob/main/src/cpu/mod.rs): `src/cpu/mod.rs`
- [Instruction operations](https://github.com/linkfy/gb_emu_1/blob/main/src/cpu/instructions.rs): `src/cpu/instructions.rs`

### Emulated hardware

- [Memory and controllers](https://github.com/linkfy/gb_emu_1/blob/main/src/memory.rs): `src/memory.rs`
- [Joypad state](https://github.com/linkfy/gb_emu_1/blob/main/src/input.rs): `src/input.rs`
- [Video processor](https://github.com/linkfy/gb_emu_1/blob/main/src/ppu.rs): `src/ppu.rs`
- [Audio processor](https://github.com/linkfy/gb_emu_1/blob/main/src/apu.rs): `src/apu.rs`

### User interface

- [Window and display](https://github.com/linkfy/gb_emu_1/blob/main/src/main.rs): `src/main.rs`
- [Audio output stream](https://github.com/linkfy/gb_emu_1/blob/main/src/main.rs): `src/main.rs`

### Opcode progress viewer

- [Opcode progress](https://github.com/linkfy/gb_emu_1/blob/main/html_viewer/progress.js): `html_viewer/progress.js`

### Other components

- **Player**
- **Browser local storage**

## Connections

- Player → Emulation loop: starts emulator (evidence: `src/main.rs`)
- Emulation loop → ROM loader: loads ROM (evidence: `src/main.rs`)
- Emulation loop → CPU: steps CPU (evidence: `src/main.rs`)
- Emulation loop → Video processor: advances cycles (evidence: `src/main.rs`)
- Emulation loop → Audio processor: advances cycles (evidence: `src/main.rs`)
- Emulation loop → Joypad state: reads buttons (evidence: `src/main.rs`)
- Emulation loop → Memory and controllers: updates joypad (evidence: `src/main.rs`)
- CPU → Instruction operations: dispatches opcodes (evidence: `src/cpu/mod.rs`)
- CPU → Memory and controllers: fetches data (evidence: `src/cpu/mod.rs`)
- Instruction operations → Memory and controllers: reads and writes (evidence: `src/cpu/instructions.rs`)
- Video processor → Memory and controllers: reads display state (evidence: `src/ppu.rs`)
- Audio processor → Memory and controllers: reads audio registers (evidence: `src/apu.rs`)
- Emulation loop → Window and display: presents frames (evidence: `src/main.rs`)
- Emulation loop → Audio output stream: starts stream (evidence: `src/main.rs`)
- Opcode progress → Browser local storage: saves progress (evidence: `html_viewer/progress.js`)
