From 04fcb000a161362c15becc14ef037e9e69bf1e0e Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Mon, 13 Feb 2023 10:51:52 +1100 Subject: [PATCH] initial apu --- src/processor/apu.rs | 7 +++++++ src/processor/memory.rs | 7 ++++++- src/processor/mod.rs | 5 ++++- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 src/processor/apu.rs diff --git a/src/processor/apu.rs b/src/processor/apu.rs new file mode 100644 index 0000000..bb95584 --- /dev/null +++ b/src/processor/apu.rs @@ -0,0 +1,7 @@ +pub(super) struct Apu {} + +impl Apu { + pub(super) fn init() -> Self { + Self {} + } +} diff --git a/src/processor/memory.rs b/src/processor/memory.rs index 7f058ae..1741309 100644 --- a/src/processor/memory.rs +++ b/src/processor/memory.rs @@ -101,6 +101,7 @@ pub struct Memory { io: [u8; 76], pub(super) user_mode: bool, joypad: Joypad, + pub(super) apu_enabled: bool, } impl Memory { @@ -120,6 +121,7 @@ impl Memory { io: [0xFF; 76], user_mode: false, joypad: Joypad::default(), + apu_enabled: true, } } @@ -227,7 +229,10 @@ impl Memory { 0xFF1C => self.masked_io(addr_l, data, 0b1100000), 0xFF20 => self.masked_io(addr_l, data, 0b111111), 0xFF23 => self.io[addr_l] = (self.io[addr_l] & 0b10111111) | (data & 0b01000000), - 0xFF26 => self.io[addr_l] = (self.io[addr_l] & 0b1111111) | (data & 0b10000000), + 0xFF26 => { + self.io[addr_l] = (self.io[addr_l] & 0b1111111) | (data & 0b10000000); + self.apu_enabled = self.io[addr_l] & 0b10000000 == 0b10000000 + } 0xFF11 | 0xFF14 | 0xFF16 | 0xFF19 | 0xFF1E => { // sound self.io[addr_l] = data; diff --git a/src/processor/mod.rs b/src/processor/mod.rs index b064df3..8b7e615 100644 --- a/src/processor/mod.rs +++ b/src/processor/mod.rs @@ -1,4 +1,4 @@ -use self::{gpu::Gpu, memory::Memory, timer::Timers}; +use self::{apu::Apu, gpu::Gpu, memory::Memory, timer::Timers}; use crate::{ util::{clear_bit, get_bit}, verbose_println, @@ -6,6 +6,7 @@ use crate::{ use gilrs::Gilrs; use minifb::Window; +mod apu; pub mod gpu; mod instructions; pub mod memory; @@ -35,6 +36,7 @@ pub struct Cpu { halted: bool, timers: Timers, gamepad_handler: Gilrs, + apu: Apu, } // Hz @@ -62,6 +64,7 @@ impl Cpu { halted: false, timers: Timers::init(), gamepad_handler, + apu: Apu::init(), } }