# skx/cpmulator architecture

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

## Overview

##### Project Type and Core Purpose
This is a CP/M emulator written in Go, designed to run CP/M binaries by emulating the CP/M operating system environment. The system needs to represent both the emulated CP/M architecture and the modern implementation components.

##### Main Components

A. Core Emulation Layer:
- Z80 CPU Emulation (via external library)
- Memory Management System (memory/ package)
- CP/M System Components (cpm/ package)
- BDOS (Basic Disk Operating System)
- BIOS (Basic Input/Output System)

B. I/O Subsystem:
- Console Input Handler (consolein/ package)
- Console Output Handler (consoleout/ package)
- Multiple terminal emulation drivers (ADM-3A, ANSI)
- File System Interface (fcb/ package)

C. Command Processors:
- Default CCP (Console Command Processor)
- Enhanced CCPZ
- Built-in Commands Implementation

D. Runtime Environment:
- Drive Management System
- File System Abstraction
- Debug/Logging System

**┌─────────────────────────────────────────────────────┐**
- User Interface                      │
- (CCP/CCPZ Command Processor & Terminal Emulation)  │
- ┤
- CP/M Emulation Layer                  │
- ┬──────────────────┬──────────────────┤
- BDOS      │      BIOS        │  Memory Manager   │
- (cpm_bdos.go)│  (cpm_bios.go)   │  (memory/)       │
- ┴──────────────────┴──────────────────┤
- I/O Abstraction Layer                  │
- ┬──────────────────┬──────────────────┤
- Console In   │   Console Out    │   File System    │
- (consolein/) │  (consoleout/)   │    (fcb/)        │
- ┴──────────────────┴──────────────────┤
- Host System Interface                  │
- (File System, Terminal, Debug Logging)          │
- ┘

##### Important Elements to Highlight

- Blue: Core CP/M emulation components
- Green: I/O subsystems
- Yellow: User interface components
- Gray: Host system interfaces

- Command flow from CCP to BDOS/BIOS
- File system operations through FCB
- I/O operations through console handlers
- Memory access patterns

c. Special Features:
- Debug logging system
- Drive/Directory mapping
- Extension mechanisms
- Printer output redirection

##### Implementation Details to Note

- Memory map (0x0000 - 0xFE00)
- Locations of CCP, BDOS, and BIOS in memory
- Relationship between host directories and CP/M drives
- Syscall implementation status

##### External Interfaces

- Integration with host file system
- Console I/O handling
- Debug logging outputs
- Printer output redirection

Remember to highlight the extensibility points where the system can be configured or modified, such as the console drivers and CCP implementations.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph UI[User Interface Layer]
        CCP[Default CCP]
        CCPZ[Enhanced CCPZ]
        TERM[Terminal Emulation]
    end

    subgraph CPM[CP/M Emulation Layer]
        CORE[Core CP/M System]
        BDOS[BDOS]
        BIOS[BIOS]
        MEM[Memory Manager]
    end

    subgraph IO[I/O Abstraction Layer]
        direction TB
        CONIN[Console Input]
        CONOUT[Console Output]
        FCB[File System Interface]
        
        subgraph TD[Terminal Drivers]
            ADM["ADM-3A Driver"]
            ANSI["ANSI Driver"]
            LOG["Logger Driver"]
        end
    end

    subgraph HOST[Host System Interface]
        FS[File System]
        TERM_IO[Terminal I/O]
        DEBUG[Debug Logging]
        PRINT[Printer Output]
        DRIVE[Drive Management]
    end

    %% Relationships
    CCP --> CORE
    CCPZ --> CORE
    CORE --> BDOS
    CORE --> BIOS
    CORE --> MEM
    BIOS --> CONIN
    BIOS --> CONOUT
    BIOS --> FCB
    CONOUT --> TD
    FCB --> FS
    CONIN --> TERM_IO
    CONOUT --> TERM_IO
    LOG --> DEBUG
    BIOS --> PRINT
    FCB --> DRIVE

    %% Click Events
    click CCP "https://github.com/skx/cpmulator/blob/master/ccp/ccp.go"
    click CCPZ "https://github.com/skx/cpmulator/blob/master/ccp/CCPZ.BIN"
    click CORE "https://github.com/skx/cpmulator/blob/master/cpm/cpm.go"
    click BDOS "https://github.com/skx/cpmulator/blob/master/cpm/cpm_bdos.go"
    click BIOS "https://github.com/skx/cpmulator/blob/master/cpm/cpm_bios.go"
    click MEM "https://github.com/skx/cpmulator/blob/master/memory/memory.go"
    click CONIN "https://github.com/skx/cpmulator/blob/master/consolein/consolein.go"
    click CONOUT "https://github.com/skx/cpmulator/blob/master/consoleout/consoleout.go"
    click FCB "https://github.com/skx/cpmulator/blob/master/fcb/fcb.go"
    click ADM "https://github.com/skx/cpmulator/blob/master/consoleout/drv_adm3a.go"
    click ANSI "https://github.com/skx/cpmulator/blob/master/consoleout/drv_ansi.go"
    click LOG "https://github.com/skx/cpmulator/blob/master/consoleout/drv_logger.go"
    click PRINT "https://github.com/skx/cpmulator/blob/master/cpm/prnc.go"
    click DRIVE "https://github.com/skx/cpmulator/blob/master/static/static.go"

    %% Styling
    classDef ui fill:#FFE873,stroke:#333,stroke-width:2px
    classDef cpm fill:#AED6F1,stroke:#333,stroke-width:2px
    classDef io fill:#A9DFBF,stroke:#333,stroke-width:2px
    classDef host fill:#D5D8DC,stroke:#333,stroke-width:2px
    classDef driver fill:#F5B7B1,stroke:#333,stroke-width:2px

    class CCP,CCPZ,TERM ui
    class CORE,BDOS,BIOS,MEM cpm
    class CONIN,CONOUT,FCB io
    class FS,TERM_IO,DEBUG,PRINT,DRIVE host
    class ADM,ANSI,LOG driver
```
