add test for fetch instruction, handle timers & fix handle timers
This commit is contained in:
parent
baf2f50406
commit
ebe913ec61
1 changed files with 32 additions and 2 deletions
|
@ -168,8 +168,8 @@ where
|
||||||
if self.delay_timer > 0 {
|
if self.delay_timer > 0 {
|
||||||
self.delay_timer -= 1
|
self.delay_timer -= 1
|
||||||
}
|
}
|
||||||
if self.delay_timer > 0 {
|
if self.sound_timer > 0 {
|
||||||
self.delay_timer -= 1
|
self.sound_timer -= 1
|
||||||
} else {
|
} else {
|
||||||
self.do_beep()
|
self.do_beep()
|
||||||
}
|
}
|
||||||
|
@ -996,4 +996,34 @@ mod tests {
|
||||||
|
|
||||||
assert_eq!(emulator.registers[0xA], 0xEF);
|
assert_eq!(emulator.registers[0xA], 0xEF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_fetch_instruction() {
|
||||||
|
let mut emulator = Emulator::new(TerminalDisplay::new(), TerminalSound, NoInput);
|
||||||
|
emulator.program_counter = 0x200;
|
||||||
|
emulator.memory[0x200] = 0x00;
|
||||||
|
emulator.memory[0x201] = 0xEE;
|
||||||
|
|
||||||
|
let instruction = emulator.fetch_instruction();
|
||||||
|
match instruction {
|
||||||
|
Ok(instruction) => {
|
||||||
|
assert_eq!(instruction, 0x00EE);
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
assert!(false, "Did not fetch");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_handle_timers() {
|
||||||
|
let mut emulator = Emulator::new(TerminalDisplay::new(), TerminalSound, NoInput);
|
||||||
|
emulator.sound_timer = 10;
|
||||||
|
emulator.delay_timer = 12;
|
||||||
|
|
||||||
|
emulator.handle_timers();
|
||||||
|
|
||||||
|
assert_eq!(emulator.sound_timer, 9);
|
||||||
|
assert_eq!(emulator.delay_timer, 11);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue