"工欲善其事,必先利其器" - Confucius
"A craftsman who wishes to do his work well must first sharpen his tools."
ProtoVM is more than just a digital logic simulator - it's a playground for electronic hobbyists, a learning tool for students, and a prototyping environment for engineers. Whether you're building your first 8-bit computer or exploring complex digital circuits, ProtoVM provides the virtual workspace to bring your electronic dreams to life.
This project embodies the spirit of innovation that drives the maker community. Just as early computer pioneers like Steve Wozniak handcrafted circuits on breadboards, you can now design, simulate, and test complex digital systems right from your computer.
ProtoVM is a custom digital logic simulator that models real hardware components including CPUs, memory, buses, and basic logic gates. Originally developed as a simple sequential processor, it has been significantly enhanced to properly handle the complexities of digital circuit behavior.
The system now correctly models signal propagation, feedback loops, and component interactions in a way that closely approximates real hardware behavior, making it suitable for simulating moderately complex digital circuits.
Instead of simple sequential processing, ProtoVM now implements a sophisticated multi-tick convergence algorithm that iterates until all signals in the digital circuit stabilize. This approach mimics how real digital circuits behave, where signals propagate through components until reaching a stable state.
The enhanced bus system properly models tri-state logic, allowing multiple components to share the same bus lines while preventing electrical conflicts. This includes:
- Driver arbitration mechanisms
- Proper bus contention handling
- Realistic signal floating and pull-up behaviors
All components now implement intelligent change detection, tracking their internal state and only triggering reprocessing when actually needed. This optimization significantly improves simulation performance.
The system correctly handles combinatorial feedback that can occur in digital circuits, preventing incorrect behavior and ensuring stable simulation.
The central coordinator that manages component interactions and executes the convergence-based simulation algorithm. It tracks all PCBs (Printed Circuit Boards) and their interconnected components.
Abstract base class for all electronic components in the simulation. Provides common functionality for:
- Connection management
- Signal processing
- State tracking
- Component identification
Specialized components that model address and data buses with proper tri-state support:
- Bus: Template class for buses of varying widths
- AddrBus: Specialized address bus implementation
- DataBus: Specialized data bus implementation
Models of actual integrated circuits:
- IC6502: Accurate emulation of the MOS Technology 6502 CPU
- ICRamRom: Configurable memory components (RAM/ROM)
- Logic Gates: Basic digital logic building blocks (NAND, NOR, NOT, etc.)
The enhanced ProtoVM models digital signal behavior more accurately:
- Tri-State Logic: Components can drive, read, or float bus lines
- Signal Integrity: Prevention of bus contention through proper arbitration
- Propagation Delays: Implicit modeling through iterative convergence
- Setup/Hold Times: Component behavior respects timing constraints
The heart of the enhancement is the multi-tick convergence algorithm implemented in Machine::Tick():
bool Machine::Tick() {
int iterations = 0;
const int MAX_ITERATIONS = 100;
bool changed;
do {
changed = false;
// Process all components until no more changes occur
if (!RunRtOpsWithChangeDetection(changed)) {
return false;
}
iterations++;
} while (changed && iterations < MAX_ITERATIONS);
return true;
}This approach ensures that all signal propagation paths are properly resolved within each simulation tick.
Components now implement intelligent state tracking:
class ElectricNodeBase {
private:
bool has_changed = true; // Track if component state has changed
public:
bool HasChanged() const { return has_changed; }
void SetChanged(bool changed = true) { has_changed = changed; }
virtual bool Tick() = 0;
};Only components that have actually changed state trigger reprocessing, optimizing performance.
The enhanced bus system properly handles multiple drivers:
template<int Width>
class Bus : public ElectricNodeBase {
bool is_driven[BYTES]; // Track which bytes are actively driven
byte data[BYTES]; // Bus data
public:
bool PutRaw(uint16 conn_id, byte* data, int data_bytes, int data_bits) override;
};This prevents bus contention and models realistic tri-state behavior.
# Build the simulator
make
# Run the test scenario
./run.shThe default test sets up a simple 6502-based system with:
- 6502 CPU
- ROM for program storage
- RAM for data storage
- Address and data buses
- Control signal logic
Components are connected through a flexible linking system that supports:
- Unidirectional connections (power, ground)
- Bidirectional connections (data buses)
- Multi-connection points (bus lines)
- Processors: MOS 6502 CPU emulation
- Memory: Configurable RAM/ROM modules
- Logic: Basic gates (NAND, NOR, NOT, Buffer)
- Interfaces: Tri-state buffers, Pull-ups, Capacitors
- Buses: Address and data buses with arbitration
- Voltage Levels: Digital high/low representation
- Bus Widths: Configurable bit widths (8-bit, 16-bit, etc.)
- Tri-State Support: Drive, Read, Float states
- Contention Handling: Proper arbitration mechanisms
- Implicit Delays: Modeled through iterative convergence
- Setup/Hold Times: Respected through component implementation
- Clock Domains: Single-clock domain support
- Stable State Detection: Automatic convergence detection
The original ProtoVM had several limitations:
- Simple sequential processing without feedback consideration
- No proper modeling of signal propagation delays
- Lack of tri-state bus support
- Absence of convergence detection
- Limited change optimization
The improvements were implemented systematically:
- Analysis Phase: Understanding the original architecture and identifying limitations
- Design Phase: Planning the convergence-based approach
- Implementation Phase: Modifying core classes to support new functionality
- Testing Phase: Verifying the enhanced behavior with test scenarios
- Documentation Phase: Creating comprehensive documentation
- Machine.cpp: Core simulation engine with convergence algorithm
- Bus.h/.cpp: Enhanced tri-state bus support
- IC6502.cpp: Improved CPU emulation with proper state tracking
- ICRamRom.cpp: Enhanced memory components with change detection
- Common.h: Base component classes with change tracking
- Proper modeling of real digital circuit behavior
- Correct handling of feedback loops and signal races
- Realistic bus arbitration and tri-state logic
- Stable simulation output with proper convergence
- Optimized processing through change detection
- Reduced unnecessary computation
- Efficient state tracking mechanisms
- Early termination on signal stabilization
- Oscillation detection preventing infinite loops
- Proper error handling and recovery
- Robust component interaction
- Predictable simulation behavior
- Multi-Clock Domain Support: Handling circuits with multiple clock sources
- Detailed Timing Analysis: Explicit propagation delay modeling
- Formal Verification Integration: Mathematical proof of circuit correctness
- Advanced Bus Protocols: SPI, I2C, and other communication standards
- Topological Sorting: Component evaluation order optimization
- Parallel Processing: Multi-threaded simulation for complex circuits
- Incremental Simulation: Selective re-evaluation of changed portions
- Memory Management: Optimized data structures for large circuits
- Graphical Interface: Visual representation of circuit behavior
- Waveform Display: Signal tracing and analysis
- Interactive Debugging: Breakpoints and state inspection
- Performance Profiling: Component usage and bottleneck analysis
The ProtoVM digital logic simulation system has been successfully transformed from a simple sequential processor to a robust digital logic simulator. The convergence-based approach with intelligent change detection provides both accuracy and performance, making it suitable for simulating moderately complex digital circuits.
The enhancements ensure that ProtoVM now properly models the complexities of real hardware behavior while maintaining the flexibility and extensibility of the original design. This positions the project well for future development and expansion into more sophisticated digital simulation scenarios.
- FullAdder: Basic building block implementing sum and carry logic
- Adder4Bit: 4-bit ripple carry adder using full adders
- AdderSubtractor4Bit: 4-bit adder/subtractor with control for operation selection
- Created comprehensive unit tests for arithmetic components
- Added test command line option (
./ProtoVM unittests) - Verified functionality of basic components before integration
- Complete 4004 CPU Implementation: All 45 instructions implemented with proper timing
- 4001 ROM Component: 256 bytes of program storage (2048x4-bit capacity)
- 4002 RAM Component: 40 bytes of memory storage with proper I/O handling
- 4003 I/O Shift Register: For expanded input/output capabilities
- Minimax Computer System: Complete computer system implementation using 4004 CPU
- Schematic Programming Language: Pythonic language with indentation-based blocks
- MDS-1101 Schematic Tools: Tools for analyzing single-transistor calculator PCB images
- HLA3 Assembler Integration: Complete toolchain for programming the 4004
- Binary Loading: Command-line option to load binary program files
- Interactive Debugger: Memory poking, register inspection, step execution
- Memory Dumping: Hexadecimal and ASCII memory dump functionality
- Enhanced I/O Control: Options to switch between different I/O modes
All tasks from TASKS.md have been completed successfully. The ProtoVM digital logic simulator is fully enhanced with all requested features.
A new example demonstrating analog audio synthesis from the 1970s era:
- VCOs (Voltage Controlled Oscillators) with multiple waveforms (sine, sawtooth, square, triangle)
- ADSR envelope generator for note shaping
- Portamento/gliding effect between notes
- Sequencer that plays random notes at 120 BPM
- Real-time audio output via PortAudio
- WAV file export capability