# kroc/v80 architecture

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

- Interactive diagram: https://gitdiagram.com/kroc/v80
- Repository: https://github.com/kroc/v80

## Overview

##### Main Components

a) Input Processing Layer:
- Source File Reader (handles .v80, .v65 files)
- Lexical Analyzer (handles sigils, keywords, and tokens)
- Expression Parser (handles arithmetic and logical operations)

b) Core Assembly Components:
- ISA (Instruction Set Architecture) Plugins
- Symbol Table Manager (for constants and labels)
- Program Counter Manager
- Conditional Assembly Handler

c) Output Generation:
- Binary Output Generator
- Symbol File Generator (stdout)
- Error Handling System

**┌─────────────────────────────────────────┐**
- Source Files               │
- (.v80, .v65, includes, etc.)        │
- ┬───────────────────────┘
- ▼
**┌─────────────────────────────────────────┐**
- Input Processing Layer          │
- ┤
- Lexical Analysis                      │
- Expression Parsing                    │
- Include File Resolution               │
- ┬───────────────────────┘
- ▼
**┌─────────────────────────────────────────┐**
- Assembly Core                   │
- ┤
- ┌─────────────┐      ┌──────────────┐  │
- Symbol Table │◄────►│Program Counter│  │
- ┘      └──────────────┘  │
- ┌─────────────┐      ┌──────────────┐  │
- ISA Plugins  │◄────►│Cond. Assembly│  │
- ┘      └──────────────┘  │
- ┬───────────────────────┘
- ▼
**┌─────────────────────────────────────────┐**
- Output Generation               │
- ┤
- Binary Output                         │
- Symbol File                           │
- Error Messages                        │
- ┘

##### Key Relationships to Highlight

- Two-pass assembly process
- Forward reference handling
- File processing
- Symbol table management
- Error reporting flow

##### Implementation Details

- Size constraints (< 8KB for CP/M binary)
- File format support (.v80, .v65)
- Expression evaluation flow
- Demonstrate conditional assembly process

##### Additional Notes

- Simplicity of design (no macros, no linker)
- Platform independence
- Extensibility through ISA plugins
- Self-hosting capability

This design should capture both the current implementation and future expansion possibilities while maintaining clarity about the core assembly process.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        SF["Source Files<br/>(.v80, .v65)"]:::input
        IF["Include Files"]:::input
    end

    subgraph "Input Processing"
        LA["Lexical Analyzer"]:::processor
        EP["Expression Parser"]:::processor
        click EP "https://github.com/kroc/v80/blob/main/v1/v80_expr.v80"
    end

    subgraph "Assembly Core"
        AC["Core Assembler"]:::core
        click AC "https://github.com/kroc/v80/blob/main/v1/v80_asm.v80"
        
        subgraph "Symbol Management"
            ST["Symbol Table"]:::data
            PC["Program Counter"]:::data
        end
        
        subgraph "ISA System"
            ISA["ISA Plugins"]:::isa
            click ISA "https://github.com/kroc/v80/blob/main/v1/isa_z80.v80"
            Z80["Z80 ISA"]:::isa
            click Z80 "https://github.com/kroc/v80/blob/main/v1/isa_z80.v80"
            M6502["6502 ISA"]:::isa
            click M6502 "https://github.com/kroc/v80/blob/main/v1/isa_6502.v80"
            FE["Future ISAs<br/>(6809, SM83)"]:::planned
        end
        
        CA["Conditional<br/>Assembly"]:::processor
    end

    subgraph "Platform Layer"
        CPM["CP/M Interface"]:::platform
        click CPM "https://github.com/kroc/v80/blob/main/v1/v80_cpm.v80"
        PE["PC Emulation<br/>(NTVCM/RunCPM)"]:::platform
    end

    subgraph "Output Generation"
        BO["Binary Output"]:::output
        SF2["Symbol File"]:::output
        EH["Error Handler"]:::error
        click EH "https://github.com/kroc/v80/blob/main/v1/v80_err.v80"
    end

    SF --> LA
    IF --> LA
    LA --> EP
    EP --> AC
    AC --> ST
    AC --> PC
    AC --> ISA
    ISA --> Z80
    ISA --> M6502
    ISA --> FE
    AC --> CA
    ST --> CA
    CA --> BO
    AC --> BO
    AC --> SF2
    AC --> EH
    BO --> CPM
    CPM --> PE

    classDef input fill:#a8d1ff,stroke:#333,stroke-width:2px
    classDef processor fill:#90EE90,stroke:#333,stroke-width:2px
    classDef core fill:#98FB98,stroke:#333,stroke-width:2px
    classDef data fill:#FFE4B5,stroke:#333,stroke-width:2px
    classDef isa fill:#FFD700,stroke:#333,stroke-width:2px
    classDef platform fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef output fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef error fill:#FF6B6B,stroke:#333,stroke-width:2px
    classDef planned fill:#E6E6FA,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5

    subgraph Legend
        L1["Input Files"]:::input
        L2["Processors"]:::processor
        L3["Core Assembly"]:::core
        L4["Data Storage"]:::data
        L5["ISA Components"]:::isa
        L6["Platform Layer"]:::platform
        L7["Output Components"]:::output
        L8["Error Handling"]:::error
        L9["Planned Features"]:::planned
    end
```
