# nokturnusmf/gameboy architecture

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

- Interactive diagram: https://gitdiagram.com/nokturnusmf/gameboy
- Repository: https://github.com/nokturnusmf/gameboy

## Overview

##### Main Components

a) Core Hardware Components:
- CPU (cpu.h)
- Memory Management Unit (memmap.h/cpp)
- Controller (display.h/cpp)
- Timer System (timer.h/cpp)
- Input Controller (input.h/cpp)
- Interrupt Controller (interrupts.h/cpp)
- Memory Bank Controller (bank.h/bank.impl)

b) External Interfaces:
- ROM Loading System (rom.h/cpp)
- GLFW Display Output (gb-glfw.cpp)
- Keyboard Input System

##### Component Relationships

a) Central Components:
- Interrupt Controller connected to both CPU and other components that can trigger interrupts

b) Data Flow:
- ROM data flow into Memory Management Unit
- Memory access path from Memory Management Unit to Display Controller
- Input Controller connection to Interrupt Controller
- Timer connection to Interrupt Controller

##### Specific Implementation Details

- Core Components (Rectangle): CPU, MMU, Display
- Support Systems (Rounded Rectangle): Timer, Input, Interrupts
- External Interfaces (Hexagon): ROM Loader, GLFW Display

**[GLFW Display Output] ←→ [Display Controller] ←→ [Memory Management Unit] ←→ [ROM Loader]**
- ↑↓
**[Keyboard Input] →→ [Input Controller] →→→→→→→→ [CPU] ←→ [Bank Controller]**
- ↓                       ↑
- [Interrupt Controller] ←←←← [Timer System]

##### Implementation Notes

- The cycle-accurate nature of the emulation
- Memory mapping and bank switching capabilities
- Interrupt handling paths
- Refresh and timing mechanisms
- Input handling and processing flow

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef core fill:#a8d1f0,stroke:#000
    classDef interface fill:#98FB98,stroke:#000
    classDef support fill:#FFB6C1,stroke:#000
    classDef memory fill:#DDA0DD,stroke:#000
    classDef external fill:#F0E68C,stroke:#000

    %% External Interfaces
    GLFW["GLFW Display Output"]:::external
    KBD["Keyboard Input"]:::external
    ROM["ROM Loading System"]:::external

    %% Core Components
    CPU["CPU"]:::core
    MMU["Memory Management Unit"]:::memory
    DISP["Display Controller"]:::core
    BANK["Memory Bank Controller"]:::memory

    %% Support Systems
    TIMER["Timer System"]:::support
    INPUT["Input Controller"]:::support
    INT["Interrupt Controller"]:::support

    %% Component Relationships
    GLFW <--> DISP
    DISP <--> MMU
    MMU <--> ROM
    MMU <--> CPU
    MMU <--> BANK
    KBD --> INPUT
    INPUT --> INT
    INT --> CPU
    TIMER --> INT
    CPU <--> BANK

    %% Click Events
    click CPU "https://github.com/nokturnusmf/Gameboy/blob/master/src/cpu.h"
    click MMU "https://github.com/nokturnusmf/Gameboy/blob/master/src/memmap.h"
    click DISP "https://github.com/nokturnusmf/Gameboy/blob/master/src/display.h"
    click TIMER "https://github.com/nokturnusmf/Gameboy/blob/master/src/timer.h"
    click INPUT "https://github.com/nokturnusmf/Gameboy/blob/master/src/input.h"
    click INT "https://github.com/nokturnusmf/Gameboy/blob/master/src/interrupts.h"
    click BANK "https://github.com/nokturnusmf/Gameboy/blob/master/src/bank.h"
    click ROM "https://github.com/nokturnusmf/Gameboy/blob/master/src/rom.h"
    click GLFW "https://github.com/nokturnusmf/Gameboy/blob/master/src/gb-glfw.cpp"

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Interface Components"]:::interface
        L3["Support Systems"]:::support
        L4["Memory Components"]:::memory
        L5["External Systems"]:::external
    end
```
