5.5 KiB
5.5 KiB
System Control Architecture Design
Overview
This document outlines the architecture for implementing enhanced system start/stop/pause controls for the Intel MCS-4 emulator. The design provides centralized system management with fine-grained control over execution state and clock parameters.
System Architecture
graph TB
subgraph "System Controller Layer"
SC[SystemController Trait]
EC[ExecutionController]
SS[SystemState Enum]
end
subgraph "System Layer"
CS[ConfigurableSystem]
SF[SystemFactory]
end
subgraph "Component Layer"
CPU[Intel4004]
CLK1[GenericClock]
CLK2[TwoPhaseClock]
ROM[Intel4001]
RAM[Intel4002]
end
subgraph "Interface Layer"
GUI[GUI Control Panel]
CON[Console Commands]
KB[Keyboard Shortcuts]
end
SC --> EC
EC --> CS
CS --> CPU
CS --> CLK1
CS --> CLK2
CS --> ROM
CS --> RAM
GUI --> SC
CON --> SC
KB --> SC
Core Components
1. SystemController Trait
Defines the interface for system-wide control operations:
pub trait SystemController {
fn start(&mut self) -> Result<(), String>;
fn stop(&mut self) -> Result<(), String>;
fn pause(&mut self) -> Result<(), String>;
fn resume(&mut self) -> Result<(), String>;
fn is_running(&self) -> bool;
fn is_paused(&self) -> bool;
fn set_clock_frequency(&mut self, frequency: f64) -> Result<(), String>;
fn set_clock_enabled(&mut self, enabled: bool) -> Result<(), String>;
fn get_system_state(&self) -> SystemState;
fn get_clock_frequency(&self) -> f64;
fn get_clock_enabled(&self) -> bool;
}
2. SystemState Enum
Tracks the overall system execution state:
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum SystemState {
Stopped,
Running,
Paused,
Error(String),
}
3. ExecutionController
Manages system lifecycle and coordinates component states:
pub struct ExecutionController {
system_state: SystemState,
clock_frequency: f64,
clock_enabled: bool,
components: HashMap<String, Arc<Mutex<Box<dyn Component>>>>,
}
Component Enhancements
Clock Components
GenericClock & TwoPhaseClock Enhancements:
- Add
pausedboolean field - Implement
pause()andresume()methods - Add dynamic frequency adjustment with
set_frequency(f64) - Add
enable()anddisable()methods for power control - Update
update()methods to respect pause state
CPU Component
Intel4004 Enhancements:
- Add
pausedboolean field - Implement
pause()to halt instruction execution - Implement
resume()to continue instruction execution - Update
update()to check pause state before executing instructions - Maintain clock edge detection during pause for seamless resume
Memory Components
Intel4001 & Intel4002 Enhancements:
- Add
pausedboolean field - Implement
pause()andresume()methods - Update
update()to respect pause state - Ensure memory operations complete current cycle before pausing
Interface Updates
Console Commands
New console commands:
pause/p- Pause system executionresume- Resume system executionclock <freq>- Set clock frequency (e.g.,clock 500000)clock on/clock off- Enable/disable clockspeed +/speed -- Increase/decrease clock frequency by 50%
GUI Controls
New GUI control panel:
- System state indicator (Stopped/Running/Paused)
- Start/Stop/Pause/Resume buttons
- Clock frequency slider (100Hz - 10MHz range)
- Clock enable/disable toggle
- Real-time frequency display
- Keyboard shortcuts (Space=pause/resume, +/- for frequency)
Configuration Schema
Extended JSON configuration with clock control:
{
"clock_control": {
"initial_frequency": 750000,
"min_frequency": 1000,
"max_frequency": 10000000,
"frequency_step": 50000,
"auto_start": true
}
}
Implementation Strategy
Phase 1: Core Infrastructure
- Implement SystemController trait
- Create SystemState enum
- Build ExecutionController
- Update ConfigurableSystem
Phase 2: Component Updates
- Update clock components with pause/resume
- Update CPU with execution control
- Update memory components
- Add dynamic frequency adjustment
Phase 3: Interface Integration
- Update console with new commands
- Enhance GUI with control panel
- Add keyboard shortcuts
- Update configuration handling
Phase 4: Testing & Documentation
- Create comprehensive test suite
- Update all documentation
- Verify backwards compatibility
Key Design Decisions
Pause Behavior
- Complete system freeze including clock signals
- Components maintain state for seamless resume
- Clock edges are tracked but not propagated during pause
Frequency Adjustment
- Dynamic adjustment during runtime
- Smooth transitions without glitches
- Validation against component limits
State Management
- Centralized state tracking
- Thread-safe state updates
- Consistent state across all components
Benefits
- Enhanced Control: Fine-grained system management
- Dynamic Adjustment: Runtime frequency changes
- Better Debugging: Pause/resume for analysis
- User Experience: Intuitive controls in both interfaces
- Extensibility: Clean architecture for future enhancements
Compatibility
- Maintains existing Component trait
- Backwards compatible with current configurations
- No breaking changes to existing APIs
- Optional features with sensible defaults