Remove Beep from Delay Timer

This commit is contained in:
Rekai Musuka 2020-07-15 15:08:02 -05:00
parent 37a2e89dab
commit 7acfaeb3a1
2 changed files with 12 additions and 2 deletions

View File

@ -28,7 +28,7 @@ impl Default for Chip8 {
stack: [0; 16],
memory: [0; 4096],
delay: Default::default(),
sound: Default::default(),
sound: Timer::default().with_beep(),
key: Default::default(),
display: Default::default(),
request_redraw: false,

View File

@ -61,6 +61,7 @@ impl Default for Display {
pub struct Timer {
remaining: u8,
enabled: bool,
beep_enabled: bool,
}
impl Default for Timer {
@ -68,11 +69,17 @@ impl Default for Timer {
Timer {
remaining: 0,
enabled: false,
beep_enabled: false,
}
}
}
impl Timer {
pub fn with_beep(mut self) -> Self {
self.beep_enabled = true;
self
}
pub fn set(&mut self, secs: u8) {
self.remaining = secs;
self.enabled = true;
@ -88,7 +95,10 @@ impl Timer {
if self.remaining == 0 {
self.enabled = false;
Self::beep();
if self.beep_enabled {
Self::beep();
}
}
}
}