diff --git a/Cargo.lock b/Cargo.lock index 141c7bf..c80f96f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -461,6 +461,13 @@ dependencies = [ "yansi 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "fps_bench" +version = "0.1.0" +dependencies = [ + "rustboyadvance-core 0.1.0", +] + [[package]] name = "fuchsia-cprng" version = "0.1.1" diff --git a/Cargo.toml b/Cargo.toml index 9d961a2..0c42615 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ members = [ "platform/rustboyadvance-sdl2", "platform/rustboyadvance-minifb", "bindings/rustboyadvance-jni", + "fps_bench" ] [profile.dev] diff --git a/fps_bench/Cargo.toml b/fps_bench/Cargo.toml new file mode 100644 index 0000000..a0e932c --- /dev/null +++ b/fps_bench/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "fps_bench" +version = "0.1.0" +authors = ["Michel Heily "] +edition = "2018" + +[dependencies] +rustboyadvance-core = {path = "../rustboyadvance-core/"} diff --git a/fps_bench/src/main.rs b/fps_bench/src/main.rs new file mode 100644 index 0000000..06b6678 --- /dev/null +++ b/fps_bench/src/main.rs @@ -0,0 +1,58 @@ +use std::cell::RefCell; +use std::env; +use std::path::Path; +use std::rc::Rc; + +use rustboyadvance_core::prelude::*; +use rustboyadvance_core::util::FpsCounter; + +struct BenchmarkHardware {} + +impl BenchmarkHardware { + fn new() -> BenchmarkHardware { + BenchmarkHardware {} + } +} + +impl VideoInterface for BenchmarkHardware {} +impl AudioInterface for BenchmarkHardware {} +impl InputInterface for BenchmarkHardware {} + +fn main() { + if env::args().count() < 3 { + eprintln!("usage: {} ", env::args().nth(0).unwrap()); + return; + } + + let bios_path = env::args().nth(1).expect("missing "); + let rom_path = env::args().nth(2).expect("missing "); + + let bios = read_bin_file(Path::new(&bios_path)).expect("failed to read bios file"); + let rom = read_bin_file(Path::new(&rom_path)).expect("failed to read rom file"); + + let gamepak = GamepakBuilder::new() + .take_buffer(rom.into_boxed_slice()) + .with_sram() + .without_backup_to_file() + .build() + .unwrap(); + + let dummy = Rc::new(RefCell::new(BenchmarkHardware::new())); + + let mut gba = GameBoyAdvance::new( + bios.into_boxed_slice(), + gamepak, + dummy.clone(), + dummy.clone(), + dummy.clone(), + ); + gba.skip_bios(); + + let mut fps_counter = FpsCounter::default(); + loop { + gba.frame(); + if let Some(fps) = fps_counter.tick() { + println!("FPS: {}", fps); + } + } +}