chore(interpreter): fix small bugs
This commit is contained in:
@@ -49,7 +49,7 @@ impl Computer {
|
|||||||
let op: fn(Lhs, Rhs) -> ArithmeticResult = |lhs, rhs| lhs + rhs;
|
let op: fn(Lhs, Rhs) -> ArithmeticResult = |lhs, rhs| lhs + rhs;
|
||||||
let flag_set: fn(&mut Flags, ArithmeticResult, Lhs, Rhs) = |flags, result, lhs, rhs| {
|
let flag_set: fn(&mut Flags, ArithmeticResult, Lhs, Rhs) = |flags, result, lhs, rhs| {
|
||||||
flags.cf = result < 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.zf = result.zero();
|
||||||
flags.sf = result.msb();
|
flags.sf = result.msb();
|
||||||
flags.pf = result.parity();
|
flags.pf = result.parity();
|
||||||
|
|||||||
@@ -427,14 +427,21 @@ impl Interpreter {
|
|||||||
},
|
},
|
||||||
Mnemonic::CALL_p(_) => todo!(),
|
Mnemonic::CALL_p(_) => todo!(),
|
||||||
Mnemonic::CALL_v(offset) => {
|
Mnemonic::CALL_v(offset) => {
|
||||||
// save next instruction onto stack for later RET
|
|
||||||
if let Some(next_instr) = ip.next() {
|
if let Some(next_instr) = ip.next() {
|
||||||
self.computer.push_stack(next_instr.start.into())?;
|
self.computer.push_stack(next_instr.start.into())?;
|
||||||
}
|
}
|
||||||
// jump to target
|
|
||||||
Self::ip_jump(&self.instructions, &mut ip, offset);
|
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!(),
|
Mnemonic::CALL_Mp(_) => todo!(),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ impl Register {
|
|||||||
bx: BX::new(),
|
bx: BX::new(),
|
||||||
cx: CX::new(),
|
cx: CX::new(),
|
||||||
dx: DX::new(),
|
dx: DX::new(),
|
||||||
sp: 0xffff,
|
sp: 0xffda,
|
||||||
bp: 0,
|
bp: 0,
|
||||||
si: 0,
|
si: 0,
|
||||||
di: 0,
|
di: 0,
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ impl From<usize> for ImmediateOperand {
|
|||||||
impl Into<Word> for ImmediateOperand {
|
impl Into<Word> for ImmediateOperand {
|
||||||
fn into(self) -> u16 {
|
fn into(self) -> u16 {
|
||||||
match self {
|
match self {
|
||||||
ImmediateOperand::Byte(_) => self.sign_extend().into(),
|
ImmediateOperand::Byte(b) => b as Word,
|
||||||
ImmediateOperand::Word(w) => w,
|
ImmediateOperand::Word(w) => w,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user