summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorNathan Lee <me@nwlee.tech>2026-06-05 16:37:32 -0500
committerNathan Lee <me@nwlee.tech>2026-06-05 16:37:32 -0500
commitf92fa7c0aaec9da67fec2854ad484568df0307c9 (patch)
tree0e3b05b3fc0a735da57c74e32090f9b5b5c82311 /src/main.rs
parentccc954547c39a14fb795bcecb6773634e1797ac8 (diff)
refactor a CpuState struct
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 502d285..df644a4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -9,6 +9,12 @@ const MEMORY_SIZE: usize = 64 * 1024 * 1024;
static MEMORY: LazyLock<Mutex<Box<[u8]>>> =
LazyLock::new(|| Mutex::new(vec![0u8; MEMORY_SIZE].into_boxed_slice()));
+struct CpuState<'a> {
+ memory: &'a mut Box<[u8]>,
+ registers: &'a mut [u32;32],
+ pc: &'a mut u32
+}
+
fn main() {
let path = std::path::PathBuf::from("hi");
@@ -48,12 +54,16 @@ fn main() {
loop {
{
let mut memory = MEMORY.lock().expect("Unable to get memory");
- handle_instruction(&mut *memory, &mut registers, &mut pc);
+ handle_instruction(CpuState {
+ memory: &mut *memory,
+ registers: &mut registers,
+ pc: &mut pc
+ });
}
}
}
-fn handle_instruction(memory: &mut Box<[u8]>, registers: &mut [u32], pc: &mut u32) {
+fn handle_instruction(CpuState { memory, registers, pc }: CpuState) {
let word = u32::from_le_bytes([
memory[*pc as usize],
memory[*pc as usize + 1],