# samfarah/sap1-emulator architecture

> Architecture diagram of the GitHub repository samfarah/sap1-emulator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/samfarah/sap1-emulator
- Repository: https://github.com/samfarah/sap1-emulator

## Overview

SAP1-Emulator is a Windows Forms SAP-1 computer emulator: users can assemble or load machine code, run the simulated CPU automatically or step its clock, and inspect component state visually. The execution model includes instruction sequencing, bus transfers, arithmetic and flags, memory, and output. The README documents assembly and simulation capabilities, while sampled source confirms CPU construction and control-signal wiring; unsampled form logic prevents asserting the exact assembler-to-RAM and UI-to-CPU call paths.

Main entry points: [`SAP1Emulator/SAP1Emulator/SAP1_Modules/SAP1_8Bit.cs`](https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/SAP1_8Bit.cs) (SAP-1 computer), [`SAP1Emulator/SAP1Emulator/SumulationForm.cs`](https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SumulationForm.cs) (Simulation controls), [`SAP1Emulator/SAP1Emulator/Program.cs`](https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/Program.cs) (Application entry), [`SAP1Emulator/SAP1Emulator/SAP1_Modules/Assembler.cs`](https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/Assembler.cs) (Assembler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["User interface"]
  node_entry["Application entry<br/>[Program.cs]"]
  node_assembly_form["Assembly editor<br/>[AssemblyForm.cs]"]
  node_simulation_form["Simulation controls<br/>[SumulationForm.cs]"]
end

subgraph group_assembly["Assembly"]
  node_assembler["Assembler<br/>[Assembler.cs]"]
end

subgraph group_cpu["CPU execution"]
  node_computer["SAP-1 computer<br/>[SAP1_8Bit.cs]"]
  node_clock["Clock generator<br/>[ClockGenerator.cs]"]
  node_sequencer["Control sequencer"]
  node_bus["Shared bus<br/>[Bus.cs]"]
  node_registers["CPU registers<br/>[Register.cs]"]
  node_pc["Program counter<br/>[Counter.cs]"]
  node_alu["Arithmetic unit<br/>[ALU.cs]"]
  node_flags["Flags register<br/>[FlagsRegister.cs]"]
  node_ram[("RAM<br/>[SRAM.cs]")]
end

subgraph group_display["Visualization"]
  node_visual_controls["LEDs and arrows"]
  node_led_display["LED display<br/>[LEDDisplay.cs]"]
end

node_user(("User or caller"))

node_user -->|"launches"| node_entry
node_entry -->|"opens"| node_simulation_form
node_user -->|"edits or loads"| node_assembly_form
node_user -->|"creates and runs"| node_computer
node_computer -->|"constructs and connects"| node_bus
node_computer -->|"constructs"| node_registers
node_computer -->|"constructs"| node_alu
node_computer -->|"constructs with MAR"| node_ram
node_computer -->|"constructs"| node_pc
node_computer -->|"constructs"| node_flags
node_computer -->|"controls"| node_clock
node_computer -->|"applies control signals"| node_sequencer
node_computer -->|"state displayed by"| node_simulation_form
node_simulation_form -->|"updates"| node_visual_controls
node_simulation_form -->|"updates"| node_led_display
node_assembler -.->|"machine code used by"| node_computer

click node_entry "https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/Program.cs"
click node_assembly_form "https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/AssemblyForm.cs"
click node_assembler "https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/Assembler.cs"
click node_simulation_form "https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SumulationForm.cs"
click node_computer "https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/SAP1_8Bit.cs"
click node_clock "https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/ClockGenerator.cs"
click node_sequencer "https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/ControlSequencer.cs"
click node_bus "https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/Bus.cs"
click node_registers "https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/Register.cs"
click node_pc "https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/Counter.cs"
click node_alu "https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/ALU.cs"
click node_flags "https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/FlagsRegister.cs"
click node_ram "https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/SRAM.cs"
click node_visual_controls "https://github.com/samfarah/sap1-emulator/tree/main/SAP1Emulator/SAP1Emulator/Visual"
click node_led_display "https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/Visual/LEDDisplay.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_assembly_form,node_simulation_form,node_user toneBlue
class node_assembler toneAmber
class node_computer,node_clock,node_sequencer,node_bus,node_registers,node_pc,node_alu,node_flags,node_ram toneMint
class node_visual_controls,node_led_display toneRose
```

## Components

### User interface

- [Application entry](https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/Program.cs): `SAP1Emulator/SAP1Emulator/Program.cs`
- [Assembly editor](https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/AssemblyForm.cs): `SAP1Emulator/SAP1Emulator/AssemblyForm.cs`
- [Simulation controls](https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SumulationForm.cs): `SAP1Emulator/SAP1Emulator/SumulationForm.cs`

### Assembly

- [Assembler](https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/Assembler.cs): `SAP1Emulator/SAP1Emulator/SAP1_Modules/Assembler.cs`

### CPU execution

- [SAP-1 computer](https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/SAP1_8Bit.cs): `SAP1Emulator/SAP1Emulator/SAP1_Modules/SAP1_8Bit.cs`
- [Clock generator](https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/ClockGenerator.cs): `SAP1Emulator/SAP1Emulator/SAP1_Modules/ClockGenerator.cs`
- [Control sequencer](https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/ControlSequencer.cs): `SAP1Emulator/SAP1Emulator/SAP1_Modules/ControlSequencer.cs`
- [Shared bus](https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/Bus.cs): `SAP1Emulator/SAP1Emulator/SAP1_Modules/Bus.cs`
- [CPU registers](https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/Register.cs): `SAP1Emulator/SAP1Emulator/SAP1_Modules/Register.cs`
- [Program counter](https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/Counter.cs): `SAP1Emulator/SAP1Emulator/SAP1_Modules/Counter.cs`
- [Arithmetic unit](https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/ALU.cs): `SAP1Emulator/SAP1Emulator/SAP1_Modules/ALU.cs`
- [Flags register](https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/FlagsRegister.cs): `SAP1Emulator/SAP1Emulator/SAP1_Modules/FlagsRegister.cs`
- [RAM](https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/SAP1_Modules/SRAM.cs): `SAP1Emulator/SAP1Emulator/SAP1_Modules/SRAM.cs`

### Visualization

- [LEDs and arrows](https://github.com/samfarah/sap1-emulator/tree/main/SAP1Emulator/SAP1Emulator/Visual): `SAP1Emulator/SAP1Emulator/Visual`
- [LED display](https://github.com/samfarah/sap1-emulator/blob/main/SAP1Emulator/SAP1Emulator/Visual/LEDDisplay.cs): `SAP1Emulator/SAP1Emulator/Visual/LEDDisplay.cs`

### Other components

- **User or caller**

## Connections

- User or caller → Application entry: launches
- Application entry → Simulation controls: opens
- User or caller → Assembly editor: edits or loads
- User or caller → SAP-1 computer: creates and runs
- SAP-1 computer → Shared bus: constructs and connects
- SAP-1 computer → CPU registers: constructs
- SAP-1 computer → Arithmetic unit: constructs
- SAP-1 computer → RAM: constructs with MAR
- SAP-1 computer → Program counter: constructs
- SAP-1 computer → Flags register: constructs
- SAP-1 computer → Clock generator: controls
- SAP-1 computer → Control sequencer: applies control signals
- SAP-1 computer → Simulation controls: state displayed by
- Simulation controls → LEDs and arrows: updates
- Simulation controls → LED display: updates
- Assembler → SAP-1 computer: machine code used by
