mirror of
https://github.com/Noratrieb/rustv32i.git
synced 2026-01-14 13:25:01 +01:00
init
This commit is contained in:
commit
7183421b8f
10 changed files with 378 additions and 0 deletions
41
src/emu.rs
Normal file
41
src/emu.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
use aligned_vec::{AVec, ConstAlign};
|
||||
|
||||
use crate::PAGE_SIZE;
|
||||
|
||||
pub struct Memory {
|
||||
pub mem: AVec<u8, ConstAlign<PAGE_SIZE>>,
|
||||
}
|
||||
|
||||
impl Memory {
|
||||
fn load_u32(&self, addr: u32) -> Result<u32, ()> {
|
||||
Ok(u32::from_le_bytes(
|
||||
self.mem
|
||||
.get((addr as usize)..)
|
||||
.ok_or(())?
|
||||
.get(..4)
|
||||
.ok_or(())?
|
||||
.try_into()
|
||||
.unwrap(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Emulator {
|
||||
pub mem: Memory,
|
||||
pub xreg: [u32; 32],
|
||||
pub pc: u32,
|
||||
}
|
||||
|
||||
impl Emulator {
|
||||
pub fn execute(&mut self) -> Result<(), ()> {
|
||||
loop {
|
||||
self.step();
|
||||
}
|
||||
}
|
||||
|
||||
fn step(&mut self) -> Result<(), ()> {
|
||||
let instruction = self.mem.load_u32(self.pc)?;
|
||||
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue