mirror of
https://github.com/mre/mos6502.git
synced 2024-11-25 02:33:26 +00:00
whitespace
This commit is contained in:
parent
153f8e4bd7
commit
3844a730f0
69
src/cpu.rs
69
src/cpu.rs
@ -567,56 +567,45 @@ impl CPU {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement binary-coded decimal
|
// TODO: Implement binary-coded decimal
|
||||||
fn subtract_with_carry(&mut self, value: i8) {
|
fn subtract_with_carry(&mut self, value: i8) {
|
||||||
if self.registers.status.contains(Status::PS_DECIMAL_MODE) {
|
// A - M - (1 - C)
|
||||||
debug!(
|
|
||||||
"binary-coded decimal not implemented for \
|
|
||||||
subtract_with_carry"
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// A - M - (1 - C)
|
|
||||||
|
|
||||||
// nc -- 'not carry'
|
// nc -- 'not carry'
|
||||||
let nc: i8 = if self.registers.status.contains(Status::PS_CARRY) {
|
let nc: i8 = if self.registers.status.contains(Status::PS_CARRY) {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
1
|
1
|
||||||
};
|
};
|
||||||
|
|
||||||
let a_before: i8 = self.registers.accumulator;
|
let a_before: i8 = self.registers.accumulator;
|
||||||
|
|
||||||
let a_after = a_before.wrapping_sub(value).wrapping_sub(nc);
|
let a_after = a_before.wrapping_sub(value).wrapping_sub(nc);
|
||||||
|
|
||||||
// The carry flag is set on unsigned overflow.
|
// The carry flag is set on unsigned overflow.
|
||||||
let did_carry = (a_after as u8) > (a_before as u8);
|
let did_carry = (a_after as u8) > (a_before as u8);
|
||||||
|
|
||||||
// The overflow flag is set on two's-complement overflow.
|
// The overflow flag is set on two's-complement overflow.
|
||||||
//
|
//
|
||||||
// range of A is -128 to 127
|
// range of A is -128 to 127
|
||||||
// range of - M - (1 - C) is -128 to 128
|
// range of - M - (1 - C) is -128 to 128
|
||||||
// -(127 + 1) to -(-128 + 0)
|
// -(127 + 1) to -(-128 + 0)
|
||||||
//
|
//
|
||||||
let over =
|
let over =
|
||||||
((nc == 0 && value < 0) || (nc == 1 && value < -1)) && a_before >= 0 && a_after < 0;
|
((nc == 0 && value < 0) || (nc == 1 && value < -1)) && a_before >= 0 && a_after < 0;
|
||||||
|
|
||||||
let under = (a_before < 0) && (-value - nc < 0) && a_after >= 0;
|
let under = (a_before < 0) && (-value - nc < 0) && a_after >= 0;
|
||||||
|
|
||||||
let did_overflow = over || under;
|
let did_overflow = over || under;
|
||||||
|
|
||||||
let mask = Status::PS_CARRY | Status::PS_OVERFLOW;
|
let mask = Status::PS_CARRY | Status::PS_OVERFLOW;
|
||||||
|
|
||||||
self.registers.status.set_with_mask(
|
self.registers.status.set_with_mask(
|
||||||
mask,
|
mask,
|
||||||
Status::new(StatusArgs {
|
Status::new(StatusArgs { carry: did_carry, overflow: did_overflow, ..StatusArgs::none() }),
|
||||||
carry: did_carry,
|
);
|
||||||
overflow: did_overflow,
|
|
||||||
..StatusArgs::none()
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
self.load_accumulator(a_after);
|
self.load_accumulator(a_after);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn decrement_memory(&mut self, addr: Address) {
|
fn decrement_memory(&mut self, addr: Address) {
|
||||||
let value_new = self.memory.get_byte(addr).wrapping_sub(1);
|
let value_new = self.memory.get_byte(addr).wrapping_sub(1);
|
||||||
|
Loading…
Reference in New Issue
Block a user