mirror of
https://github.com/mre/mos6502.git
synced 2024-11-24 11:31:00 +00:00
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:
parent
18e55aaeca
commit
f3d3bf470f
5
.github/workflows/ci.yaml
vendored
5
.github/workflows/ci.yaml
vendored
@ -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
|
||||
|
@ -54,3 +54,7 @@ skeptic = "0.13.7"
|
||||
|
||||
[dev-dependencies]
|
||||
skeptic = "0.13.7"
|
||||
|
||||
[features]
|
||||
decimal_mode = []
|
||||
default = ["decimal_mode"]
|
||||
|
12
src/cpu.rs
12
src/cpu.rs
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user