1
0
mirror of https://github.com/mre/mos6502.git synced 2024-12-01 11:51:51 +00:00

Add tests for stack over- and underflow

This commit is contained in:
Sam M W 2021-01-30 15:10:41 +00:00
parent ad40c72dfe
commit 34bbe55712

View File

@ -37,6 +37,12 @@ pub struct CPU {
pub memory: Memory,
}
impl Default for CPU {
fn default() -> Self {
Self::new()
}
}
impl CPU {
pub fn new() -> CPU {
CPU {
@ -554,7 +560,14 @@ impl CPU {
let mask = Status::PS_CARRY | Status::PS_OVERFLOW;
self.registers.status.set_with_mask( mask, Status::new(StatusArgs { carry: did_carry, overflow: did_overflow, ..StatusArgs::none() }),);
self.registers.status.set_with_mask(
mask,
Status::new(StatusArgs {
carry: did_carry,
overflow: did_overflow,
..StatusArgs::none()
}),
);
self.load_accumulator(result);
@ -618,10 +631,13 @@ impl CPU {
self.registers.status.set_with_mask(
mask,
Status::new(StatusArgs { carry: did_carry, overflow: did_overflow, ..StatusArgs::none() }),
Status::new(StatusArgs {
carry: did_carry,
overflow: did_overflow,
..StatusArgs::none()
}),
);
self.load_accumulator(result);
}
@ -809,7 +825,10 @@ mod tests {
#[test]
fn decimal_subtract_test() {
let mut cpu = CPU::new();
cpu.registers.status.or(Status::PS_DECIMAL_MODE);
cpu.registers
.status
.or(Status::PS_DECIMAL_MODE | Status::PS_CARRY);
cpu.registers.accumulator = 0;
cpu.subtract_with_carry(0x48);
assert_eq!(cpu.registers.accumulator as u8, 0x52);
@ -1343,4 +1362,10 @@ mod tests {
}
}
}
#[test]
fn stack_underflow() {
let mut cpu = CPU::new();
let _val: u8 = cpu.pull_from_stack();
}
}