mirror of
https://github.com/FranLMSP/rmg-001.git
synced 2024-11-23 10:12:11 +00:00
Frame counter
This commit is contained in:
parent
6404593f2c
commit
7beeae01fa
@ -59,11 +59,15 @@ impl Bus {
|
|||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let args: Vec<String> = std::env::args().collect();
|
let args: Vec<String> = std::env::args().collect();
|
||||||
if args.len() < 2 {
|
if args.len() < 2 {
|
||||||
panic!("Please, specify a ROM");
|
println!("Please, specify a ROM file");
|
||||||
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
let game_rom = match ROM::load_file(&args[1]) {
|
let game_rom = match ROM::load_file(&args[1]) {
|
||||||
Ok(rom) => rom,
|
Ok(rom) => rom,
|
||||||
Err(_) => panic!("Could not read ROM"),
|
Err(err) => {
|
||||||
|
println!("Could not read ROM: {}", err);
|
||||||
|
std::process::exit(1);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
let mut data = [0x00; 0x10000];
|
let mut data = [0x00; 0x10000];
|
||||||
// Hardware registers after the bootrom
|
// Hardware registers after the bootrom
|
||||||
|
37
src/frames.rs
Normal file
37
src/frames.rs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
|
pub struct Frames {
|
||||||
|
count: usize,
|
||||||
|
timer: Instant,
|
||||||
|
time_start: u128,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Frames {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
count: 0,
|
||||||
|
timer: Instant::now(),
|
||||||
|
time_start: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reset_count(&mut self) {
|
||||||
|
self.count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reset_timer(&mut self) {
|
||||||
|
self.time_start = self.timer.elapsed().as_millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn increment(&mut self) {
|
||||||
|
self.count = self.count.saturating_add(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn elapsed_ms(&self) -> u128 {
|
||||||
|
self.timer.elapsed().as_millis().saturating_sub(self.time_start)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn count(&self) -> usize {
|
||||||
|
self.count
|
||||||
|
}
|
||||||
|
}
|
@ -7,3 +7,4 @@ pub mod bus;
|
|||||||
pub mod joypad;
|
pub mod joypad;
|
||||||
pub mod emulator;
|
pub mod emulator;
|
||||||
pub mod render;
|
pub mod render;
|
||||||
|
pub mod frames;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use crate::emulator::Emulator;
|
use crate::emulator::Emulator;
|
||||||
|
use crate::frames::Frames;
|
||||||
use crate::cpu::{Cycles};
|
use crate::cpu::{Cycles};
|
||||||
use crate::ppu::{WIDTH, HEIGHT};
|
use crate::ppu::{WIDTH, HEIGHT};
|
||||||
|
|
||||||
@ -42,6 +43,9 @@ pub fn create_window<T>(width: u32, height: u32, title: String, event_loop: &Eve
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_eventloop() {
|
pub fn start_eventloop() {
|
||||||
|
let mut emulator = Emulator::new();
|
||||||
|
let mut frames = Frames::new();
|
||||||
|
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let event_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
let mut input = WinitInputHelper::new();
|
let mut input = WinitInputHelper::new();
|
||||||
@ -49,8 +53,6 @@ pub fn start_eventloop() {
|
|||||||
let window = create_window(WIDTH, HEIGHT, "rmg-001".to_string(), &event_loop);
|
let window = create_window(WIDTH, HEIGHT, "rmg-001".to_string(), &event_loop);
|
||||||
let mut pixels = create_pixels(WIDTH, HEIGHT, &window);
|
let mut pixels = create_pixels(WIDTH, HEIGHT, &window);
|
||||||
|
|
||||||
let mut emulator = Emulator::new();
|
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
*control_flow = ControlFlow::Wait;
|
*control_flow = ControlFlow::Wait;
|
||||||
|
|
||||||
@ -80,6 +82,12 @@ pub fn start_eventloop() {
|
|||||||
},
|
},
|
||||||
Event::MainEventsCleared => {
|
Event::MainEventsCleared => {
|
||||||
emulator.run(Cycles(70224), pixels.get_frame());
|
emulator.run(Cycles(70224), pixels.get_frame());
|
||||||
|
frames.increment();
|
||||||
|
if frames.elapsed_ms() >= 1000 {
|
||||||
|
window.set_title(&format!("rmg-001 (FPS: {})", frames.count()));
|
||||||
|
frames.reset_count();
|
||||||
|
frames.reset_timer();
|
||||||
|
}
|
||||||
|
|
||||||
// thread::sleep(time::Duration::from_millis(1));
|
// thread::sleep(time::Duration::from_millis(1));
|
||||||
window.request_redraw();
|
window.request_redraw();
|
||||||
|
Loading…
Reference in New Issue
Block a user