diff --git a/src/processor/mod.rs b/src/processor/mod.rs index 5c0a2f7..bf5c8b8 100644 --- a/src/processor/mod.rs +++ b/src/processor/mod.rs @@ -40,10 +40,6 @@ pub struct Cpu { cycle_start: Instant, } -// Hz -const CLOCK_SPEED: usize = 4194304; -const SPEEDUP: f64 = 1.; - impl Cpu { pub fn new( mut memory: Memory, diff --git a/src/processor/timer.rs b/src/processor/timer.rs index 4d641eb..b5e83aa 100644 --- a/src/processor/timer.rs +++ b/src/processor/timer.rs @@ -1,7 +1,7 @@ use std::time::Duration; use crate::{ - processor::{Cpu, CLOCK_SPEED, SPEEDUP}, + processor::Cpu, util::{get_bit, set_bit}, }; @@ -19,6 +19,8 @@ impl Timers { } } +// Hz +const CLOCK_SPEED: usize = 4194304; // this will need to change when cgb mode is implemented // as it uses bit 5 in double speed mode const AUDIO_BIT: u8 = 4; @@ -68,7 +70,7 @@ impl Cpu { pub(super) fn sleep(&mut self, machine_cycles: u8) { let secs = ((machine_cycles as f64) * 4.) / CLOCK_SPEED as f64; if let Some(remaining) = - Duration::from_secs_f64(secs / SPEEDUP).checked_sub(self.cycle_start.elapsed()) + Duration::from_secs_f64(secs).checked_sub(self.cycle_start.elapsed()) { spin_sleep::sleep(remaining); }