ft(interpreter): impl shift and rotate
This commit is contained in:
@@ -235,6 +235,47 @@ impl Computer {
|
||||
ModRmTarget::Register(reg) => self.regs.read(reg),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rotate(
|
||||
&mut self,
|
||||
target: ModRmTarget,
|
||||
rotations: usize, // how many rotations
|
||||
carry_usage: CarryUsage, // if carry should be included, or should just receive a copy
|
||||
rotation_direction: RotationDirection, // direction of rotation
|
||||
) {
|
||||
let mut bits = self.read_modrm(target).bits();
|
||||
match carry_usage {
|
||||
CarryUsage::FullRotation => bits.push(self.flags.cf),
|
||||
_ => {}
|
||||
}
|
||||
match rotation_direction {
|
||||
RotationDirection::Left => {
|
||||
bits.rotate_left(rotations);
|
||||
match carry_usage {
|
||||
CarryUsage::ReceiveCopy => self.flags.cf = bits[7],
|
||||
CarryUsage::FullRotation => self.flags.cf = bits.pop().unwrap(),
|
||||
}
|
||||
}
|
||||
RotationDirection::Right => {
|
||||
bits.rotate_right(rotations);
|
||||
match carry_usage {
|
||||
CarryUsage::ReceiveCopy => self.flags.cf = bits[0],
|
||||
CarryUsage::FullRotation => self.flags.cf = bits.pop().unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
self.write_modrm(target, ImmediateOperand::from(bits));
|
||||
}
|
||||
}
|
||||
|
||||
pub enum RotationDirection {
|
||||
Left,
|
||||
Right,
|
||||
}
|
||||
|
||||
pub enum CarryUsage {
|
||||
ReceiveCopy, // dont add when rotating, but copy bit that was rotated to other side
|
||||
FullRotation, // include in full rotation
|
||||
}
|
||||
|
||||
impl fmt::Display for Computer {
|
||||
|
||||
Reference in New Issue
Block a user