Created factory for system creation.

Systems are now defined in JSON rather than hard-coded
This commit is contained in:
Jan-Peter von Hunnius 2025-09-29 12:41:16 +02:00
parent c039e9069a
commit 6f3295dc5e
31 changed files with 1610 additions and 1709 deletions

View file

@ -1,6 +1,7 @@
# Source Code Architecture
This directory contains the core implementation of the Rusty Emulator, an Intel 4004/4001 microprocessor simulator written in Rust.
This directory contains the core implementation of the Rusty Emulator, an Intel 4004/4001 microprocessor simulator
written in Rust.
## Architecture Overview
@ -29,7 +30,9 @@ src/
## Core Abstractions
### Component System
The emulator is built around a component-based architecture where each hardware element implements the `Component` trait:
The emulator is built around a component-based architecture where each hardware element implements the `Component`
trait:
```rust
pub trait Component: Send + Sync {
@ -44,22 +47,27 @@ pub trait Component: Send + Sync {
```
### Pin System
All components communicate through pins that can be in one of three states:
- `High` (logic 1)
- `Low` (logic 0)
- `HighZ` (high impedance/tri-state)
### Clocking
The system uses a two-phase clock architecture (Φ1, Φ2) that matches the Intel 4004's requirements.
## Component Categories
### CPU Components (`src/components/cpu/`)
- **Intel4004**: Complete Intel 4004 CPU implementation
- **MOS6502**: MOS Technology 6502 CPU (placeholder)
- **WDC65C02**: Western Design Center 65C02 CPU (placeholder)
### Memory Components (`src/components/memory/`)
- **Intel4001**: 256-byte ROM with 4-bit I/O ports
- **Intel4002**: 320-bit RAM with 4-bit output ports
- **Intel4003**: 10-bit shift register
@ -67,21 +75,25 @@ The system uses a two-phase clock architecture (Φ1, Φ2) that matches the Intel
- **GenericROM**: Generic ROM implementation
### Common Functionality (`src/components/common/`)
- **Intel400x**: Shared traits and utilities for all Intel 400x series chips
- Clock handling and edge detection
- Data bus operations
- Address handling and latching
- Control pin management
- Reset handling
- Timing state machines
- Clock handling and edge detection
- Data bus operations
- Address handling and latching
- Control pin management
- Reset handling
- Timing state machines
### Clock Components (`src/components/clock/`)
- **GenericClock**: Configurable clock generator
## System Integration (`src/systems/`)
### Intel MCS-4 System
Complete Intel MCS-4 (Micro Computer System) implementation featuring:
- Intel 4004 CPU
- Intel 4001 ROM units
- Intel 4002 RAM units
@ -92,18 +104,21 @@ Complete Intel MCS-4 (Micro Computer System) implementation featuring:
## Key Features
### Hardware-Accurate Simulation
- Cycle-accurate timing where possible
- Two-phase clock operation
- Proper pin drive and tri-state handling
- Bus contention detection and avoidance
### Extensible Architecture
- Trait-based component system
- Easy addition of new CPU types
- Pluggable memory implementations
- Configurable system topologies
### Testing Support
- Comprehensive test suite
- Mock components for isolated testing
- Property-based testing for verification
@ -112,6 +127,7 @@ Complete Intel MCS-4 (Micro Computer System) implementation featuring:
## Usage Examples
### Basic Component Usage
```rust
use rusty_emu::components::memory::intel_4001::Intel4001;
@ -120,13 +136,14 @@ let mut rom = Intel4001::new("ROM1".to_string());
// Load program data
let program = vec![0x12, 0x34, 0x56, 0x78];
rom.load_rom_data(program, 0)?;
rom.load_rom_data(program, 0) ?;
// Use in simulation
rom.update(); // Process one clock cycle
```
### System Integration
```rust
use rusty_emu::systems::intel_mcs_4::IntelMCS4;
@ -134,7 +151,7 @@ use rusty_emu::systems::intel_mcs_4::IntelMCS4;
let mut system = IntelMCS4::new();
// Load program into ROM
system.load_program(0, &program_data)?;
system.load_program(0, & program_data) ?;
// Run simulation
system.run();
@ -143,6 +160,7 @@ system.run();
## Development Guidelines
### Adding New Components
1. Implement the `Component` trait
2. Add appropriate pin configuration
3. Implement timing-accurate behavior
@ -150,12 +168,14 @@ system.run();
5. Update module exports
### Testing Requirements
- Unit tests for individual components
- Integration tests for component interactions
- Property-based tests for behavioral verification
- Mock-based tests for external dependencies
### Code Organization
- Keep components focused on single responsibilities
- Use traits for shared behavior
- Maintain clear separation between hardware abstraction and implementation