From f5cebaf8feed5f5980df63a6c5b6a64d5d5ba092 Mon Sep 17 00:00:00 2001 From: Ashelyn Rose Date: Fri, 6 Dec 2024 15:10:31 -0700 Subject: Instruction parsing --- src/interpreter.rs | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) (limited to 'src/interpreter.rs') 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; -- cgit 1.4.1