From f3c77f5a31a3d9ba6ba559316b26e565417aa0eb Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Sat, 18 May 2024 10:31:47 +1200 Subject: Fix SHF instruction The wrong shifting operation was being used for the SHF operation. The 'wrapping' operations were shifting by the given distance, modulo eight, which was yielding incorrect results for shift distances greater than seven. --- src/processor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/processor.rs b/src/processor.rs index cb1b2d5..9c9fb45 100644 --- a/src/processor.rs +++ b/src/processor.rs @@ -47,7 +47,7 @@ impl Processor { macro_rules! pc { () => { self.mem.read_pc() }; } macro_rules! truth { ($x:expr) => { if $x {0xff} else {0x00} }; } macro_rules! nyb { ($v:expr=>$h:ident,$l:ident) => { let $h=($v>>4); let $l=($v&0x0f); } } - macro_rules! shf { ($x:expr,$y:expr) => { { nyb!($y=>l,r); $x.wrapping_shl(l as u32).wrapping_shr(r as u32) } } ; } + macro_rules! shf { ($x:expr,$y:expr) => { { nyb!($y=>l,r); $x.checked_shl(l as u32).unwrap_or(0).checked_shr(r as u32).unwrap_or(0) } } ; } macro_rules! shc { ($x:expr,$y:expr) => { { nyb!($y=>l,r); $x.rotate_left( l as u32).rotate_right(r as u32) } }; } for _ in 0..num_cycles { -- cgit v1.2.3-70-g09d2