Skip to content
Snippets Groups Projects
Verified Commit f3c17675 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

feat: initial benchmark support

parent 59a7a2b1
No related branches found
No related tags found
No related merge requests found
[package]
name = "chip-ahoyto-benchmark"
version = "0.1.0"
authors = ["João Magalhães <joamag@gmail.com>"]
description = "CHIP-8 Benchmark application"
license = "Apache-2.0"
keywords = ["chip-8", "emulator", "rust", "benchmark"]
edition = "2018"
[dependencies.chip-ahoyto]
path = "../.."
[profile.release]
debug = false
lto = true
opt-level = 3
File added
use chip_ahoyto::chip8::Chip8;
use std::{fs::File, io::Read};
const CYCLE_COUNT: u32 = 1_000_000_000;
fn main() {
let rom = read_file("./resources/pong.ch8");
let mut chip8 = Chip8::new();
chip8.reset_hard();
chip8.load_rom(&rom);
println!("Running {} cycles", CYCLE_COUNT);
for _ in 0..CYCLE_COUNT {
chip8.tick();
}
}
fn read_file(path: &str) -> Vec<u8> {
let mut file = File::open(path).unwrap();
let mut data = Vec::new();
file.read_to_end(&mut data).unwrap();
data
}
......@@ -272,9 +272,7 @@ fn main() {
for _ in 0..logic_visual_ratio {
// runs the tick operation in the CHIP-8 system,
// effectively changing the logic state of the machine
state.system.clock();
state.system.clock_dt();
state.system.clock_st();
state.system.tick();
beep |= state.system.beep();
}
......@@ -348,7 +346,7 @@ fn key_to_btn(keycode: Keycode) -> Option<u8> {
fn read_file(path: &str) -> Vec<u8> {
let mut file = File::open(path).unwrap();
let mut rom = Vec::new();
file.read_to_end(&mut rom).unwrap();
rom
let mut data = Vec::new();
file.read_to_end(&mut data).unwrap();
data
}
......@@ -120,6 +120,12 @@ impl Chip8 {
self.ram[ROM_START..ROM_START + rom.len()].clone_from_slice(rom);
}
pub fn tick(&mut self) {
self.clock();
self.clock_dt();
self.clock_st();
}
pub fn clock(&mut self) {
let opcode = self.fetch_opcode();
self.process_opcode(opcode);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment