summaryrefslogtreecommitdiff
path: root/src/devices/math.rs
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2024-04-16 10:51:13 +1200
committerBen Bridle <bridle.benjamin@gmail.com>2024-04-16 10:51:26 +1200
commit6b3796c9a0d3a2f1422bcbde4790c43417659722 (patch)
tree6429a5fa2f8c4d3b26790775e07e46e6338b61d3 /src/devices/math.rs
parent28101de56231252ca0cfa6a9f107b75112c9acad (diff)
downloadbedrock-pc-6b3796c9a0d3a2f1422bcbde4790c43417659722.zip
Update devices to match new specifications
Diffstat (limited to 'src/devices/math.rs')
-rw-r--r--src/devices/math.rs28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/devices/math.rs b/src/devices/math.rs
index c8d2194..cefb572 100644
--- a/src/devices/math.rs
+++ b/src/devices/math.rs
@@ -1,10 +1,6 @@
pub struct MathDevice {
pub operand_1: u16,
pub operand_2: u16,
- pub product_high: u16,
- pub product_low: u16,
- pub quotient: u16,
- pub remainder: u16,
}
impl MathDevice {
@@ -12,24 +8,24 @@ impl MathDevice {
Self {
operand_1: 0x0000,
operand_2: 0x0000,
- product_high: 0x0000,
- product_low: 0x0000,
- quotient: 0x0000,
- remainder: 0x0000,
}
}
- pub fn multiply(&mut self) {
- let (low, high) = self.operand_1.widening_mul(self.operand_2);
- self.product_high = high;
- self.product_low = low;
+ pub fn multiply_high(&mut self) -> u16 {
+ let (_, high) = self.operand_1.widening_mul(self.operand_2);
+ return high;
}
- pub fn divide(&mut self) {
- self.quotient = self.operand_1.checked_div(self.operand_2).unwrap_or(0);
+ pub fn multiply_low(&mut self) -> u16 {
+ let (low, _) = self.operand_1.widening_mul(self.operand_2);
+ return low;
}
- pub fn modulo(&mut self) {
- self.remainder = self.operand_1.checked_rem(self.operand_2).unwrap_or(0);
+ pub fn divide(&mut self) -> u16 {
+ self.operand_1.checked_div(self.operand_2).unwrap_or(0)
+ }
+
+ pub fn modulo(&mut self) -> u16 {
+ self.operand_1.checked_rem(self.operand_2).unwrap_or(0)
}
}