more sample roms.

more coverage.
This commit is contained in:
2024-11-01 09:41:20 -04:00
parent 13ceb61c97
commit 00c75a82e5
12 changed files with 232 additions and 318 deletions
+42
View File
@@ -0,0 +1,42 @@
use std::fs::File;
use std::io::Read;
use std::ops::Add;
use std::path::Path;
use std::time::{Duration, Instant};
use gemma::chip8::computer::Chip8Computer;
use gemma::chip8::computer_manager::Chip8ComputerManager;
const ROM_ROOT: &str = "resources/roms";
fn main() {
let mut x = Chip8ComputerManager::new();
let mut buffer = Vec::new();
let mut input_file = File::open(Path::new(&(ROM_ROOT.to_string() + "/mandelbrot_bench.ch8"))).expect("derp");
input_file.read_to_end(&mut buffer).expect("unable to read file");
x.load_new_program_to_system_memory((&*buffer).into());
for _ in 0..10 {
let start_time = Instant::now();
let mut num_cycles = 0;
// how many instructions in 10s.
let end_time = start_time.add(Duration::from_secs(10));
while (Instant::now().le(&end_time)) {
num_cycles += 1;
x.step();
}
let num = num_cycles.to_string()
.as_bytes()
.rchunks(3)
.rev()
.map(std::str::from_utf8)
.collect::<Result<Vec<&str>, _>>()
.unwrap()
.join(","); // separator
let num_ips = num_cycles / 1000000;
println!("Completed at {num_ips} Mips.");
}
}
+2 -1
View File
@@ -35,7 +35,8 @@ impl Chip8SystemMemory {
pub fn peek(&self, address: u16) -> u8 {
trace!("PEEK: {} / {}", address, self.memory[address as usize].clone());
self.memory[address as usize]
let effective = address as i32 % CHIP8_MEMORY_SIZE;
self.memory[effective as usize]
}
pub fn poke(&mut self, address: u16, value: u8) {
+22 -7
View File
@@ -3,7 +3,7 @@ use crate::chip8::video::Chip8VideoModes::{HighRes, LowRes};
use crate::constants::{CHIP8_VIDEO_HEIGHT, CHIP8_VIDEO_MEMORY, CHIP8_VIDEO_WIDTH, SCHIP_VIDE_MEMORY, SCHIP_VIDEO_HEIGHT, SCHIP_VIDEO_WIDTH};
#[derive(Clone, Copy)]
enum Chip8VideoModes {
pub enum Chip8VideoModes {
LowRes,
HighRes,
}
@@ -15,15 +15,10 @@ pub struct Chip8Video {
current_res: Chip8VideoModes,
}
impl Chip8Video {
pub fn scroll_up(&self, how_far: &u8) {
println!("Scrolling up {how_far} rows.");
}
}
impl Chip8Video {
pub fn reset(&mut self) {
self.cls();
self.set_lowres();
self.start_frame();
}
@@ -186,6 +181,26 @@ impl Chip8Video {
}
}
pub fn scroll_up(&mut self, how_far: &u8) {
let how_far = *how_far as i32;
let (width, height) = self.get_resolution();
let row_shift = how_far * width;
for current_source_row in how_far..height {
let current_source_offset = current_source_row * width;
for current_source_column in 0..width {
let base_offset: usize = (current_source_offset + current_source_column) as usize;
let shifted_offset: usize = base_offset - row_shift as usize;
self.memory[shifted_offset] = self.memory[base_offset];
}
}
// Clear the new bottom rows after shifting
let clear_start = ((height - how_far) * width) as usize;
self.memory[clear_start..].fill(false);
}
pub fn scroll_down(&mut self, how_far: i32) {
let (width, height) = self.get_resolution();
let row_shift = how_far * width;