Implement IO access to cards
This commit is contained in:
parent
63096025bd
commit
476c744bfa
34
src/state.rs
34
src/state.rs
@ -15,6 +15,7 @@ pub struct EmuState {
|
|||||||
options: Options,
|
options: Options,
|
||||||
fp_state: FrontpanelState,
|
fp_state: FrontpanelState,
|
||||||
cards: Vec<(&'static Type, Box<dyn Card>)>,
|
cards: Vec<(&'static Type, Box<dyn Card>)>,
|
||||||
|
io_cache: Option<(u8, u8)>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EmuState {
|
impl EmuState {
|
||||||
@ -34,6 +35,7 @@ impl EmuState {
|
|||||||
options,
|
options,
|
||||||
fp_state: FrontpanelState::default(),
|
fp_state: FrontpanelState::default(),
|
||||||
cards,
|
cards,
|
||||||
|
io_cache: None,
|
||||||
};
|
};
|
||||||
slf.apply_options();
|
slf.apply_options();
|
||||||
slf
|
slf
|
||||||
@ -125,8 +127,10 @@ impl EmuState {
|
|||||||
| MemCycle::Hlta => {
|
| MemCycle::Hlta => {
|
||||||
self.fp_state.set_data(0xff);
|
self.fp_state.set_data(0xff);
|
||||||
}
|
}
|
||||||
MemCycle::In(_) => {
|
MemCycle::In(a) => {
|
||||||
self.fp_state.set_data(0);
|
let data = self.read_io(a as u8);
|
||||||
|
self.io_cache = Some((a as u8, data));
|
||||||
|
self.fp_state.set_data(data);
|
||||||
}
|
}
|
||||||
MemCycle::Inta(_) => todo!(),
|
MemCycle::Inta(_) => todo!(),
|
||||||
MemCycle::IntaHlt(_) => todo!(),
|
MemCycle::IntaHlt(_) => todo!(),
|
||||||
@ -141,8 +145,22 @@ impl EmuState {
|
|||||||
self.write_mem(a, d);
|
self.write_mem(a, d);
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
MemCycle::In(_) => 0,
|
MemCycle::In(a) => {
|
||||||
MemCycle::Out(_, _) => 0,
|
if let Some((cached_addr, cached_data)) = self.io_cache {
|
||||||
|
if cached_addr == a as u8 {
|
||||||
|
self.io_cache = None;
|
||||||
|
cached_data
|
||||||
|
} else {
|
||||||
|
self.read_io(a as u8)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.read_io(a as u8)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
MemCycle::Out(a, d) => {
|
||||||
|
self.write_io(a as u8, d);
|
||||||
|
0
|
||||||
|
},
|
||||||
MemCycle::Inta(_) => todo!(),
|
MemCycle::Inta(_) => todo!(),
|
||||||
MemCycle::Hlta => {
|
MemCycle::Hlta => {
|
||||||
self.running = false;
|
self.running = false;
|
||||||
@ -217,4 +235,12 @@ impl EmuState {
|
|||||||
fn write_mem(&mut self, address: u16, data: u8) {
|
fn write_mem(&mut self, address: u16, data: u8) {
|
||||||
self.cards.iter_mut().find_map(|(_, card)| card.write_mem(address, data));
|
self.cards.iter_mut().find_map(|(_, card)| card.write_mem(address, data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn read_io(&mut self, address: u8) -> u8 {
|
||||||
|
self.cards.iter_mut().find_map(|(_, card)| card.read_io(address)).unwrap_or(0xFF)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_io(&mut self, address: u8, data: u8) {
|
||||||
|
self.cards.iter_mut().find_map(|(_, card)| card.write_io(address, data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user