Skip to content

Commit

Permalink
Add approximate feature
Browse files Browse the repository at this point in the history
To emulate the same behavior as used in the rusty-date
  • Loading branch information
Javier-varez committed May 22, 2024
1 parent f449172 commit 6b4d2c5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions rusty-boy-sdl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ categories = ["embedded", "gaming"]
keywords = ["embedded", "gameboy", "playdate"]
readme = "../README.md"

[features]
approximate = []

[dependencies]
cartridge = { path = "../cartridge" }
ppu = { path = "../ppu" }
sm83 = { path = "../sm83" }
rusty-boy = { path = "../rusty-boy" }
anyhow = "1.0"
png = "0.17"
Expand Down
15 changes: 14 additions & 1 deletion rusty-boy-sdl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ fn main() -> anyhow::Result<()> {
.map_err(|e| anyhow::format_err!("Invalid cartridge: {}", e))?;
let mut rusty_boy = RustyBoy::new_with_cartridge(cartridge);

#[cfg(feature = "approximate")]
rusty_boy.configure_cpu_step(sm83::core::Cycles::new(60));

if rusty_boy.supports_battery_backed_ram() {
attempt_restore_save_file(&mut rusty_boy, &args.rom_path)?;
}
Expand Down Expand Up @@ -217,6 +220,10 @@ fn main() -> anyhow::Result<()> {

let frame = {
let frame_start = Instant::now();

#[cfg(feature = "approximate")]
rusty_boy.run_until_next_frame(false);

let frame = rusty_boy.run_until_next_frame(true);
let frame_end = Instant::now();
load += frame_end - frame_start;
Expand Down Expand Up @@ -244,7 +251,13 @@ fn main() -> anyhow::Result<()> {
}
}

next_deadline += Duration::from_nanos(16_666_667); // 60 fps
#[cfg(feature = "approximate")]
const FRAME_TIME: Duration = Duration::from_nanos(33_333_333); // 30 fps
#[cfg(not(feature = "approximate"))]
const FRAME_TIME: Duration = Duration::from_nanos(16_666_667); // 60 fps

next_deadline += FRAME_TIME;

sleep_until(next_deadline);

frame_id += 1;
Expand Down

0 comments on commit 6b4d2c5

Please sign in to comment.