emu: use wrapping_add in displacement address as operand can be neg

This commit is contained in:
2021-03-18 01:43:22 -07:00
parent 73c537183e
commit d6e645cae7

View File

@@ -133,19 +133,23 @@ macro_rules! step {
(@displace8=($reg1:ident $(+ $reg2:ident)? ) $cookie:tt, $cpu:expr, $bus:expr,
($segment:ident, $repeat:ident, $prefix_loop:lifetime),
$modrm:tt) => { {
let d8 = i8088::next_ip($cpu.cs.get(), &mut $cpu.ip, $bus);
let rel8 = i8088::next_ip($cpu.cs.get(), &mut $cpu.ip, $bus) as i8 as u16;
step!(@arg $cookie, &mut FarPtr { bus: $bus,
segment: $segment.unwrap(),
offset: $cpu.$reg1.get() $(+ $cpu.$reg2.get())? + d8 as u16 })
offset: ($cpu.$reg1.get() $(+ $cpu.$reg2.get())?)
.wrapping_add(rel8)
})
} };
(@displace16=($reg1:ident $(+ $reg2:ident)? ) $cookie:tt, $cpu:expr, $bus:expr,
($segment:ident, $repeat:ident, $prefix_loop:lifetime),
$modrm:tt) => { {
let d16 = i8088::next_ip16($cpu.cs.get(), &mut $cpu.ip, $bus);
let rel16 = i8088::next_ip16($cpu.cs.get(), &mut $cpu.ip, $bus);
step!(@arg $cookie, &mut FarPtr { bus: $bus,
segment: $segment.unwrap(),
offset: $cpu.$reg1.get() $(+ $cpu.$reg2.get())? + d16 })
offset: ($cpu.$reg1.get() $(+ $cpu.$reg2.get())?)
.wrapping_add(rel16)
})
} };
(@flags $cookie:tt, $cpu:expr, $bus:expr, $prefix:tt, $modrm:tt) => {