add option to statically disable decimal mode (#47)

* add the decimal mode feature to `Cargo.toml`
* add tests for disabled decimal mode to github workflows
* don't run decimal mode tests if decimal mode disabled

Co-authored-by: Sam M W <you@example.com>
This commit is contained in:
omarandlorraine 2022-08-11 14:42:34 +01:00 committed by GitHub
parent 18e55aaeca
commit f3d3bf470f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 2 deletions

View File

@ -33,3 +33,8 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
- name: Run tests with disabled decimal mode
uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features

View File

@ -54,3 +54,7 @@ skeptic = "0.13.7"
[dev-dependencies]
skeptic = "0.13.7"
[features]
decimal_mode = []
default = ["decimal_mode"]

View File

@ -546,12 +546,16 @@ impl CPU {
0x00
};
#[cfg(feature = "decimal_mode")]
let result: i8 = if self.registers.status.contains(Status::PS_DECIMAL_MODE) {
a_after.wrapping_add(bcd1).wrapping_add(bcd2)
} else {
a_after
};
#[cfg(not(feature = "decimal_mode"))]
let result: i8 = a_after;
let did_carry = (result as u8) < (a_before as u8) || (c_before == 1 && value == -1);
let did_overflow = (a_before < 0 && value < 0 && a_after >= 0)
@ -619,12 +623,16 @@ impl CPU {
0x00
};
#[cfg(feature = "decimal_mode")]
let result: i8 = if self.registers.status.contains(Status::PS_DECIMAL_MODE) {
a_after.wrapping_sub(bcd1).wrapping_sub(bcd2)
} else {
a_after
};
#[cfg(not(feature = "decimal_mode"))]
let result: i8 = a_after;
// The carry flag is set on unsigned overflow.
let did_carry = (result as u8) > (a_before as u8);
@ -794,7 +802,7 @@ mod tests {
use super::*;
use num::range_inclusive;
#[test]
#[cfg_attr(feature = "decimal_mode", test)]
fn decimal_add_test() {
let mut cpu = CPU::new();
cpu.registers.status.or(Status::PS_DECIMAL_MODE);
@ -821,7 +829,7 @@ mod tests {
assert!(cpu.registers.status.contains(Status::PS_OVERFLOW));
}
#[test]
#[cfg_attr(feature = "decimal_mode", test)]
fn decimal_subtract_test() {
let mut cpu = CPU::new();
cpu.registers