diff --git a/src/interpreter/computer.rs b/src/interpreter/computer.rs index 07042b6..6dbda18 100644 --- a/src/interpreter/computer.rs +++ b/src/interpreter/computer.rs @@ -49,7 +49,7 @@ impl Computer { let op: fn(Lhs, Rhs) -> ArithmeticResult = |lhs, rhs| lhs + rhs; let flag_set: fn(&mut Flags, ArithmeticResult, Lhs, Rhs) = |flags, result, lhs, rhs| { flags.cf = result < rhs; - flags.of = lhs.msb() && rhs.msb() != result.msb(); + flags.of = (lhs.msb() && rhs.msb()) && (result.msb() != lhs.msb()); flags.zf = result.zero(); flags.sf = result.msb(); flags.pf = result.parity(); diff --git a/src/interpreter/interpreter.rs b/src/interpreter/interpreter.rs index 88aa355..bc1aa61 100644 --- a/src/interpreter/interpreter.rs +++ b/src/interpreter/interpreter.rs @@ -427,14 +427,21 @@ impl Interpreter { }, 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_Mod(target) => { + if let Some(next_instr) = ip.next() { + self.computer.push_stack(next_instr.start.into())?; + } + Self::ip_jump( + &self.instructions, + &mut ip, + self.computer.read_modrm(target).into(), + ); + } Mnemonic::CALL_Mp(_) => todo!(), /* diff --git a/src/interpreter/register.rs b/src/interpreter/register.rs index be2f08d..38385e1 100644 --- a/src/interpreter/register.rs +++ b/src/interpreter/register.rs @@ -22,7 +22,7 @@ impl Register { bx: BX::new(), cx: CX::new(), dx: DX::new(), - sp: 0xffff, + sp: 0xffda, bp: 0, si: 0, di: 0, diff --git a/src/operands.rs b/src/operands.rs index c3091fe..e506b37 100644 --- a/src/operands.rs +++ b/src/operands.rs @@ -151,7 +151,7 @@ impl From for ImmediateOperand { impl Into for ImmediateOperand { fn into(self) -> u16 { match self { - ImmediateOperand::Byte(_) => self.sign_extend().into(), + ImmediateOperand::Byte(b) => b as Word, ImmediateOperand::Word(w) => w, } }