# michalklabisz/pascal-wezyk architecture

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

- Interactive diagram: https://gitdiagram.com/michalklabisz/pascal-wezyk
- Repository: https://github.com/michalklabisz/pascal-wezyk

## Overview

##### Project type and purpose
- This is a standalone DOS-based Snake clone written in Turbo Pascal.
- It consists of Pascal source files, Turbo Pascal units, compiled executables, and game asset files (graphics, sound, data).

##### File structure
- Source code (.PAS):
- BEFORE.PAS, CREATE.PAS, FNT.PAS, GRA.PAS, M13H.PAS, PLIK.PAS, SOUND.PAS, STEROW.PAS, …
- Compiled unit:
- GVGA.TPU – Turbo Pascal graphics unit
- Executable:
- GRA.EXE
- Data files:
- PALMENU.DAT, Palgame.dat, TOP5.DAT – menu, game data, top-scores
- title.bmp – splash/title screen
- .wav files (begin.wav, brzdek.wav, dzwiek.wav, end.wav, gold.wav, mniam.wav) – sound effects
- Readme and docs:
- README.md, readme.txt

##### Main components
a. Game Core (main loop)
- Parses command-line or menu selection
- Initializes graphics (GVGA unit) and sound
- Loads configuration/data files
b. Input Handler
- Module STEROW.PAS handles keyboard/game controls
c. Game Logic
- Snake movement, collision detection, score tracking (modules GRA.PAS, CREATE.PAS, BEFORE.PAS)
d. Rendering Engine
- Graphics drawing routines (GRA.PAS, GVGA.TPU, FNT.PAS for fonts)
e. Sound Engine
- SOUND.PAS loads and plays wave files
f. Persistence/File I/O
- PLIK.PAS reads/writes .DAT files (PALMENU.DAT, Palgame.dat, TOP5.DAT)
g. Menu/System UI
- PALMENU.DAT + menu code for starting game, showing top scores
h. Assets
- External data (bitmaps, sounds, level/menu data)

##### Relationships and interactions
- The Game Core orchestrates the flow:
- Calls Input Handler each frame
- Passes input events to Game Logic
- Game Logic updates state (snake position, score)
- Calls Sound Engine when events occur (e.g. eat, game over)
- File I/O invoked on start/end (load menu, save scores)
- Data assets are loaded once at init or on-demand
- The GVGA.TPU unit underpins all low-level graphics calls

##### Architectural patterns and design principles
- Modular decomposition: separate .PAS files for graphics, logic, sound, I/O
- Single-threaded game loop pattern
- Layered approach:
- Hardware abstraction (GVGA)
- Engine layers (input, logic, render, sound)
- Data layer (asset files)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Pascal Runtime"
        GVGA["GVGA.TPU"]:::runtime
    end

    subgraph "Game Core"
        M13H["M13H.PAS"]:::code
    end

    subgraph "Input Handler"
        STEROW["STEROW.PAS"]:::code
    end

    subgraph "Game Logic"
        BEFORE["BEFORE.PAS"]:::code
        CREATE["CREATE.PAS"]:::code
        GRA_LOGIC["GRA.PAS"]:::code
    end

    subgraph "Rendering Engine"
        GRA_RENDER["GRA.PAS"]:::code
        FNT["FNT.PAS"]:::code
    end

    subgraph "Sound Engine"
        SOUND["SOUND.PAS"]:::code
    end

    subgraph "File I/O"
        PLIK["PLIK.PAS"]:::code
    end

    subgraph "Assets"
        BMP["title.bmp"]:::data
        DAT1["PALMENU.DAT"]:::data
        DAT2["Palgame.dat"]:::data
        DAT3["TOP5.DAT"]:::data
        WAV1["begin.wav"]:::data
        WAV2["brzdek.wav"]:::data
        WAV3["dzwiek.wav"]:::data
        WAV4["end.wav"]:::data
        WAV5["gold.wav"]:::data
        WAV6["mniam.wav"]:::data
    end

    Docs["README.md"]:::data
    Exe["GRA.EXE"]:::data

    %% Control & Data Flow
    M13H -->|calls| STEROW
    STEROW -->|events to| BEFORE
    BEFORE -->|updates| CREATE
    CREATE -->|logic to| GRA_LOGIC
    GRA_LOGIC -->|draw calls| GRA_RENDER
    GRA_RENDER -->|uses| GVGA
    M13H -->|load/save| PLIK
    PLIK --> DAT1
    PLIK --> DAT2
    PLIK --> DAT3
    DAT1 --> PLIK
    DAT2 --> PLIK
    DAT3 --> PLIK
    M13H -->|trigger| SOUND
    SOUND --> WAV1
    SOUND --> WAV2
    SOUND --> WAV3
    SOUND --> WAV4
    SOUND --> WAV5
    SOUND --> WAV6
    BMP --> GRA_RENDER
    M13H -->|builds| Exe
    Docs -.-> M13H

    %% Click Events
    click M13H "https://github.com/michalklabisz/pascal-wezyk/blob/master/M13H.PAS"
    click STEROW "https://github.com/michalklabisz/pascal-wezyk/blob/master/STEROW.PAS"
    click BEFORE "https://github.com/michalklabisz/pascal-wezyk/blob/master/BEFORE.PAS"
    click CREATE "https://github.com/michalklabisz/pascal-wezyk/blob/master/CREATE.PAS"
    click GRA_LOGIC "https://github.com/michalklabisz/pascal-wezyk/blob/master/GRA.PAS"
    click GRA_RENDER "https://github.com/michalklabisz/pascal-wezyk/blob/master/GRA.PAS"
    click FNT "https://github.com/michalklabisz/pascal-wezyk/blob/master/FNT.PAS"
    click GVGA "https://github.com/michalklabisz/pascal-wezyk/blob/master/GVGA.TPU"
    click SOUND "https://github.com/michalklabisz/pascal-wezyk/blob/master/SOUND.PAS"
    click WAV1 "https://github.com/michalklabisz/pascal-wezyk/blob/master/begin.wav"
    click WAV2 "https://github.com/michalklabisz/pascal-wezyk/blob/master/brzdek.wav"
    click WAV3 "https://github.com/michalklabisz/pascal-wezyk/blob/master/dzwiek.wav"
    click WAV4 "https://github.com/michalklabisz/pascal-wezyk/blob/master/end.wav"
    click WAV5 "https://github.com/michalklabisz/pascal-wezyk/blob/master/gold.wav"
    click WAV6 "https://github.com/michalklabisz/pascal-wezyk/blob/master/mniam.wav"
    click PLIK "https://github.com/michalklabisz/pascal-wezyk/blob/master/PLIK.PAS"
    click DAT1 "https://github.com/michalklabisz/pascal-wezyk/blob/master/PALMENU.DAT"
    click DAT2 "https://github.com/michalklabisz/pascal-wezyk/blob/master/Palgame.dat"
    click DAT3 "https://github.com/michalklabisz/pascal-wezyk/blob/master/TOP5.DAT"
    click Docs "https://github.com/michalklabisz/pascal-wezyk/blob/master/README.md"

    %% Styles
    classDef code fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef data fill:#d4edda,stroke:#333,stroke-width:1px
    classDef runtime fill:#fff3cd,stroke:#333,stroke-width:1px
```
