Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚡ NanoTekSpice

A digital electronics simulator

C++ Make


📖 About

NanoTekSpice is a logic simulator that parses circuit description files (.nts) and simulates digital electronic components using tri-state logic (True, False, Undefined).

The program builds a virtual circuit from a configuration file, then provides an interactive shell to manipulate inputs, run simulations and observe output states in real-time.


🏗️ Architecture

The project follows a clean OOP architecture leveraging interfaces, abstract classes, and the Factory design pattern:

┌─────────────┐
│ IComponent  │  ← Pure interface
└──────┬──────┘
       │
┌──────▼──────┐
│ AComponent  │  ← Abstract base class (common logic, link management)
└──────┬──────┘
       │
       ├──── Elementary Gates (AND, OR, NOT, XOR)
       ├──── Chipset Components (4001, 4011, 4030, 4069, 4071, 4081)
       └──── Special Components (Input, Output, True, False, Clock)

Key Design Patterns

Pattern Usage
Interface (IComponent) Defines the contract for all components (compute, simulate, setLink…)
Abstract Class (AComponent) Implements shared behavior: pin management, bidirectional linking, error handling
Factory Creates components dynamically from type strings via a lambda registry
Composite Chipset components (4xxx) are composed of elementary gates internally

🔌 Supported Components

Special Components

Component Description
input User-defined input, value set via CLI
output Displays the computed result of the circuit
true Constant — always outputs 1
false Constant — always outputs 0
clock Alternating signal, toggles state on each simulation tick

Elementary Gates

Gate Logic
and Output is 1 only if both inputs are 1
or Output is 1 if at least one input is 1
not Inverts the input signal
xor Output is 1 if inputs are different

Chipset Components (4000 series)

Chipset Type Pins Description
4001 NOR 14 Quad 2-input NOR gates
4011 NAND 14 Quad 2-input NAND gates
4030 XOR 14 Quad 2-input XOR gates
4069 NOT 14 Hex inverter (6 NOT gates)
4071 OR 14 Quad 2-input OR gates
4081 AND 14 Quad 2-input AND gates

🚀 Getting Started

Prerequisites

  • g++ with C++20 support
  • GNU Make

Build

make            # Build the project
make re         # Clean rebuild
make fclean     # Remove binary and object files

Run

./nanotekspice <circuit_file.nts>

📄 Circuit File Format (.nts)

Circuit files describe components and their connections:

# This is a comment

.chipsets:
input   a
input   b
and     gate
output  s

.links:
a:1     gate:1
b:1     gate:2
gate:3  s:1
  • .chipsets: — Declares the components with their type and name
  • .links: — Connects component pins together (name:pin)
  • # — Lines starting with # are comments

💻 Interactive Shell

Once the circuit is loaded, NanoTekSpice provides an interactive prompt:

> 

Available Commands

Command Description
exit Closes the program
display Shows the current tick, input values and output values
simulate Advances the simulation by one tick
loop Continuously simulates until interrupted (Ctrl+C)
<name>=<value> Sets an input component's value (0, 1, or U)

Example Session

> a=1
> b=1
> simulate
> display
tick: 1
input(s):
  a: 1
  b: 1
output(s):
  s: 1
> b=0
> simulate
> display
tick: 2
input(s):
  a: 1
  b: 0
output(s):
  s: 0
> exit

📂 Project Structure

.
├── main.cpp                          # Entry point
├── Makefile                          # Build system
├── include/
│   └── my.hpp                        # Global includes & My_Struct definition
├── class/
│   ├── IComponent.hpp                # Component interface
│   ├── AComponent.hpp / .cpp         # Abstract component base class
│   ├── Factory.hpp / .cpp            # Component factory (lambda registry)
│   ├── FileParser.hpp / .cpp         # .nts file parser
│   ├── ParserCli.hpp / .cpp          # Interactive CLI handler
│   ├── Fileloader.hpp                # File loading utility
│   └── Tristate.hpp                  # Tri-state enum (True, False, Undefined)
├── components/
│   ├── AndComponent.hpp / .cpp       # AND gate
│   ├── OrComponent.hpp / .cpp        # OR gate
│   ├── NotComponent.hpp / .cpp       # NOT gate
│   ├── XorComponent.hpp / .cpp       # XOR gate
│   ├── special/
│   │   ├── InputComponent.hpp / .cpp
│   │   ├── OutputComponent.hpp / .cpp
│   │   ├── TrueComponent.hpp / .cpp
│   │   ├── FalseComponent.hpp / .cpp
│   │   └── ClockComponent.hpp / .cpp
│   └── gate_components/
│       ├── C4001.hpp / .cpp          # Quad NOR
│       ├── C4011.hpp / .cpp          # Quad NAND
│       ├── C4030.hpp / .cpp          # Quad XOR
│       ├── C4069.hpp / .cpp          # Hex NOT
│       ├── C4071.hpp / .cpp          # Quad OR
│       └── C4081.hpp / .cpp          # Quad AND

⚙️ Tri-State Logic

NanoTekSpice uses a tri-state value system to accurately model real digital electronics:

Value Meaning
True (1) Logic high
False (0) Logic low
Undefined (U) Unknown / not yet computed

This allows the simulator to correctly propagate undefined states through the circuit when inputs haven't been set.


About

A digital electronics simulator

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages