# desmodroid/nes-emulator architecture

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

- Interactive diagram: https://gitdiagram.com/desmodroid/nes-emulator
- Repository: https://github.com/desmodroid/nes-emulator

## Overview

This is a work-in-progress NES emulator whose implemented workflow loads an iNES ROM, connects its cartridge to a simple memory bus, and repeatedly steps a 6502 CPU. The CPU supports implemented official instructions and addressing modes; the bus currently provides mirrored RAM and cartridge reads, while PPU/APU routing and interrupts are not implemented. The graph separates CPU dispatch, addressing, and instruction behavior. Relationships are based on the shown excerpts and README; unsampled behavior is omitted.

Main entry points: [`src/bus.cpp`](https://github.com/desmodroid/nes-emulator/blob/main/src/bus.cpp) (Memory bus), [`main.cpp`](https://github.com/desmodroid/nes-emulator/blob/main/main.cpp) (Emulator runner), [`src/cpu.cpp`](https://github.com/desmodroid/nes-emulator/blob/main/src/cpu.cpp) (CPU dispatch), [`src/cpu_addressing_modes.cpp`](https://github.com/desmodroid/nes-emulator/blob/main/src/cpu_addressing_modes.cpp) (Addressing modes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Emulator runtime"]
  node_runner["Emulator runner<br/>[main.cpp]"]
end

subgraph group_cpu["6502 CPU"]
  node_cpu_core["CPU dispatch<br/>[cpu.cpp]"]
  node_addressing["Addressing modes"]
  node_instructions["Instruction behavior"]
end

subgraph group_media["ROM and memory"]
  node_bus["Memory bus<br/>[bus.cpp]"]
  node_cartridge["Cartridge parser<br/>[cartridge.cpp]"]
  node_ram[("Mirrored RAM<br/>[bus.hpp]")]
end

node_user(("ROM user"))
node_rom["NES ROM file"]

node_user -->|"starts with ROM"| node_runner
node_runner -->|"reads bytes"| node_rom
node_runner -->|"constructs cartridge"| node_cartridge
node_runner -->|"connects cartridge"| node_bus
node_runner -->|"resets and steps"| node_cpu_core
node_cpu_core -->|"dispatches mode"| node_addressing
node_cpu_core -->|"executes instruction"| node_instructions
node_cpu_core -->|"fetches opcode"| node_bus
node_addressing -->|"reads operands"| node_bus
node_instructions -->|"reads and writes"| node_bus
node_bus -->|"reads and writes"| node_ram
node_bus -->|"routes cartridge reads"| node_cartridge

click node_runner "https://github.com/desmodroid/nes-emulator/blob/main/main.cpp"
click node_cpu_core "https://github.com/desmodroid/nes-emulator/blob/main/src/cpu.cpp"
click node_addressing "https://github.com/desmodroid/nes-emulator/blob/main/src/cpu_addressing_modes.cpp"
click node_instructions "https://github.com/desmodroid/nes-emulator/blob/main/src/cpu_instructions.cpp"
click node_bus "https://github.com/desmodroid/nes-emulator/blob/main/src/bus.cpp"
click node_cartridge "https://github.com/desmodroid/nes-emulator/blob/main/src/cartridge.cpp"
click node_ram "https://github.com/desmodroid/nes-emulator/blob/main/include/bus.hpp"

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_user toneBlue
class node_cpu_core,node_addressing,node_instructions toneAmber
class node_bus,node_cartridge,node_ram toneMint
class node_rom toneIndigo
```

## Components

### Emulator runtime

- [Emulator runner](https://github.com/desmodroid/nes-emulator/blob/main/main.cpp): `main.cpp`

### 6502 CPU

- [CPU dispatch](https://github.com/desmodroid/nes-emulator/blob/main/src/cpu.cpp): `src/cpu.cpp`
- [Addressing modes](https://github.com/desmodroid/nes-emulator/blob/main/src/cpu_addressing_modes.cpp): `src/cpu_addressing_modes.cpp`
- [Instruction behavior](https://github.com/desmodroid/nes-emulator/blob/main/src/cpu_instructions.cpp): `src/cpu_instructions.cpp`

### ROM and memory

- [Memory bus](https://github.com/desmodroid/nes-emulator/blob/main/src/bus.cpp): `src/bus.cpp`
- [Cartridge parser](https://github.com/desmodroid/nes-emulator/blob/main/src/cartridge.cpp): `src/cartridge.cpp`
- [Mirrored RAM](https://github.com/desmodroid/nes-emulator/blob/main/include/bus.hpp): `include/bus.hpp`

### Other components

- **ROM user**
- **NES ROM file**

## Connections

- ROM user → Emulator runner: starts with ROM (evidence: `README.md`)
- Emulator runner → NES ROM file: reads bytes (evidence: `main.cpp`)
- Emulator runner → Cartridge parser: constructs cartridge (evidence: `main.cpp`)
- Emulator runner → Memory bus: connects cartridge (evidence: `main.cpp`)
- Emulator runner → CPU dispatch: resets and steps (evidence: `main.cpp`)
- CPU dispatch → Addressing modes: dispatches mode (evidence: `src/cpu.cpp`)
- CPU dispatch → Instruction behavior: executes instruction (evidence: `src/cpu.cpp`)
- CPU dispatch → Memory bus: fetches opcode (evidence: `src/cpu.cpp`)
- Addressing modes → Memory bus: reads operands (evidence: `src/cpu_addressing_modes.cpp`)
- Instruction behavior → Memory bus: reads and writes (evidence: `src/cpu_instructions.cpp`)
- Memory bus → Mirrored RAM: reads and writes (evidence: `src/bus.cpp`)
- Memory bus → Cartridge parser: routes cartridge reads (evidence: `src/bus.cpp`)
