more coverage

This commit is contained in:
Trevor Merritt 2024-11-01 10:56:09 -04:00
parent 00c75a82e5
commit d2537705b7
3 changed files with 50 additions and 8 deletions

View File

@ -91,7 +91,7 @@ impl Chip8Computer {
}
pub fn step_system(&mut self) -> &mut Chip8Computer {
debug!("Stepping System 1 Step");
println!("Stepping System 1 Step");
// read the next instruction
let local_memory = &self.memory;
@ -107,6 +107,7 @@ impl Chip8Computer {
match self.state {
Chip8CpuStates::WaitingForInstruction => {
println!("Ticking sound, delay, video");
self.sound_timer.tick();
self.delay_timer.tick();
self.video_memory.tick();

View File

@ -884,9 +884,6 @@ impl Chip8CpuInstructions {
value_to_poke = (y_register - x_register) as u16;
1
};
debug!("SUB CARRY -> REGISTER 1 = [0x{x:02x}] / [{x_register}] REGISTER 2 = [0x{y:02x}] / [{y_register}] SUB = {value_to_poke} CARRY = {new_value}");
input.registers.poke(*x, value_to_poke as u8);
input.registers.poke(0xf, new_value);
}
@ -938,8 +935,11 @@ impl Chip8CpuInstructions {
// 0xBxnn Jump to Xnn+Vx
JPX(vx_register, addr) => {
let x_reg_value: u16 = input.registers.peek(*vx_register) as u16;
let new_addr = *addr + x_reg_value;
input.registers.poke_i(new_addr);
let shifted_x_reg = x_reg_value << 8;
let added_addr = shifted_x_reg | addr;
let final_addr = added_addr + shifted_x_reg;
println!("JPX -> {x_reg_value:02x} {shifted_x_reg:04x} {added_addr:04x} {final_addr:04x}");
input.registers.poke_i(final_addr);
}
Chip8CpuInstructions::RND(x, byte) => {
// Cxkk - RND Vx, byte

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);
}