49 lines
1.2 KiB
Rust
49 lines
1.2 KiB
Rust
pub trait MemoryMapper {
|
|
/// Read a byte at the specified address through the memory mapper
|
|
fn read(&mut self, address: u16) -> u8;
|
|
|
|
/// Write a byte to the specified address through the memory mapper
|
|
fn write(&mut self, address: u16, value: u8);
|
|
|
|
/// Receive a byte from a device on the I/O bus through the memory mapper
|
|
#[allow(unused_variables)]
|
|
fn read_io(&mut self, port: u8) -> u8 {
|
|
0
|
|
}
|
|
|
|
/// Send a byte to a device on the I/O bus through the memory mapper
|
|
#[allow(unused_variables)]
|
|
fn write_io(&mut self, port: u8, value: u8) {}
|
|
}
|
|
|
|
//#[cfg(test)]
|
|
pub struct TestMapper(pub [u8; u16::MAX as usize + 1]);
|
|
|
|
//#[cfg(test)]
|
|
impl MemoryMapper for TestMapper {
|
|
fn read(&mut self, address: u16) -> u8 {
|
|
self.0[address as usize]
|
|
}
|
|
|
|
fn write(&mut self, address: u16, value: u8) {
|
|
self.0[address as usize] = value;
|
|
}
|
|
|
|
fn write_io(&mut self, port: u8, value: u8) {
|
|
if port == 0x1 {
|
|
if value == b'\n' {
|
|
println!();
|
|
} else {
|
|
print!("{}", value as char);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//#[cfg(test)]
|
|
impl Default for TestMapper {
|
|
fn default() -> Self {
|
|
Self([0; u16::MAX as usize + 1])
|
|
}
|
|
}
|