boxswap
This commit is contained in:
@@ -9,7 +9,11 @@ impl Default for At28C256 {
|
||||
let boxed_array: Box<[u8; SIZE_32KB]> = boxed_slice
|
||||
.try_into()
|
||||
.expect("Failed to convert Vec to boxed array");
|
||||
At28C256 { data: boxed_array }
|
||||
At28C256 { data: boxed_array,
|
||||
address_bus: 0x0000,
|
||||
data_bus: 0x00,
|
||||
offset: 0x0000
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
use crate::periph::at28c256::At28C256;
|
||||
|
||||
pub struct At28C256State {
|
||||
offset: u16
|
||||
}
|
||||
|
||||
impl At28C256 {
|
||||
pub fn dump(&self) -> At28C256State {
|
||||
At28C256State {
|
||||
offset: self.offset
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ pub mod rom_chip;
|
||||
pub mod tick;
|
||||
mod new;
|
||||
mod program;
|
||||
mod dump;
|
||||
|
||||
use crate::constants::constants_system::SIZE_32KB;
|
||||
use crate::periph::rom_chip::RomChip;
|
||||
@@ -15,7 +16,11 @@ use std::io::Read;
|
||||
/// 256kbit storage
|
||||
/// 32kbyte storage
|
||||
pub struct At28C256 {
|
||||
data_bus: u8,
|
||||
address_bus: u16,
|
||||
data: Box<[u8; SIZE_32KB]>,
|
||||
// where in the computer memory map do we live?
|
||||
offset: u16
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -2,9 +2,12 @@ use crate::constants::constants_system::SIZE_32KB;
|
||||
use crate::periph::at28c256::At28C256;
|
||||
|
||||
impl At28C256 {
|
||||
pub fn new(data: &[u8; SIZE_32KB]) -> Self {
|
||||
pub fn new(offset: u16, data: &[u8; SIZE_32KB]) -> Self {
|
||||
At28C256 {
|
||||
data: (*data).into()
|
||||
data: (*data).into(),
|
||||
address_bus: 0x0000,
|
||||
data_bus: 0x00,
|
||||
offset
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,23 @@
|
||||
use crate::constants::constants_system::SIZE_32KB;
|
||||
use crate::periph::at28c256::At28C256;
|
||||
use crate::periph::hm62256::Hm62256;
|
||||
|
||||
impl At28C256 {
|
||||
fn tick(&mut self, address_bus: u16, data_bus: u8, read_mode: bool) -> (u16, u8) {
|
||||
if read_mode {
|
||||
panic!("UNABLE TO WRITE TO ROM");
|
||||
} else {
|
||||
// has to be read mode. its a rom.
|
||||
return (address_bus, data_bus)
|
||||
fn max_address(&self) -> u16 {
|
||||
self.offset + SIZE_32KB as u16
|
||||
}
|
||||
|
||||
|
||||
pub fn tick(&mut self, address_bus: u16, data_bus: u8, read_mode: bool) -> (u16, u8) {
|
||||
if address_bus.gt(&self.offset) & address_bus.lt(&self.max_address()) {
|
||||
if read_mode {
|
||||
panic!("UNABLE TO WRITE TO ROM");
|
||||
} else {
|
||||
// has to be read mode. its a rom.
|
||||
return (address_bus, data_bus)
|
||||
}
|
||||
}
|
||||
// not for us.
|
||||
(address_bus, self.data[address_bus as usize])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user