# carlosdaniel26/intel-8080 architecture

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

- Interactive diagram: https://gitdiagram.com/carlosdaniel26/intel-8080
- Repository: https://github.com/carlosdaniel26/intel-8080

## Overview

##### Project type and purpose
- This is a native C application implementing an Intel 8080 CPU emulator.
- It uses SDL2 for graphical output of the emulated video buffer.
- It loads binary “ROM” files, executes instructions, and renders the result in a window.

##### File structure
- Top-level:
– src/ – core emulator code (cpu.c, memory/ROM loader, screen renderer, debug hooks).
– include/ – public headers for each module.
– rom/ – test binaries and game ROMs to be loaded.
– Makefile & gdb_script.gdb – build and debug automation.
- Patterns:
– Modular C design: CPU, memory/ROM, screen, debug, helper utilities.
– Single-process, single-binary architecture.

##### README for additional insights
- Emulation pipeline: fetch → decode → execute cycles in cpu.c.
- SDL2 handles rendering of a memory‐mapped video buffer.
- Supports loading arbitrary Intel 8080 binaries (e.g., Space Invaders).

##### Main components
a. CPU Core
– Instruction fetch/decode/execute loop.
– Registers, flags, program counter.
b. Memory & ROM Loader
– RAM array + mapped ROM regions.
– Loader module reading .COM/.BIN files into memory.
c. Screen Renderer
– Video memory buffer in C.
– SDL2 window & rendering pipeline.
d. Debug Module
– Logging, state dumps, breakpoints (gdb_script integration).
e. Main/Orchestration
– Entry point (main.c), module initialization, emulation loop, event handling.
f. Utilities (helper.c)
– Timing, I/O abstractions, argument parsing.

##### Relationships & data flow
- Main → initializes CPU, Memory, Screen, Debug
- CPU ← fetches instructions from Memory → writes results back
- CPU & Helper → invoke Debug hooks/loggers
- Screen module reads a designated memory region each frame → hands pixel data to SDL2
- Event loop in Main captures user/OS events → passes them to CPU or quits
- ROM Loader writes binary data into Memory at startup

##### Architectural patterns & design principles
- Separation of concerns: CPU logic vs. memory management vs. rendering
- Single-threaded, event-driven loop
- Modular C interfaces via headers (include/)
- External dependency (SDL2) abstracted behind a minimal screen module

##### Relevant technologies & libraries
- Pure C (GCC, Makefile)
- SDL2 for graphics & window management
- gdb scripting for debug automation

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Main entry point
    Main["Main/Orchestration"]:::core
    %% Core modules
    CPU["CPU Core\n(fetch-decode-execute)"]:::core
    Memory["Memory & ROM Loader"]:::core
    Screen["Screen Renderer"]:::core
    Debug["Debug Module"]:::core
    Helper["Utilities (Helper)"]:::core
    %% External components
    ROM["External ROM Files"]:::external
    SDL2["SDL2 Library"]:::external
    %% Build/debug tools
    Makefile["Makefile"]:::tools
    GDB["gdb_script.gdb"]:::tools

    %% Relationships
    Main -->|"initialize modules"| CPU
    Main -->|"initialize modules"| Memory
    Main -->|"initialize modules"| Screen
    Main -->|"initialize modules"| Debug
    Main -->|"initialize modules"| Helper

    Main -->|"load ROM"| ROM
    ROM -->|"binary data"| Memory

    Main -->|"start event loop"| CPU
    Main -->|"start event loop"| Screen

    CPU -->|"fetch instruction"| Memory
    Memory -->|"instruction data"| CPU
    CPU -->|"write result"| Memory

    Memory -->|"video RAM data"| Screen
    Screen -->|"render frame"| SDL2

    CPU -->|"invoke hooks"| Debug
    Helper -->|"logging/timing"| Debug

    %% Build and debug tools connections
    Main -->|"build using"| Makefile
    Main -->|"debug script"| GDB

    %% Click events
    click Main "https://github.com/carlosdaniel26/intel-8080/blob/main/src/main.c"
    click CPU "https://github.com/carlosdaniel26/intel-8080/blob/main/src/cpu.c"
    click Memory "https://github.com/carlosdaniel26/intel-8080/blob/main/src/rom.c"
    click Screen "https://github.com/carlosdaniel26/intel-8080/blob/main/src/screen.c"
    click Debug "https://github.com/carlosdaniel26/intel-8080/blob/main/src/debug.c"
    click Helper "https://github.com/carlosdaniel26/intel-8080/blob/main/src/helper.c"
    click ROM "https://github.com/carlosdaniel26/intel-8080/tree/main/rom/"
    click Makefile "https://github.com/carlosdaniel26/intel-8080/tree/main/Makefile"
    click GDB "https://github.com/carlosdaniel26/intel-8080/blob/main/gdb_script.gdb"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef external fill:#90EE90,stroke:#333,stroke-width:1px
    classDef tools fill:#FFFACD,stroke:#333,stroke-width:1px
```
