# awesomedolphin/megaagi architecture

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

- Interactive diagram: https://gitdiagram.com/awesomedolphin/megaagi
- Repository: https://github.com/awesomedolphin/megaagi

## Overview

##### Main Components
- Core Engine: Represented by files such as engine.c and main.c, which coordinate the initialization, command processing (changing picture, view, sound), and overall control flow.
- Graphics Subsystem: Files like gfx.h, pic.c, sprite.c, and view.c indicate components dealing with rendering pictures and sprites, as well as managing different views.
- Sound Subsystem: Files such as sound.c and volume.c manage audio playback and volume control.
- Interrupt and Memory Management: With files like irq.h, irq.s, interrupt.c, memmanage.c, and pic.c – these are essential for handling low-level operations and resource management.
- File/Asset Handling: The simplefile.h and simplefile.s files, along with support for loading external AGI game directories (PICDIR, SNDDIR, VIEWDIR, VOL.n), indicate a component responsible for reading game data from the media.
- NCM Mode: With ncm.c present, suggest that a back-buffer related mechanism is in place (even if not fully implemented) as part of the rendering process.
- Additional Support: Other files (logic.c, fcm.c) imply there’s some form of internal game logic control, even if only partially implemented.

- Begin at the entry point (main.c) which invokes the Core Engine.
- The Engine then dispatches commands to different subsystems. For instance:
- When a “pic n” command is received, the engine delegates to the Graphics subsystem via pic.c.
- For “view n”, the view.c module is called.
- For “sound n”, control passes to the Sound subsystem.
- The Core Engine manages interrupts and cooperates with low-level memory and file management routines.
- External asset files from the game (provided on the D81 disk image) are loaded into memory using the file/asset handling module.

##### Architectural Patterns and Design Principles
- Modular Design: Each subsystem is clearly separated at the file level (audio, graphics, memory, I/O), making it easier to see how components operate independently.
- Low-level Integration: The mix of C and assembly files (e.g., irq.s, simplefile.s) highlights the need for performance-sensitive operations, typical in systems programming.
- Command-driven Architecture: The system responds directly to text commands (e.g., “pic n”, “view n”, “sound n”), indicating a minimalist command interpreter design, even though the full parser is not implemented.
- Hardware Abstraction: Memory and interrupt management modules abstract the platform-specific or hardware-level operations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Engine and Subsystem Layers
    subgraph "Engine Layer"
        CE["Core Engine"]
    end

    subgraph "Subsystem Layer"
        GFX["Graphics Subsystem"]
        SND["Sound Subsystem"]
        IH["Interrupt Handling"]
        MEM["Memory Management"]
        FILE["File/Asset Handling"]
        NCM["NCM Mode"]
        LOG["Additional Logic"]
    end

    %% Core Engine interactions
    CE -->|"Graphics_Command"| GFX
    CE -->|"Sound_Command"| SND
    CE -->|"Interrupt_Control"| IH
    CE -->|"Memory_Control"| MEM
    CE -->|"Asset_Load_Request"| FILE
    CE -->|"Game_Logic_Update"| LOG
    CE -->|"Backbuffer_Support"| NCM

    %% Subsystem interactions
    FILE -->|"Load_Pictures"| GFX
    FILE -->|"Load_Sounds"| SND
    IH -->|"Memory_Access"| MEM

    %% Click Events
    click CE "https://github.com/awesomedolphin/megaagi/blob/main/src/main.c, src/engine.c"
    click GFX "https://github.com/awesomedolphin/megaagi/blob/main/src/pic.c, src/sprite.c, src/view.c, include/gfx.h"
    click SND "https://github.com/awesomedolphin/megaagi/blob/main/src/sound.c, src/volume.c, include/sound.h, include/volume.h"
    click IH "https://github.com/awesomedolphin/megaagi/blob/main/src/irq.s, src/interrupt.c, include/irq.h"
    click MEM "https://github.com/awesomedolphin/megaagi/blob/main/src/memmanage.c, include/memmanage.h"
    click FILE "https://github.com/awesomedolphin/megaagi/blob/main/src/simplefile.s, include/simplefile.h"
    click NCM "https://github.com/awesomedolphin/megaagi/blob/main/src/ncm.c"
    click LOG "https://github.com/awesomedolphin/megaagi/blob/main/src/logic.c, src/fcm.c"

    %% Styles
    classDef engine fill:#FFD700,stroke:#DAA520,stroke-width:2px;
    classDef subsystem fill:#90EE90,stroke:#32CD32,stroke-width:2px;
    classDef support fill:#ADD8E6,stroke:#1E90FF,stroke-width:2px;

    class CE engine;
    class GFX,SND subsystem;
    class IH,MEM,FILE,NCM,LOG support;
```
