Fix offset to link being treated as unsigned
This commit is contained in:
parent
d361b5a090
commit
a0ca311e9a
@ -460,8 +460,8 @@ impl<T> Disasm<'_, T> {
|
|||||||
Ok(Instruction::Trap(vector))
|
Ok(Instruction::Trap(vector))
|
||||||
} else if ins_word[4..13].load_be::<u16>() == 0b1_1100_1010 {
|
} else if ins_word[4..13].load_be::<u16>() == 0b1_1100_1010 {
|
||||||
let areg = ins_word[13..16].load_be::<u8>();
|
let areg = ins_word[13..16].load_be::<u8>();
|
||||||
let displacement = self.read_immediate(Size::Word)? as u16;
|
let displacement = self.read_immediate(Size::Word)? as i16;
|
||||||
Ok(Instruction::Link { areg, displacement })
|
Ok(Instruction::Link {areg, displacement})
|
||||||
} else if ins_word[4..13].load_be::<u16>() == 0b1_1100_1011 {
|
} else if ins_word[4..13].load_be::<u16>() == 0b1_1100_1011 {
|
||||||
let dst = ins_word[13..16].load_be::<u8>();
|
let dst = ins_word[13..16].load_be::<u8>();
|
||||||
Ok(Instruction::Unlk(dst))
|
Ok(Instruction::Unlk(dst))
|
||||||
|
@ -334,7 +334,7 @@ pub enum Instruction {
|
|||||||
Trap(u8),
|
Trap(u8),
|
||||||
Link {
|
Link {
|
||||||
areg: u8,
|
areg: u8,
|
||||||
displacement: u16,
|
displacement: i16,
|
||||||
},
|
},
|
||||||
Unlk(u8),
|
Unlk(u8),
|
||||||
MoveUsp(MoveDirection, u8),
|
MoveUsp(MoveDirection, u8),
|
||||||
@ -475,7 +475,7 @@ impl Display for Instruction {
|
|||||||
Self::Tas(dst) => write!(f, "TAS {dst}"),
|
Self::Tas(dst) => write!(f, "TAS {dst}"),
|
||||||
Self::Tst(size, src) => write!(f, "TST.{size} {src}"),
|
Self::Tst(size, src) => write!(f, "TST.{size} {src}"),
|
||||||
Self::Trap(vec) => write!(f, "TRAP #{vec:#x}"),
|
Self::Trap(vec) => write!(f, "TRAP #{vec:#x}"),
|
||||||
Self::Link { areg, displacement } => write!(f, "LINK A{areg}, #{displacement:#x}"),
|
Self::Link { areg, displacement } => write!(f, "LINK A{areg}, #{displacement}"),
|
||||||
Self::Unlk(areg) => write!(f, "UNLK A{areg}"),
|
Self::Unlk(areg) => write!(f, "UNLK A{areg}"),
|
||||||
Self::MoveUsp(dir, areg) => match dir {
|
Self::MoveUsp(dir, areg) => match dir {
|
||||||
MoveDirection::MemToReg => write!(f, "MOVE USP, A{areg}"),
|
MoveDirection::MemToReg => write!(f, "MOVE USP, A{areg}"),
|
||||||
|
@ -595,9 +595,14 @@ impl M68K {
|
|||||||
self.push(dst_val, Size::Long)?;
|
self.push(dst_val, Size::Long)?;
|
||||||
let sp = self.read_effective(EffectiveAddress::AddressReg(7), Size::Long)?;
|
let sp = self.read_effective(EffectiveAddress::AddressReg(7), Size::Long)?;
|
||||||
self.write_effective(dst, sp, Size::Long)?;
|
self.write_effective(dst, sp, Size::Long)?;
|
||||||
|
let new_sp = if displacement >= 0 {
|
||||||
|
sp.wrapping_add(displacement as u32)
|
||||||
|
} else {
|
||||||
|
sp.wrapping_sub(-displacement as u32)
|
||||||
|
};
|
||||||
self.write_effective(
|
self.write_effective(
|
||||||
EffectiveAddress::AddressReg(7),
|
EffectiveAddress::AddressReg(7),
|
||||||
sp.wrapping_add(u32::from(displacement)),
|
new_sp,
|
||||||
Size::Long,
|
Size::Long,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user