holey-bytes/src/memory.rs

43 lines
1.1 KiB
Rust
Raw Normal View History

2023-04-22 17:17:49 -05:00
use hashbrown::HashMap;
use log::trace;
use crate::{engine::Page, RuntimeErrors};
2023-04-22 16:06:33 -05:00
pub struct Memory {
//TODO: hashmap with the start bytes as key and end bytes as offset
2023-04-22 17:17:49 -05:00
inner: HashMap<u64, Page>,
}
impl Memory {
pub fn new() -> Self {
Self {
inner: HashMap::new(),
}
}
pub fn map_vec(&mut self, address: u64, vec: Vec<u8>) {}
2023-04-22 16:06:33 -05:00
}
2023-04-22 17:17:49 -05:00
2023-04-22 16:06:33 -05:00
impl Memory {
2023-04-22 17:17:49 -05:00
pub fn read_addr8(&mut self, address: u64) -> Result<u8, RuntimeErrors> {
let (page, offset) = addr_to_page(address);
let val: u8 = self.inner.get(&page).unwrap().data[offset as usize];
trace!("Value read {} from page {} offset {}", val, page, offset);
Ok(val)
2023-04-22 16:06:33 -05:00
}
pub fn read_addr64(&mut self, address: u64) -> u64 {
2023-04-22 17:17:49 -05:00
unimplemented!()
2023-04-22 16:06:33 -05:00
}
2023-04-22 17:17:49 -05:00
pub fn set_addr8(&self, address: u64, value: u8) -> Result<(), RuntimeErrors> {
unimplemented!()
2023-04-22 16:06:33 -05:00
}
pub fn set_addr64(&mut self, address: u64, value: u64) -> u64 {
2023-04-22 17:17:49 -05:00
unimplemented!()
2023-04-22 16:06:33 -05:00
}
}
2023-04-22 17:17:49 -05:00
fn addr_to_page(addr: u64) -> (u64, u64) {
(addr / 8192, addr % 8192)
}