# donno2048/snake architecture

> Architecture diagram of the GitHub repository donno2048/snake, 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/donno2048/snake
- Repository: https://github.com/donno2048/snake

## Overview

##### Main Components

a) Input Layer:
- DOS Keyboard Interface
- Mobile Touch Input (for web demo)

b) Core Game Engine:
- Assembly Code Execution Environment
- Game State Manager
- Collision Detection System
- Snake Movement Logic

c) System:
- DOS Video Memory Interface
- Screen Buffer Management

d) Web Demo Infrastructure:
- js-dos Emulation Layer
- WebAssembly Module (wdosbox.wasm)
- JavaScript Bridge

##### Native DOS Environment
- Hardware interfaces
- Memory management
- Interrupt handlers

##### Game Core
- In the center
- Data flow between components
- Minimal 57-byte implementation

##### Web Demo Layer
- At the top
- Emulation stack
- Browser interface

Use these specific visual elements:

Important Implementation Details to Highlight:

##### Direct Hardware Access
- Connection to video memory
- Keyboard interrupt handling
- Memory-mapped I/O

##### Emulation Bridge
- WebAssembly compilation path
- JavaScript event handling

Use these specific symbols:
- ⚡ for interrupts
- 🔄 for game loops
- 💾 for memory operations
- 🎮 for input handling

- Assembly-level operations
- DOS interface points
- Web emulation stack
- Memory management approach

Remember to include version information:
- Native DOS version
- Web demo compatibility
- DOSBox emulation requirements

This approach will give other engineers a clear understanding of how this minimal implementation achieves its functionality while maintaining its incredibly small footprint.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef hardware fill:#gray,stroke:#333
    classDef core fill:#98FB98,stroke:#333
    classDef web fill:#FFE4B5,stroke:#333
    classDef dos fill:#B0C4DE,stroke:#333
    classDef input fill:#FFA07A,stroke:#333
    classDef display fill:#87CEEB,stroke:#333

    subgraph Web
        WEB["Web Browser Interface"]:::web
        JSDOS["js-dos Emulation Layer"]:::web
        WASM["WebAssembly Module"]:::web
        JSBRIDGE["JavaScript Bridge"]:::web
        HTML["Web Demo Interface"]:::web
    end

    subgraph GameCore
        ASM["Assembly Implementation"]:::core
        GSM["Game State Manager"]:::core
        CDS["Collision Detection"]:::core
        SML["Snake Movement Logic"]:::core
        BIN["Compiled Binary"]:::core
    end

    subgraph DOSLayer
        DOSENV["DOS Environment"]:::dos
        DOSMEM["Memory Management"]:::dos
        DOSINT["Interrupt Handlers"]:::dos
    end

    subgraph InputSystem
        KBD["DOS Keyboard Interface"]:::input
        ARROW["Arrow Key Handler"]:::input
        TOUCH["Mobile Touch Input"]:::input
    end

    subgraph DisplaySystem
        VIDMEM["Video Memory Interface"]:::display
        SCREEN["Screen Buffer"]:::display
    end

    %% Connections
    WEB --> JSDOS
    JSDOS --> WASM
    WASM --> JSBRIDGE
    JSBRIDGE --> BIN
    HTML --> JSBRIDGE

    ASM --> GSM
    ASM --> CDS
    ASM --> SML
    GSM --> BIN
    CDS --> BIN
    SML --> BIN

    BIN --> DOSENV
    DOSENV --> DOSMEM
    DOSENV --> DOSINT

    KBD --> ARROW
    TOUCH --> JSBRIDGE
    ARROW --> GSM

    GSM --> VIDMEM
    VIDMEM --> SCREEN

    %% Click Events
    click ASM "https://github.com/donno2048/snake/blob/master/snake.asm"
    click BIN "https://github.com/donno2048/snake/blob/master/demo/snake.com"
    click JSDOS "https://github.com/donno2048/snake/blob/master/demo/js-dos.js"
    click WASM "https://github.com/donno2048/snake/blob/master/demo/wdosbox.wasm.js"
    click JSBRIDGE "https://github.com/donno2048/snake/blob/master/demo/main.js"
    click HTML "https://github.com/donno2048/snake/blob/master/demo/index.html"

    %% Legend
    subgraph Legend
        L1["Hardware Interface"]:::hardware
        L2["Core Game Component"]:::core
        L3["Web Layer"]:::web
        L4["DOS Component"]:::dos
        L5["Input Component"]:::input
        L6["Display Component"]:::display
    end
```
