trevors_chip8_toy/gemma/src/chip8/sound_timer.rs
Trevor Merritt cddbe0c46e fixes reset from exection completion
adds 'default.oc8'
adds control window size to state for load/save of settings maybe?
moves TestCompressionTool code into InstructionUtil
remove gemmautil and moves into gemma
2024-11-09 20:07:21 -05:00

49 lines
1.1 KiB
Rust

use log::trace;
use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Serialize, Deserialize, Debug, PartialEq)]
pub struct SoundTimer {
counter: i32,
}
impl Default for SoundTimer {
fn default() -> Self {
Self::new()
}
}
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;
}
}