summary refs log tree commit diff
path: root/src/interpreter.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/interpreter.rs')
-rw-r--r--src/interpreter.rs30
1 files changed, 7 insertions, 23 deletions
diff --git a/src/interpreter.rs b/src/interpreter.rs
index bc51754..39a33a8 100644
--- a/src/interpreter.rs
+++ b/src/interpreter.rs
@@ -1,6 +1,6 @@
 use core::panic;
 
-use crate::glk::Glk;
+use crate::{glk::Glk, instructions::Instruction};
 
 pub type MemAddress = u32;
 pub type StackAddress = u32;
@@ -18,19 +18,6 @@ enum StubDestType {
     ResumeUnicodeString = 14,
 }
 
-enum Nybble {
-    High,
-    Low,
-}
-
-enum Operand {
-    Constant(i32),
-    PopStack,
-    FrameIndirect(StackAddress),
-    MemIndirect(MemAddress),
-    MemRamIndirect(MemAddress),
-}
-
 enum ReadWriteDest {
     Stack,
     Memory,
@@ -100,11 +87,12 @@ impl Interpreter {
         self.reg_program = self.create_stack_frame(entry_func, Vec::new());
 
         loop {
-            let instruction = self.load_program_instruction();
+            let pc = self.reg_program as usize;
+            let mut instruction_slice = &self.memory[pc..pc+100];
+            let (instruction, bytes_read) = Instruction::read(&mut instruction_slice);
+            self.reg_program += bytes_read;
 
-            match instruction {
-                _ => todo!("Haven't done any of the instruction loading yet")
-            }
+            println!("Parsed instruction {instruction:?}");
         }
     }
 
@@ -144,7 +132,7 @@ impl Interpreter {
             format_of_locals.push(format);
         };
 
-        let opcode_start = local_pointer + 1;
+        let opcode_start = local_pointer + 2;
 
         // Writing stack frame
         self.reg_frame = self.reg_stack;
@@ -214,10 +202,6 @@ impl Interpreter {
         return opcode_start;
     }
 
-    fn load_program_instruction(&mut self) {
-
-    }
-
     fn push_stack(&mut self, value: u32) {
         self.write_word(self.reg_stack, ReadWriteDest::Stack, value);
         self.reg_stack += 4;