diff --git a/src/main.rs b/src/main.rs index 1527512..92ddeb3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,21 +66,25 @@ fn main() { let mouse = Arc::new(Mutex::new(Mouse::new())); // 32 MiB of shared memory - let shared_memory = Arc::new(Mutex::new(vec![0u8; 0x02000000])); + // plus 3 bytes at the end to allow for reading the last byte of memory as an immediate pointer + // Operand::ImmediatePtr always reads 4 bytes + let shared_memory = Arc::new(Mutex::new(vec![0u8; 0x02000003])); let mut cpu = { // 32 MiB of fast memory - let cpu_fast_memory = vec![0; 0x02000000]; + // plus 3 extra bytes at the end to allow for reading the last byte of memory as an immediate pointer + // Operand::ImmediatePtr always reads 4 bytes + let cpu_fast_memory = vec![0; 0x02000003]; let cpu_shared_memory = Arc::clone(&shared_memory); let cpu_overlays = Arc::clone(&display.overlays); let cpu_read_only_memory = read_rom(); - let fast_size = cpu_fast_memory.len(); + let fast_size = cpu_fast_memory.len() - 3; let fast_bottom_address = 0x00000000; let fast_top_address = fast_bottom_address + fast_size - 1; println!("Fast: {:.2}MB mapped at {:#010X}-{:#010X}", fast_size / 1048576, fast_bottom_address, fast_top_address); - let shared_size = { cpu_shared_memory.lock().unwrap().len() }; + let shared_size = { cpu_shared_memory.lock().unwrap().len() - 3 }; let shared_bottom_address = 0x80000000; let shared_top_address = shared_bottom_address + shared_size - 1; println!("Shared: {:.2}MB mapped at {:#010X}-{:#010X}", shared_size / 1048576, shared_bottom_address, shared_top_address); diff --git a/src/memory.rs b/src/memory.rs index df21937..a9ce675 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -18,9 +18,10 @@ pub struct Memory { impl Memory { pub fn new(fast_memory: Vec, shared_memory: Arc>>, overlays: Arc>>, rom: Vec) -> Self { - let shared_memory_size = { shared_memory.lock().unwrap().len() }; + // 3 extra bytes at the end to allow for reading the last byte of memory as an immediate pointer + let shared_memory_size = { shared_memory.lock().unwrap().len() - 3 }; Memory { - fast_memory_size: fast_memory.len(), + fast_memory_size: fast_memory.len() - 3, fast_memory, shared_memory_size, shared_memory,