From 1336a3af34ee6694fcef0fa555783415d083f033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com> Date: Fri, 3 Mar 2023 12:11:55 +0000 Subject: [PATCH] feat: conditional enabling of components This is specially useful for disabling APU if not used. --- src/gb.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/gb.rs b/src/gb.rs index 26103de9..ace18d14 100644 --- a/src/gb.rs +++ b/src/gb.rs @@ -34,6 +34,9 @@ use std::{ #[cfg_attr(feature = "wasm", wasm_bindgen)] pub struct GameBoy { cpu: Cpu, + ppu_enabled: bool, + apu_enabled: bool, + timer_enabled: bool, } #[cfg_attr(feature = "wasm", wasm_bindgen)] @@ -71,7 +74,12 @@ impl GameBoy { let timer = Timer::default(); let mmu = Mmu::new(ppu, apu, pad, timer); let cpu = Cpu::new(mmu); - Self { cpu } + Self { + cpu, + ppu_enabled: true, + apu_enabled: false, + timer_enabled: true, + } } pub fn reset(&mut self) { @@ -82,9 +90,15 @@ impl GameBoy { pub fn clock(&mut self) -> u8 { let cycles = self.cpu_clock(); - self.ppu_clock(cycles); - self.apu_clock(cycles); - self.timer_clock(cycles); + if self.ppu_enabled { + self.ppu_clock(cycles); + } + if self.apu_enabled { + self.apu_clock(cycles); + } + if self.timer_enabled { + self.timer_clock(cycles); + } cycles } -- GitLab