diff --git a/src/instructions.rs b/src/instructions.rs index 1595697..fa84432 100644 --- a/src/instructions.rs +++ b/src/instructions.rs @@ -202,14 +202,14 @@ pub enum Mnemonic { CBW, CWD, // CALL - CALL_p(Pointer32), - CALL_v(usize), - CALL_Mod(ModRmTarget), - CALL_Mp(Pointer16), + CALL_p(Pointer32), // 0x9A + CALL_v(usize), // 0xE8 + CALL_Mod(ModRmTarget), // 0xFF 2 + CALL_Mp(Pointer16), // 0xFF 3 // JUMP JMP_p(Pointer32), - JMP_b(usize), // parses IByte, but stores as isize - JMP_v(usize), // parwses IWord, but stores as isize + JMP_b(usize), + JMP_v(usize), JMP_Mod(ModRmTarget), JMP_Mp(Pointer16), // WAIT diff --git a/src/interpreter/interpreter.rs b/src/interpreter/interpreter.rs index 077a634..aacacc4 100644 --- a/src/interpreter/interpreter.rs +++ b/src/interpreter/interpreter.rs @@ -1,5 +1,5 @@ use core::fmt; -use std::{fmt::Debug, process::exit}; +use std::{env::current_dir, fmt::Debug, process::exit}; use crate::{ instructions::{Instruction, Mnemonic}, @@ -413,6 +413,17 @@ impl Interpreter { self.computer.regs.read(register).into(), ), }, + Mnemonic::CALL_p(_) => todo!(), + Mnemonic::CALL_v(offset) => { + // save next instruction onto stack for later RET + if let Some(next_instr) = ip.next() { + self.computer.push_stack(next_instr.start.into())?; + } + // jump to target + Self::ip_jump(&self.instructions, &mut ip, offset); + } + Mnemonic::CALL_Mod(_) => todo!(), + Mnemonic::CALL_Mp(_) => todo!(), /* * Test diff --git a/src/operands.rs b/src/operands.rs index 4819b43..01de654 100644 --- a/src/operands.rs +++ b/src/operands.rs @@ -110,6 +110,16 @@ impl From for ImmediateOperand { } } +impl From for ImmediateOperand { + fn from(value: usize) -> Self { + if value > Word::MAX as usize { + panic!("Cannot convert usize to ImmediateOperand::Word") + } else { + ImmediateOperand::Word(value as Word) + } + } +} + impl Into for ImmediateOperand { fn into(self) -> u16 { match self {