timer consts

This commit is contained in:
Alex Janka 2023-02-15 09:01:05 +11:00
parent 28fb90c8d6
commit 7ff06f151e
2 changed files with 4 additions and 6 deletions

View file

@ -40,10 +40,6 @@ pub struct Cpu {
cycle_start: Instant, cycle_start: Instant,
} }
// Hz
const CLOCK_SPEED: usize = 4194304;
const SPEEDUP: f64 = 1.;
impl Cpu { impl Cpu {
pub fn new( pub fn new(
mut memory: Memory, mut memory: Memory,

View file

@ -1,7 +1,7 @@
use std::time::Duration; use std::time::Duration;
use crate::{ use crate::{
processor::{Cpu, CLOCK_SPEED, SPEEDUP}, processor::Cpu,
util::{get_bit, set_bit}, 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 // this will need to change when cgb mode is implemented
// as it uses bit 5 in double speed mode // as it uses bit 5 in double speed mode
const AUDIO_BIT: u8 = 4; const AUDIO_BIT: u8 = 4;
@ -68,7 +70,7 @@ impl Cpu {
pub(super) fn sleep(&mut self, machine_cycles: u8) { pub(super) fn sleep(&mut self, machine_cycles: u8) {
let secs = ((machine_cycles as f64) * 4.) / CLOCK_SPEED as f64; let secs = ((machine_cycles as f64) * 4.) / CLOCK_SPEED as f64;
if let Some(remaining) = 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); spin_sleep::sleep(remaining);
} }