Skip to content
Snippets Groups Projects
Verified Commit 1336a3af authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

feat: conditional enabling of components

This is specially useful for disabling APU if not used.
parent 8317d608
No related branches found
No related tags found
No related merge requests found
Pipeline #2319 passed
...@@ -34,6 +34,9 @@ use std::{ ...@@ -34,6 +34,9 @@ use std::{
#[cfg_attr(feature = "wasm", wasm_bindgen)] #[cfg_attr(feature = "wasm", wasm_bindgen)]
pub struct GameBoy { pub struct GameBoy {
cpu: Cpu, cpu: Cpu,
ppu_enabled: bool,
apu_enabled: bool,
timer_enabled: bool,
} }
#[cfg_attr(feature = "wasm", wasm_bindgen)] #[cfg_attr(feature = "wasm", wasm_bindgen)]
...@@ -71,7 +74,12 @@ impl GameBoy { ...@@ -71,7 +74,12 @@ impl GameBoy {
let timer = Timer::default(); let timer = Timer::default();
let mmu = Mmu::new(ppu, apu, pad, timer); let mmu = Mmu::new(ppu, apu, pad, timer);
let cpu = Cpu::new(mmu); let cpu = Cpu::new(mmu);
Self { cpu } Self {
cpu,
ppu_enabled: true,
apu_enabled: false,
timer_enabled: true,
}
} }
pub fn reset(&mut self) { pub fn reset(&mut self) {
...@@ -82,9 +90,15 @@ impl GameBoy { ...@@ -82,9 +90,15 @@ impl GameBoy {
pub fn clock(&mut self) -> u8 { pub fn clock(&mut self) -> u8 {
let cycles = self.cpu_clock(); let cycles = self.cpu_clock();
self.ppu_clock(cycles); if self.ppu_enabled {
self.apu_clock(cycles); self.ppu_clock(cycles);
self.timer_clock(cycles); }
if self.apu_enabled {
self.apu_clock(cycles);
}
if self.timer_enabled {
self.timer_clock(cycles);
}
cycles cycles
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment