more validation tests for gemma video rendering

Adds 'doom like' 3dviprmaze-vip for demo (VERY VERY SLOW)
updates egui interface to let user select from files in resources/roms
updates cargo to centralize dependencies
95 passing tests
This commit is contained in:
2024-10-16 10:02:24 -04:00
parent 939fd83e80
commit b4b8bfb24b
21 changed files with 404 additions and 131 deletions
+13 -10
View File
@@ -58,14 +58,15 @@ impl Chip8Computer {
self.video_memory.format_as_string()
}
pub fn new_with_program(new_program: Box<Vec<u16>>) -> Self {
pub fn new_with_program(new_program: Vec<u16>) -> Self {
let mut working = Chip8Computer::new();
for i in 0..new_program.len() {
let high_byte = (new_program[i as usize] >> 8) as u8;
let low_byte = (new_program[i] & 0xff) as u8;
let base_offset = i * 2;
working.memory.poke(base_offset as u16, high_byte);
working.memory.poke((base_offset + 1) as u16, low_byte);
for (i, &word) in new_program.iter().enumerate() {
let high = (word >> 8) as u8;
let low = (word & 0xff) as u8;
let base_offset = (i * 2) as u16;
working.memory.poke(base_offset, high);
working.memory.poke(base_offset + 1, low);
}
working
}
@@ -85,11 +86,12 @@ impl Chip8Computer {
pub fn step_system(&mut self) -> &mut Chip8Computer {
debug!("Stepping System 1 Step");
// read the next instruction
let local_memory = &self.memory;
// let mut working_instruction: u16 = 0b0000000000000000;
let start_pc = self.registers.peek_pc();
let high_byte = (self.memory.clone().peek(start_pc) as u16).rotate_left(8);
let low_byte = self.memory.clone().peek(start_pc + 1) as u16;
let high_byte = (local_memory.peek(start_pc) as u16).rotate_left(8);
let low_byte = local_memory.peek(start_pc + 1) as u16;
let result = high_byte | low_byte;
let decoded_instruction =
Chip8CpuInstructions::decode(result);
@@ -101,9 +103,10 @@ impl Chip8Computer {
self.sound_timer.tick();
self.delay_timer.tick();
self.video_memory.tick();
self.num_cycles += 1;
}
Chip8CpuStates::WaitingForKey => {
println!("waiting for a key press...");
debug!("waiting for a key press...");
}
_ => {}
}
+9 -7
View File
@@ -1,4 +1,5 @@
use std::ops::{BitAnd, Shr};
use std::time::Instant;
use log::debug;
use rand::{random, Rng};
use crate::chip8::computer::{Chip8Computer};
@@ -417,6 +418,8 @@ impl Chip8CpuInstructions {
}
pub fn execute(&self, input: &mut Chip8Computer) -> Chip8Computer {
print!("INSTRUCTION {:04x}", self.encode());
let start_time = Instant::now();
let start_pc = input.registers.peek_pc();
input.registers.poke_pc(start_pc + 2);
let _ = match self {
@@ -681,19 +684,16 @@ impl Chip8CpuInstructions {
for byte_index in 0..num_bytes_to_read {
let current_byte = input.memory.peek(byte_index as u16 + source_memory_offset);
let x_offset: u16 = (x_offset + byte_index) as u16 * 64;
for bit_index in 0..8 {
let data_offset = ((x_offset as u16 + byte_index as u16) * 64) + (y_offset as u16 + bit_index as u16) as u16;
let data_offset = x_offset + (y_offset as u16 + bit_index as u16);
let current_bit = (current_byte & (0x80 >> bit_index)) != 0;
let previous_bit = input.video_memory.peek(data_offset);
let new_bit = previous_bit ^ current_bit;
if previous_bit && !new_bit {
did_change = true;
}
input.video_memory.poke(data_offset, current_bit);
}
}
if did_change {
if input.video_memory.has_frame_changed {
input.registers.poke(0xf, 1u8);
} else {
input.registers.poke(0xf, 0u8);
@@ -827,7 +827,9 @@ impl Chip8CpuInstructions {
}
Chip8CpuInstructions::XXXXERRORINSTRUCTION => {}
};
input.clone()
let cycle_time = Instant::now().duration_since(start_time).as_nanos();
println!("Took {cycle_time}ms");
input.to_owned()
}
}
+1 -3
View File
@@ -14,9 +14,7 @@ impl Chip8Video {
}
pub fn cls(&mut self) {
for i in 0..CHIP8_VIDEO_MEMORY {
self.memory[i] = false;
}
self.memory = [false; CHIP8_VIDEO_MEMORY];
}
pub fn start_frame(&mut self) {