diff options
Diffstat (limited to 'src/luma/emulator/read.rs')
-rw-r--r-- | src/luma/emulator/read.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/luma/emulator/read.rs b/src/luma/emulator/read.rs new file mode 100644 index 0000000..f374e4d --- /dev/null +++ b/src/luma/emulator/read.rs @@ -0,0 +1,29 @@ +// Copyright 2021-2023 Gabriel Jensen. + +use crate::luma::MEMORY_SIZE; +use crate::luma::emulator::{Emulator, TrapKind}; + +impl Emulator { + #[allow(dead_code)] + pub fn read_byte(&mut self, address: u32) -> u8 { + if address >= MEMORY_SIZE as u32 { self.trap(TrapKind::OutOfBounds, Some(address), None, None) }; + + return unsafe { *(self.memory.offset(address as isize) as *mut u8) }; + } + + #[allow(dead_code)] + pub fn read_halfword(&mut self, address: u32) -> u16 { + if address >= MEMORY_SIZE as u32 { self.trap(TrapKind::OutOfBounds, Some(address), None, None) }; + if address % 0x2 != 0x0 { self.trap(TrapKind::BadAlignment, Some(address), None, Some(0x2)) }; + + return unsafe { *(self.memory.offset(address as isize) as *mut u16) }; + } + + #[allow(dead_code)] + pub fn read_word(&mut self, address: u32) -> u32 { + if address >= MEMORY_SIZE as u32 { self.trap(TrapKind::OutOfBounds, Some(address), None, None) }; + if address % 0x4 != 0x0 { self.trap(TrapKind::BadAlignment, Some(address), None, Some(0x4)) }; + + return unsafe { *(self.memory.offset(address as isize) as *mut u32) }; + } +} |