Enable NVRAM to be read/stored

This commit is contained in:
Seth Morabito 2018-12-17 15:27:34 -07:00
parent 05816b838d
commit 855f750538
3 changed files with 39 additions and 1 deletions

View File

@ -6,6 +6,8 @@ use crate::err::DuartError;
use std::fmt::Debug;
use std::ops::Range;
const NVRAM_SIZE: usize = 8192;
/// Access Status Code
pub enum AccessCode {
MoveTranslated,
@ -208,6 +210,22 @@ impl Bus {
pub fn duart_output(&self) -> u8 {
self.duart.output_port()
}
pub fn get_nvram(&self) -> [u8; NVRAM_SIZE] {
let mut contents: [u8; NVRAM_SIZE] = [0u8; NVRAM_SIZE];
for i in 0..NVRAM_SIZE {
contents[i] = self.bbram[i];
}
contents
}
pub fn set_nvram(&mut self, nvram: &[u8; NVRAM_SIZE]) {
for (i, b) in nvram.into_iter().enumerate() {
self.bbram[i] = *b;
}
}
}
#[cfg(test)]

View File

@ -150,6 +150,20 @@ impl Dmd {
pub fn duart_output(&self) -> u8 {
self.bus.duart_output()
}
///
/// Load NVRAM into the emulator
///
pub fn set_nvram(&mut self, nvram: &[u8; 8192]) {
self.bus.set_nvram(nvram);
}
///
/// Get NVRAM from the emulator
///
pub fn get_nvram(&self) -> [u8; 8192] {
self.bus.get_nvram()
}
}
#[cfg(test)]

View File

@ -4,7 +4,7 @@ use crate::err::BusError;
use std::fmt::Debug;
use std::fmt::Error;
use std::fmt::Formatter;
use std::ops::Index;
use std::ops::{Index, IndexMut};
use std::vec::Vec;
use std::ops::Range;
@ -168,6 +168,12 @@ impl Index<usize> for Mem {
}
}
impl IndexMut<usize> for Mem {
fn index_mut<'a>(&'a mut self, idx: usize) -> &'a mut u8 {
&mut self.ram[idx]
}
}
#[cfg(test)]
mod tests {
use super::*;