Skip to content

Commit

Permalink
NES: fixed windows slow emulation (was due to windows Sleep function)
Browse files Browse the repository at this point in the history
`std :: thread :: sleep` is not the same in all platforms.
Rust uses `libc::nanosleep` in Linux which can take a number of nano seconds,
sleeping may not be exactly the time it was requested but at least
close.

On the other hand, Rust uses windows api function `Sleep`, it takes a
number of **Milliseconds**, this is not very good for small sleeps,
but this is what I want, and what the emulator was doing the whole time.

Changed the number of clocks to a whole frame, now that the APU is not
very affected by the sleeping time like before, this is not much of a
problem and now the emulator can run smoothly in windows. :)

*they should fix their Kernal*.
  • Loading branch information
Amjad50 committed Sep 6, 2020
1 parent 2feebaa commit 1ac20ac
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion nes_ui_base/src/nes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl<P: UiProvider + Send + 'static> NES<P> {

let mut last = std::time::Instant::now();
const CPU_FREQ: f64 = 1.789773 * 1E6;
const N: usize = 2000; // number of CPU cycles per loop, lower is smoother
const N: usize = 29780; // number of CPU cycles per loop, one full frame
const CPU_PER_CYCLE_NANOS: f64 = 1E9 / CPU_FREQ;

let mut average_apu_freq = CPU_FREQ / 2.;
Expand Down

0 comments on commit 1ac20ac

Please sign in to comment.