more coverage

This commit is contained in:
2024-11-01 10:56:09 -04:00
parent 00c75a82e5
commit d2537705b7
3 changed files with 50 additions and 8 deletions
+43 -2
View File
@@ -1,6 +1,7 @@
use log::debug;
use rand::random;
use gemma::chip8::computer::Chip8Computer;
use gemma::chip8::cpu_states::Chip8CpuStates::WaitingForInstruction;
use gemma::chip8::delay_timer::DelayTimer;
use gemma::chip8::instructions::Chip8CpuInstructions;
use gemma::chip8::instructions::Chip8CpuInstructions::JPX;
@@ -9,6 +10,7 @@ use gemma::chip8::quirk_modes::QuirkMode::{Chip8, SChipModern, XOChip};
use gemma::chip8::registers::Chip8Registers;
use gemma::chip8::sound_timer::SoundTimer;
use gemma::chip8::stack::Chip8Stack;
use gemma::chip8::system_memory::Chip8SystemMemory;
use gemma::chip8::util::InstructionUtil;
use gemma::chip8::video::{Chip8Video, Chip8VideoModes};
use gemma::constants::*;
@@ -1358,7 +1360,46 @@ fn instruction_jpx() {
x.registers.poke(0x01, 0x04);
// ...use (x1)+0x134
let to_execute = JPX(0x01, 0x34);
// expect to set PC to 0x524
// expect to set PC to 0x834
to_execute.execute(&mut x);
assert_eq!(x.registers.peek_pc(), 0x524);
assert_eq!(x.registers.peek_i(), 0x834);
}
#[test]
fn instruction_ldrd() {
let mut x = Chip8Computer::new();
x.state = WaitingForInstruction;
x.delay_timer.set_timer(0x01);
Chip8CpuInstructions::LDRD(0x01).execute(&mut x);
assert_eq!(x.registers.peek(0x01), 0x01);
x.delay_timer.set_timer(0xff);
Chip8CpuInstructions::LDRD(0x0).execute(&mut x);
assert_eq!(x.registers.peek(0x00), 0xff);
x.step_system();
x.step_system();
x.step_system();
x.step_system();
Chip8CpuInstructions::LDRD(0x0).execute(&mut x);
assert_eq!(x.registers.peek(0x0), 0xfb);
}
#[test]
fn video_hires_loop_check() {
let max_address = SCHIP_VIDE_MEMORY;
let x = build_checkboard_hd();
x.peek((max_address + 1) as u16);
// if we got here we didn't explode!
assert!(true);
}
#[test]
fn sound_timer_default() {
let x = SoundTimer::default();
assert_eq!(x.current(), 0);
}
#[test]
fn system_memory_new() {
let x = Chip8SystemMemory::new();
assert!(true);
}