From 7acfaeb3a129e215f6dd6e9187cc27ebd892cc0b Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Wed, 15 Jul 2020 15:08:02 -0500 Subject: [PATCH] Remove Beep from Delay Timer --- src/emu.rs | 2 +- src/periph.rs | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/emu.rs b/src/emu.rs index 6ddc7d3..b3b0af4 100644 --- a/src/emu.rs +++ b/src/emu.rs @@ -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, diff --git a/src/periph.rs b/src/periph.rs index df4430f..ed93f57 100644 --- a/src/periph.rs +++ b/src/periph.rs @@ -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(); + } } } }