summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/luma.rs8
-rw-r--r--src/luma/application/decode.rs8
-rw-r--r--src/luma/application/read.rs10
-rw-r--r--src/luma/application/trap.rs8
4 files changed, 17 insertions, 17 deletions
diff --git a/src/luma.rs b/src/luma.rs
index 4be467a..88eb255 100644
--- a/src/luma.rs
+++ b/src/luma.rs
@@ -10,13 +10,13 @@ pub struct VersionType<T> {
pub const VERSION: VersionType::<u32> = VersionType::<u32> {
major: 0x0,
- minor: 0x22,
+ minor: 0x23,
};
pub enum TrapKind {
- BadAlignment,
- InvalidOpcode,
- OutOfBounds,
+ BadAlignment( u32, u32),
+ InvalidOpcode(u32, u32),
+ OutOfBounds( u32),
}
pub const CONFIGURATION_VERSION: u32 = 0x0;
diff --git a/src/luma/application/decode.rs b/src/luma/application/decode.rs
index 2c18ab1..fb57e44 100644
--- a/src/luma/application/decode.rs
+++ b/src/luma/application/decode.rs
@@ -21,9 +21,9 @@ impl Application {
0b11000000000000000000000000000 => self.psr & 0b01000000000000000000000000000000 == 0x00 && self.psr & 0b00010000000000000000000000000000 >> 0x1C == self.psr & 0b10000000000000000000000000000000 >> 0x1F,
0b11010000000000000000000000000 => self.psr & 0b01000000000000000000000000000000 != 0x00 || self.psr & 0b00010000000000000000000000000000 >> 0x1C != self.psr & 0b10000000000000000000000000000000 >> 0x1F,
0b11100000000000000000000000000 => true,
- _ => { self.trap(TrapKind::InvalidOpcode, Some(self.registers[0xF] - 0x8), Some(opcode), None); false },
+ _ => { self.trap(TrapKind::InvalidOpcode(self.registers[0xF] - 0x8, opcode)); false },
};
- if !condition { return };
+ if !condition { return }
if opcode & 0b00001110000000000000000000000000 == 0b00001010000000000000000000000000 {
let off = opcode & 0b00000000111111111111111111111111; // Offset from pc.
@@ -39,10 +39,10 @@ impl Application {
true => self.registers[0xF] - inv * 0x4 + 0x8,
};
- eprintln!("branch: {:024b} => {:08X}", off, self.registers[0xF] - 0x8);
+ eprintln!("branch: {off:024b} => {:08X}", self.registers[0xF] - 0x8);
return;
}
- self.trap(TrapKind::InvalidOpcode, Some(self.registers[0xF] - 0x8), Some(opcode), None);
+ self.trap(TrapKind::InvalidOpcode(self.registers[0xF] - 0x8, opcode));
}
}
diff --git a/src/luma/application/read.rs b/src/luma/application/read.rs
index ac1b4aa..06003b7 100644
--- a/src/luma/application/read.rs
+++ b/src/luma/application/read.rs
@@ -6,23 +6,23 @@ use crate::luma::{MEMORY_SIZE, TrapKind};
impl Application {
#[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) };
+ if address >= MEMORY_SIZE as u32 { self.trap(TrapKind::OutOfBounds(address)) };
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)) };
+ if address >= MEMORY_SIZE as u32 { self.trap(TrapKind::OutOfBounds(address)) };
+ if address % 0x2 != 0x0 { self.trap(TrapKind::BadAlignment(address, 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)) };
+ if address >= MEMORY_SIZE as u32 { self.trap(TrapKind::OutOfBounds(address)) };
+ if address % 0x4 != 0x0 { self.trap(TrapKind::BadAlignment(address, 0x4)) };
return unsafe { *(self.memory.offset(address as isize) as *mut u32) };
}
diff --git a/src/luma/application/trap.rs b/src/luma/application/trap.rs
index 7b7adbf..1d38610 100644
--- a/src/luma/application/trap.rs
+++ b/src/luma/application/trap.rs
@@ -4,11 +4,11 @@ use crate::luma::{MEMORY_SIZE, TrapKind};
use crate::luma::application::Application;
impl Application {
- pub fn trap(&mut self, kind: TrapKind, address: Option<u32>, opcode: Option<u32>, alignment: Option<u32>) {
+ pub fn trap(&mut self, kind: TrapKind) {
let message = match kind {
- TrapKind::BadAlignment => format!("bad alignment of address 0x{:08X} (should be {}-byte aligned)", address.unwrap(), alignment.unwrap()),
- TrapKind::InvalidOpcode => format!("invalid opcode 0x{:08X} at 0x{:08X}", opcode.unwrap(), address.unwrap()),
- TrapKind::OutOfBounds => format!("out-of-bounds address 0x{:08X} (limit is 0x{MEMORY_SIZE:08X})", address.unwrap()),
+ TrapKind::BadAlignment( address, alignment) => format!("bad alignment of address 0x{address:08X} (should be {alignment}-byte aligned)"),
+ TrapKind::InvalidOpcode(address, opcode) => format!("invalid opcode 0x{opcode:08X} at 0x{address:08X}"),
+ TrapKind::OutOfBounds( address) => format!("out-of-bounds address 0x{address:08X} (limit is 0x{MEMORY_SIZE:08X})"),
};
eprintln!("trap - {message}");