more roms

This commit is contained in:
2024-10-14 12:13:33 -04:00
parent 683b0fc51a
commit 5e290d825b
27 changed files with 64 additions and 47 deletions
+1
View File
@@ -96,6 +96,7 @@ impl Chip8Computer {
Chip8CpuStates::WaitingForInstruction => {
self.sound_timer.tick();
self.delay_timer.tick();
self.video_memory.tick();
}
Chip8CpuStates::WaitingForKey => {
println!("waiting for a key press...");
+1 -1
View File
@@ -695,7 +695,7 @@ impl Chip8CpuInstructions {
debug!("PPOOSSTT -> CHIP8CPUINSTRUCTION:DRAWVXNIBBLE -> {}", input.video_memory.format_as_string());
let mut did_change: bool = false;
let mut did_change: bool = input.video_memory.has_frame_changed;
if did_change {
input.registers.poke(0xf, 1u8);
+41 -10
View File
@@ -42,22 +42,22 @@ impl Chip8Video {
}
pub fn poke(&mut self, address: u16, new_value: bool) -> Self {
trace!("OFFSET: {address} - POKING {new_value}");
// println!("OFFSET: {address} - POKING {new_value}");
// Loop the address
let effective_address = if address >= 2048 {
address - 2048
} else {
address
};
let old_value = self.memory[effective_address as usize];
let value_to_poke = new_value ^ old_value;
if old_value != value_to_poke {
trace!("**VIDEO** TOGGLING");
self.has_frame_changed = true;
} else {
trace!("NOT TOGGLING");
}
self.memory[effective_address as usize] = new_value ^ old_value;
let old_value = self.memory[effective_address as usize];
let xored_value = new_value ^ old_value; // XOR of the video
let value_changed = old_value != xored_value; // From True to False is a change.
self.has_frame_changed = if xored_value && value_changed { false } else { true };
self.memory[effective_address as usize] = xored_value;
self.to_owned()
}
@@ -369,6 +369,7 @@ mod test {
fn verify_change_registered() {
let mut v = Chip8Video::default();
v.poke(0x01, true);
v.poke(0x01, true);
assert!(v.has_frame_changed);
v.start_frame();
@@ -423,4 +424,34 @@ mod test {
x = x.reset();
assert_eq!(x.format_as_string(), read_test_result("test_reset_clears_video.asc"));
}
#[test]
fn collision_test() {
// Setup: Set 0xFF to 0x00 with a new frame ready
// Action: Run Poke to the same area
// Test: Verify the 'changed' flag is tripped
let mut x = Chip8Video::default();
x.poke_byte(0x00, 0xff);
x.tick();
// set the cell thats already set...
x.poke(0x00, true);
// it becomes unset and theres a frame changed
assert_eq!(false, x.peek(0x00));
assert_eq!(true, x.has_frame_changed);
}
#[test]
fn collision_test2() {
let mut x = Chip8Video::default();
x.poke_byte(0x00, 0b11110000);
assert_eq!(true, x.has_frame_changed);
x.tick();
assert_eq!(false, x.has_frame_changed);
// clear the 'has changed' flag
// now set a no-collision value
x.poke_byte(0x00, 0b00001111);
assert_eq!(false, x.has_frame_changed);
}
}