summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2024-05-18 10:31:47 +1200
committerBen Bridle <bridle.benjamin@gmail.com>2024-05-18 10:31:47 +1200
commitf3c77f5a31a3d9ba6ba559316b26e565417aa0eb (patch)
treea808408edff587e8b84fc846a2b718e2548780cb
parent8929fbc0c62db0a3ddf73c745636609f951afc20 (diff)
downloadbedrock-core-f3c77f5a31a3d9ba6ba559316b26e565417aa0eb.zip
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.
-rw-r--r--src/processor.rs2
1 files changed, 1 insertions, 1 deletions
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<D: DeviceBus> Processor<D> {
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 {