trevors_chip8_toy/gemma/src/chip8/sound_timer.rs
2024-10-27 17:52:19 -04:00

40 lines
935 B
Rust

use log::trace;
#[derive(Clone, Copy)]
pub struct SoundTimer {
counter: i32
}
impl SoundTimer {
pub fn current(&self) -> i32 {
self.counter
}
pub fn new() -> Self {
SoundTimer {
counter: 0
}
}
pub fn set_timer(&mut self, new_value: i32) {
trace!("SETTING SOUND TIMER TO {new_value}");
self.counter = new_value
}
pub fn tick(&mut self) {
trace!("TICKING SOUND FROM {} to {}", self.counter, self.counter - 1);
if self.counter > 0 {
self.counter -= 1;
/*
todo: this breaks tests. maybe its wrong?
if let good_thread = thread::spawn(|| {
beep(440).expect("Unable to beep");
thread::sleep(time::Duration::from_millis(500));
}).join().unwrap().
*/
}
}
pub fn reset(&mut self) {
self.counter = 0x00;
}
}