more instructions and tests passing.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
use crate::constants::constants_system::SIZE_32KB;
|
||||
use crate::periph::at28c256::At28C256;
|
||||
use crate::periph::hm62256::Hm62256;
|
||||
|
||||
impl Default for At28C256 {
|
||||
fn default() -> Self {
|
||||
let vec = vec![0xea; SIZE_32KB];
|
||||
let boxed_slice: Box<[u8]> = vec.into_boxed_slice();
|
||||
let boxed_array: Box<[u8; SIZE_32KB]> = boxed_slice.try_into().expect("Failed to convert Vec to boxed array");
|
||||
At28C256 {
|
||||
data: boxed_array,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn smoke() { assert!(true); }
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
mod default;
|
||||
mod rom_chip;
|
||||
|
||||
use crate::constants::constants_system::SIZE_32KB;
|
||||
use crate::periph::rom_chip::RomChip;
|
||||
|
||||
@@ -11,31 +14,6 @@ pub struct At28C256 {
|
||||
data: Box<[u8; SIZE_32KB]>,
|
||||
}
|
||||
|
||||
impl Default for At28C256 {
|
||||
fn default() -> Self {
|
||||
let vec = vec![0x00; SIZE_32KB];
|
||||
let boxed_slice: Box<[u8]> = vec.into_boxed_slice();
|
||||
let boxed_array: Box<[u8; SIZE_32KB]> = boxed_slice.try_into().expect("Failed to convert Vec to boxed array");
|
||||
At28C256 {
|
||||
data: boxed_array,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RomChip for At28C256 {
|
||||
|
||||
fn read(&self, offset: &u16) -> u8 {
|
||||
self.data[*offset as usize]
|
||||
}
|
||||
|
||||
fn program(new_data: Box<[u8; SIZE_32KB]>) -> Box<At28C256> {
|
||||
println!("Writing new chip.");
|
||||
let mut working = At28C256::default();
|
||||
working.data = Box::new(*new_data);
|
||||
working.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::constants::constants_system::SIZE_1KB;
|
||||
@@ -0,0 +1,27 @@
|
||||
use crate::constants::constants_system::SIZE_32KB;
|
||||
use crate::periph::at28c256::At28C256;
|
||||
use crate::periph::rom_chip::RomChip;
|
||||
|
||||
impl RomChip for At28C256 {
|
||||
|
||||
fn read(&self, offset: &u16) -> u8 {
|
||||
self.data[*offset as usize]
|
||||
}
|
||||
|
||||
fn program(new_data: Box<[u8; SIZE_32KB]>) -> Box<At28C256> {
|
||||
println!("Writing new chip.");
|
||||
let mut working = At28C256::default();
|
||||
working.data = Box::new(*new_data);
|
||||
working.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn smoke() { assert!(true); }
|
||||
|
||||
|
||||
}
|
||||
@@ -5,9 +5,9 @@ use crate::constants::constants_system::SIZE_32KB;
|
||||
use crate::periph::ram_chip::RamChip;
|
||||
use crate::periph::rom_chip::RomChip;
|
||||
|
||||
struct Hm62256 {
|
||||
base_offset: u16,
|
||||
data: Box<[u8]>
|
||||
pub struct Hm62256 {
|
||||
pub(crate) base_offset: u16,
|
||||
pub(crate) data: Box<[u8]>
|
||||
}
|
||||
|
||||
impl Default for Hm62256 {
|
||||
@@ -24,8 +24,9 @@ impl Default for Hm62256 {
|
||||
|
||||
impl RomChip for Hm62256 {
|
||||
fn read(&self, offset: &u16) -> u8 {
|
||||
//println!("READING FROM RAM AT [{offset:04x}]");
|
||||
self.data[*offset as usize]
|
||||
// loops memory around past 32k
|
||||
let effective = *offset as i32 % SIZE_32KB as i32;
|
||||
self.data[effective as usize]
|
||||
}
|
||||
|
||||
fn program(_: Box<[u8; SIZE_32KB]>) -> Box<Self> {
|
||||
|
||||
@@ -2,5 +2,5 @@ pub mod rom_chip;
|
||||
|
||||
pub mod at28c256;
|
||||
pub mod ram_chip;
|
||||
mod hm62256;
|
||||
pub mod hm62256;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user