# f-biondi/nth-boy architecture

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

- Interactive diagram: https://gitdiagram.com/f-biondi/nth-boy
- Repository: https://github.com/f-biondi/nth-boy

## Overview

##### Main Components

a) Core Emulation Layer (gbcore):
- CPU Module
- Memory Management Unit (MMU)
- Picture Processing Unit (PPU)
- Memory Bank Controllers (MBC)
- I/O Controllers

b) Platform-Specific Implementations:
- Desktop Application (nth-boy-desktop)
- WebAssembly Interface (nth-boy-wasm)

##### Detailed Component Breakdown

CPU Module:
- Registers subsystem
- Instruction execution flow

Memory Management Unit (MMU):
- Different address spaces:
- Cartridge (ROM/RAM)
- I/O Registers
- OAM (Object Attribute Memory)
- Memory bank controllers (MBC1, MBC2, MBC3, MBC5)

PPU (Graphics):
- Pixel fetcher subsystem
- Pixel FIFO components
- Background and sprite fetcher paths

I/O Components:
- LCD Controller
- Joypad Input
- Timer System

**[Platform Layer]**
- ↑↓
**[Core Emulation Layer]**
- ↑↓
**[Hardware Emulation Components]**

##### Key Relationships to Highlight

- MMU's central role in connecting components
- PPU's pixel pipeline flow
- Memory bank controller interaction with cartridge data
- Platform interface with core emulation layer

##### Implementation Details

For each major component, include:
- Input/output interfaces
- Key state management
- Communication protocols between components

**[Desktop UI] ←→ [WASM/Web UI]**
- ↓             ↓
- [Platform Interfaces]
- ↓
- [Core Emulator]
- ↙     ↓     ↘
**[CPU] ← [MMU] → [PPU]**
- ↘     ↑     ↗
- [I/O System]

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Style Definitions
    classDef core fill:#b3d1ff,stroke:#4d88ff
    classDef io fill:#90EE90,stroke:#228B22
    classDef memory fill:#FFB366,stroke:#FF8000
    classDef platform fill:#DDA0DD,stroke:#9370DB
    classDef ppu fill:#FFD700,stroke:#DAA520

    %% Platform Layer
    subgraph Platform
        Desktop["Desktop Application"]:::platform
        Web["Web Frontend"]:::platform
        WASM["WebAssembly Interface"]:::platform
    end

    %% Core Emulation Layer
    subgraph CoreEmulation
        CPU["CPU Module"]:::core
        Registers["Registers Subsystem"]:::core
        MMU["Memory Management Unit"]:::memory
    end

    %% Hardware Components
    subgraph PPU
        PixelFetcher["Pixel Fetcher"]:::ppu
        PixelFIFO["Pixel FIFO"]:::ppu
        BGFetcher["Background Fetcher"]:::ppu
        SpriteFetcher["Sprite Fetcher"]:::ppu
    end

    subgraph Memory
        AddressSpaces["Address Spaces"]:::memory
        MBC["Memory Bank Controllers"]:::memory
        Cart["Cartridge ROM/RAM"]:::memory
        OAM["Object Attribute Memory"]:::memory
    end

    subgraph IO
        LCD["LCD Controller"]:::io
        Joypad["Joypad Input"]:::io
        Timer["Timer System"]:::io
    end

    %% Relationships
    Desktop --> WASM
    Web --> WASM
    WASM --> CPU
    CPU --> Registers
    CPU <--> MMU
    MMU <--> Memory
    MMU <--> IO
    MMU <--> PPU
    PixelFetcher --> PixelFIFO
    BGFetcher --> PixelFetcher
    SpriteFetcher --> PixelFetcher

    %% Click Events
    click CPU "https://github.com/f-biondi/nth-boy/tree/main/gbcore/src/cpu/"
    click Registers "https://github.com/f-biondi/nth-boy/blob/main/gbcore/src/cpu/registers.rs"
    click MMU "https://github.com/f-biondi/nth-boy/tree/main/gbcore/src/mmu/"
    click AddressSpaces "https://github.com/f-biondi/nth-boy/tree/main/gbcore/src/mmu/address_spaces/"
    click MBC "https://github.com/f-biondi/nth-boy/blob/main/gbcore/src/mmu/address_spaces/cart/mbc.rs"
    click Cart "https://github.com/f-biondi/nth-boy/tree/main/gbcore/src/mmu/address_spaces/cart/"
    click OAM "https://github.com/f-biondi/nth-boy/blob/main/gbcore/src/mmu/address_spaces/oam.rs"
    click PixelFetcher "https://github.com/f-biondi/nth-boy/tree/main/gbcore/src/ppu/pixel_fetcher/"
    click BGFetcher "https://github.com/f-biondi/nth-boy/blob/main/gbcore/src/ppu/pixel_fetcher/bg_fetcher.rs"
    click SpriteFetcher "https://github.com/f-biondi/nth-boy/blob/main/gbcore/src/ppu/pixel_fetcher/sprite_fetcher.rs"
    click PixelFIFO "https://github.com/f-biondi/nth-boy/tree/main/gbcore/src/ppu/pixel_fetcher/pixel_fifo/"
    click LCD "https://github.com/f-biondi/nth-boy/blob/main/gbcore/src/mmu/address_spaces/io/lcd.rs"
    click Joypad "https://github.com/f-biondi/nth-boy/blob/main/gbcore/src/mmu/address_spaces/io/joypad.rs"
    click Timer "https://github.com/f-biondi/nth-boy/blob/main/gbcore/src/mmu/address_spaces/io/timers.rs"
    click Desktop "https://github.com/f-biondi/nth-boy/tree/main/nth-boy-desktop/"
    click WASM "https://github.com/f-biondi/nth-boy/tree/main/nth-boy-wasm/"
    click Web "https://github.com/f-biondi/nth-boy/tree/main/nth-boy-wasm/www/"

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["I/O Components"]:::io
        L3["Memory Components"]:::memory
        L4["Platform Components"]:::platform
        L5["PPU Components"]:::ppu
    end
```
