Enable NVRAM to be read/stored
This commit is contained in:
parent
05816b838d
commit
855f750538
18
src/bus.rs
18
src/bus.rs
|
@ -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)]
|
||||
|
|
14
src/dmd.rs
14
src/dmd.rs
|
@ -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)]
|
||||
|
|
|
@ -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::*;
|
||||
|
|
Loading…
Reference in New Issue