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

chore: support for unlimited mode

parent 12c18063
No related branches found
No related tags found
No related merge requests found
Pipeline #2768 passed
...@@ -54,13 +54,15 @@ impl Default for Benchmark { ...@@ -54,13 +54,15 @@ impl Default for Benchmark {
} }
pub struct EmulatorOptions { pub struct EmulatorOptions {
auto_mode: bool, auto_mode: Option<bool>,
unlimited: Option<bool>,
features: Option<Vec<&'static str>>, features: Option<Vec<&'static str>>,
} }
pub struct Emulator { pub struct Emulator {
system: GameBoy, system: GameBoy,
auto_mode: bool, auto_mode: bool,
unlimited: bool,
sdl: Option<SdlSystem>, sdl: Option<SdlSystem>,
audio: Option<Audio>, audio: Option<Audio>,
title: &'static str, title: &'static str,
...@@ -78,7 +80,8 @@ impl Emulator { ...@@ -78,7 +80,8 @@ impl Emulator {
pub fn new(system: GameBoy, options: EmulatorOptions) -> Self { pub fn new(system: GameBoy, options: EmulatorOptions) -> Self {
Self { Self {
system, system,
auto_mode: options.auto_mode, auto_mode: options.auto_mode.unwrap_or(true),
unlimited: options.unlimited.unwrap_or(false),
sdl: None, sdl: None,
audio: None, audio: None,
title: TITLE, title: TITLE,
...@@ -250,6 +253,10 @@ impl Emulator { ...@@ -250,6 +253,10 @@ impl Emulator {
self.palette_index = (self.palette_index + 1) % self.palettes.len(); self.palette_index = (self.palette_index + 1) % self.palettes.len();
} }
pub fn limited(&self) -> bool {
!self.unlimited
}
pub fn run(&mut self) { pub fn run(&mut self) {
// updates the icon of the window to reflect the image // updates the icon of the window to reflect the image
// and style of the emulator // and style of the emulator
...@@ -455,10 +462,15 @@ impl Emulator { ...@@ -455,10 +462,15 @@ impl Emulator {
.ceil() as u8; .ceil() as u8;
ticks = max(ticks, 1); ticks = max(ticks, 1);
// updates the next update time reference to the current // in case the limited (speed) mode is set then we must calculate
// time so that it can be used from game loop control // a new next tick time reference, this is required to prevent the
self.next_tick_time += (1000.0 / self.visual_frequency) * ticks as f32; // machine from running too fast (eg: 50x)
self.next_tick_time_i = self.next_tick_time.ceil() as u32; if self.limited() {
// updates the next update time reference to the current
// time so that it can be used from game loop control
self.next_tick_time += (1000.0 / self.visual_frequency) * ticks as f32;
self.next_tick_time_i = self.next_tick_time.ceil() as u32;
}
} }
let current_time = self.sdl.as_mut().unwrap().timer_subsystem.ticks(); let current_time = self.sdl.as_mut().unwrap().timer_subsystem.ticks();
...@@ -531,10 +543,15 @@ impl Emulator { ...@@ -531,10 +543,15 @@ impl Emulator {
.ceil() as u8; .ceil() as u8;
ticks = max(ticks, 1); ticks = max(ticks, 1);
// updates the next update time reference to the current // in case the limited (speed) mode is set then we must calculate
// time so that it can be used from game loop control // a new next tick time reference, this is required to prevent the
self.next_tick_time += (1000.0 / self.visual_frequency) * ticks as f32; // machine from running too fast (eg: 50x)
self.next_tick_time_i = self.next_tick_time.ceil() as u32; if self.limited() {
// updates the next update time reference to the current
// time so that it can be used from game loop control
self.next_tick_time += (1000.0 / self.visual_frequency) * ticks as f32;
self.next_tick_time_i = self.next_tick_time.ceil() as u32;
}
} }
let current_time = reference.elapsed().as_millis() as u32; let current_time = reference.elapsed().as_millis() as u32;
...@@ -569,6 +586,9 @@ struct Args { ...@@ -569,6 +586,9 @@ struct Args {
#[arg(long, default_value_t = false)] #[arg(long, default_value_t = false)]
headless: bool, headless: bool,
#[arg(long, default_value_t = false)]
unlimited: bool,
#[arg(short, long, default_value_t = String::from("../../res/roms/demo/pocket.gb"))] #[arg(short, long, default_value_t = String::from("../../res/roms/demo/pocket.gb"))]
rom_path: String, rom_path: String,
} }
...@@ -602,7 +622,8 @@ fn main() { ...@@ -602,7 +622,8 @@ fn main() {
// both the video and audio sub-systems, loads default // both the video and audio sub-systems, loads default
// ROM file and starts running it // ROM file and starts running it
let options = EmulatorOptions { let options = EmulatorOptions {
auto_mode, auto_mode: Some(auto_mode),
unlimited: Some(args.unlimited),
features: if args.headless { features: if args.headless {
Some(vec![]) Some(vec![])
} else { } else {
......
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