summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core.rs42
-rw-r--r--src/decode.rs1
-rw-r--r--src/instructions.rs2
3 files changed, 44 insertions, 1 deletions
diff --git a/src/core.rs b/src/core.rs
index fdaeafb..5a0cbe5 100644
--- a/src/core.rs
+++ b/src/core.rs
@@ -1,5 +1,7 @@
use crate::{
consts::{Addr, RegId, RegValue},
+ decode::Instruction,
+ instructions::find_runner,
mem::MemConfig,
};
@@ -27,6 +29,46 @@ impl Core {
}
}
+ pub fn run(&mut self) {
+ loop {
+ let page = (self.pc / 4096) as usize;
+ let offset = (self.pc / 4) as u16;
+ if !self.pc.is_multiple_of(4) {
+ //replace eprint with logging, replace break with exception
+ eprintln!("PC not aligned");
+ break;
+ }
+
+ let instr = match self.mem.read_word(page, offset) {
+ Ok(i) => i,
+ Err(_) => {
+ eprintln!("Memory access fault while fetching instruction");
+ break;
+ }
+ };
+
+ let instr = Instruction(instr);
+
+ let runner = find_runner(instr);
+
+ if let Some(runner) = runner {
+ let res = runner(self, instr);
+
+ match res {
+ InstructionResult::Normal => {}
+ InstructionResult::Exception(_e) => {
+ eprintln!("Exception from instruction");
+ break;
+ }
+ InstructionResult::Pause => {
+ eprintln!("Instruction asked for pause");
+ break;
+ }
+ }
+ }
+ }
+ }
+
pub fn reset(&mut self, pc: Addr) {
self.pc = pc;
}
diff --git a/src/decode.rs b/src/decode.rs
index 0da4513..409aedb 100644
--- a/src/decode.rs
+++ b/src/decode.rs
@@ -2,6 +2,7 @@ use crate::consts::{DWord, RegId, Word};
const MASK_REGISTER: Word = 0x1f;
+#[derive(Debug, Clone, Copy)]
pub struct Instruction(pub Word);
impl Instruction {
diff --git a/src/instructions.rs b/src/instructions.rs
index e16894e..ed264f9 100644
--- a/src/instructions.rs
+++ b/src/instructions.rs
@@ -12,7 +12,7 @@ use crate::{
decode::Instruction,
};
-type Runner = fn(&mut Core, Instruction) -> Result<(), InstructionResult>;
+type Runner = fn(&mut Core, Instruction) -> InstructionResult;
#[derive(Clone, Copy)]
struct InstructionHandler {