More flexible bus system that takes VIC-20 address mapping and multiplexed buses like the MCS-4 into account.
Broken currently, subject to fixes
This commit is contained in:
parent
ddac8865fa
commit
ba1b0ddc22
14 changed files with 1000 additions and 68 deletions
29
src/pin.rs
29
src/pin.rs
|
|
@ -7,45 +7,42 @@ pub enum PinValue {
|
|||
Low,
|
||||
HighZ, // High impedance (disconnected)
|
||||
}
|
||||
// Pin structure with output enable
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Pin {
|
||||
pub name: String,
|
||||
pub value: Arc<RwLock<PinValue>>, // Use RwLock for multiple readers
|
||||
pub output_enable: Arc<Mutex<bool>>, // Whether this pin is driving the line
|
||||
pub value: Arc<RwLock<PinValue>>,
|
||||
pub output_enable: Arc<Mutex<bool>>,
|
||||
pub connections: Arc<Mutex<Vec<Arc<Pin>>>>,
|
||||
}
|
||||
// Component trait
|
||||
impl Pin {
|
||||
// Get the effective value considering all connected pins
|
||||
pub fn read(&self) -> PinValue {
|
||||
let connections = self.connections.lock().unwrap();
|
||||
|
||||
let mut found_high_pin = false;
|
||||
|
||||
// Check if any connected pin is actively driving low
|
||||
for connected_pin in connections.iter() {
|
||||
let output_enable = connected_pin.output_enable.lock().unwrap();
|
||||
let value = connected_pin.value.read().unwrap();
|
||||
|
||||
|
||||
if *output_enable && *value == PinValue::Low {
|
||||
return PinValue::Low;
|
||||
}
|
||||
}
|
||||
|
||||
// If no one is driving low, check if anyone is driving high
|
||||
for connected_pin in connections.iter() {
|
||||
let output_enable = connected_pin.output_enable.lock().unwrap();
|
||||
let value = connected_pin.value.read().unwrap();
|
||||
|
||||
if *output_enable && *value == PinValue::High {
|
||||
return PinValue::High;
|
||||
} else if *output_enable && *value == PinValue::High {
|
||||
found_high_pin = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If no one is driving, return HighZ
|
||||
PinValue::HighZ
|
||||
if found_high_pin {
|
||||
PinValue::Low
|
||||
} else {
|
||||
PinValue::HighZ
|
||||
}
|
||||
}
|
||||
|
||||
// Set this pin's value and output enable
|
||||
pub fn write(&self, value: PinValue, output_enable: bool) {
|
||||
*self.value.write().unwrap() = value;
|
||||
*self.output_enable.lock().unwrap() = output_enable;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue