# oscarpitcho/gameboj architecture

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

- Interactive diagram: https://gitdiagram.com/oscarpitcho/gameboj
- Repository: https://github.com/oscarpitcho/gameboj

## Overview

##### Main Components

a. Core Emulator Components:
- CPU Emulation (src/ch/epfl/gameboj/component/cpu)
- Memory Management (src/ch/epfl/gameboj/component/memory)
- LCD Controller (src/ch/epfl/gameboj/component/lcd)
- Cartridge System (src/ch/epfl/gameboj/component/cartridge)
- Timer (src/ch/epfl/gameboj/component/Timer.java)
- Joypad (src/ch/epfl/gameboj/component/Joypad.java)

b. Supporting Systems:
- Bus System (src/ch/epfl/gameboj/Bus.java)
- Bit Operations (src/ch/epfl/gameboj/bits)
- GUI Interface (src/ch/epfl/gameboj/gui)

**┌─────────────────────┐**
- JavaFX GUI      │
- (Main.java)        │
- ┘

**┌─────────────────────────────────────────────┐**
- GameBoy.java                    │

- ┌─────────┐ ┌─────────┐ ┌──────────────┐  │
- CPU   │ │  Timer  │ │LCD Controller │  │
- ┘ └─────────┘ └──────────────┘  │

- ┌─────────┐ ┌─────────┐ ┌──────────────┐  │
- Joypad  │ │  MBC0/1 │ │BootRom Ctrl  │  │
- ┘ └─────────┘ └──────────────┘  │
- ┘

**┌─────────────────────────────────────────────┐**
- Bus                       │
- ┤
- RAM     │    ROM     │   Address Map    │
- ┘

##### Key Elements to Highlight

- Blue for core hardware emulation components (CPU, LCD, etc.)
- Green for memory components (RAM, ROM)
- Yellow for interface components (GUI, Joypad)
- Red for control components (Bus, AddressMap)

- Data flow between components through the bus
- Control flow from the GUI to emulated components
- Clock signal distribution to Clocked components

##### Important Relationships

- All components implement the Component interface
- Clocked components implement the Clocked interface
- The Bus connects all components together
- The CPU's interaction with other components through the bus
- Memory controllers' relationship with actual memory components
- Cartridge system's relationship with MBC implementations

##### Implementation Details

- The component-based architecture
- The bus-centered communication
- The clear separation between hardware emulation and user interface
- The memory management hierarchy
- The clock-driven nature of the system

- Nested components
- Clear labeling
- Export to high-resolution formats

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef gui fill:#FFE873,stroke:#333
    classDef core fill:#7CB9E8,stroke:#333
    classDef memory fill:#90EE90,stroke:#333
    classDef control fill:#FF6B6B,stroke:#333
    classDef interface fill:#E6E6FA,stroke:#333

    %% User Interface Layer
    subgraph UI
        GUI["JavaFX GUI"]:::gui
    end

    %% Core Emulator Layer
    subgraph Core
        GameBoy["GameBoy"]:::core
        
        subgraph Components
            CPU["CPU"]:::core
            ALU["ALU"]:::core
            Timer["Timer"]:::core
            LCD["LCD Controller"]:::core
            Joypad["Joypad"]:::core
            LCDImage["LCD Image"]:::core
        end
    end

    %% Memory and Bus Layer
    subgraph MemorySystem
        Bus["Bus System"]:::control
        AddressMap["Address Map"]:::control
        
        subgraph Memory
            RAM["RAM Controller"]:::memory
            BootROM["Boot ROM Controller"]:::memory
            CartSystem["Cartridge System"]:::memory
            MBC0["MBC0"]:::memory
            MBC1["MBC1"]:::memory
        end
        
        subgraph BitOps
            BitOperations["Bit Operations"]:::control
        end
    end

    %% Relationships
    GUI --> GameBoy
    GameBoy --> Bus
    Bus --> CPU
    Bus --> Timer
    Bus --> LCD
    Bus --> Joypad
    Bus --> RAM
    Bus --> BootROM
    Bus --> CartSystem
    CartSystem --> MBC0
    CartSystem --> MBC1
    CPU --> ALU
    LCD --> LCDImage
    Bus --> AddressMap

    %% Click Events
    click CPU "https://github.com/oscarpitcho/GameBoj/blob/master/src/ch/epfl/gameboj/component/cpu/Cpu.java"
    click LCD "https://github.com/oscarpitcho/GameBoj/blob/master/src/ch/epfl/gameboj/component/lcd/LcdController.java"
    click CartSystem "https://github.com/oscarpitcho/GameBoj/blob/master/src/ch/epfl/gameboj/component/cartridge/Cartridge.java"
    click Timer "https://github.com/oscarpitcho/GameBoj/blob/master/src/ch/epfl/gameboj/component/Timer.java"
    click Joypad "https://github.com/oscarpitcho/GameBoj/blob/master/src/ch/epfl/gameboj/component/Joypad.java"
    click Bus "https://github.com/oscarpitcho/GameBoj/blob/master/src/ch/epfl/gameboj/Bus.java"
    click BitOperations "https://github.com/oscarpitcho/GameBoj/tree/master/src/ch/epfl/gameboj/bits/"
    click GUI "https://github.com/oscarpitcho/GameBoj/tree/master/src/ch/epfl/gameboj/gui/"
    click GameBoy "https://github.com/oscarpitcho/GameBoj/blob/master/src/ch/epfl/gameboj/GameBoy.java"
    click AddressMap "https://github.com/oscarpitcho/GameBoj/blob/master/src/ch/epfl/gameboj/AddressMap.java"
    click BootROM "https://github.com/oscarpitcho/GameBoj/blob/master/src/ch/epfl/gameboj/component/memory/BootRomController.java"
    click RAM "https://github.com/oscarpitcho/GameBoj/blob/master/src/ch/epfl/gameboj/component/memory/RamController.java"
    click MBC0 "https://github.com/oscarpitcho/GameBoj/blob/master/src/ch/epfl/gameboj/component/cartridge/MBC0.java"
    click MBC1 "https://github.com/oscarpitcho/GameBoj/blob/master/src/ch/epfl/gameboj/component/cartridge/MBC1.java"
    click ALU "https://github.com/oscarpitcho/GameBoj/blob/master/src/ch/epfl/gameboj/component/cpu/Alu.java"
    click LCDImage "https://github.com/oscarpitcho/GameBoj/blob/master/src/ch/epfl/gameboj/component/lcd/LcdImage.java"

    %% Legend
    subgraph Legend
        L1["GUI Components"]:::gui
        L2["Core Components"]:::core
        L3["Memory Components"]:::memory
        L4["Control Components"]:::control
    end
```
