From 834423fe18a42e344272b987b5e0ad7ff0ff6881 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Sun, 3 Jan 2021 02:05:46 -0600 Subject: [PATCH] feat: stub sound register 0xff26 --- src/bus.rs | 5 +++++ src/lib.rs | 1 + src/main.rs | 2 +- src/sound.rs | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/sound.rs diff --git a/src/bus.rs b/src/bus.rs index 6d58d21..bac2ed2 100644 --- a/src/bus.rs +++ b/src/bus.rs @@ -1,6 +1,7 @@ use super::cartridge::Cartridge; use super::interrupt::Interrupt; use super::ppu::PPU; +use super::sound::Sound; use super::timer::Timer; use super::work_ram::{VariableWorkRAM, WorkRAM}; @@ -13,6 +14,7 @@ pub struct Bus { vwram: VariableWorkRAM, timer: Timer, interrupt: Interrupt, + sound: Sound, } impl Default for Bus { @@ -25,6 +27,7 @@ impl Default for Bus { vwram: Default::default(), timer: Default::default(), interrupt: Default::default(), + sound: Default::default(), } } } @@ -96,6 +99,7 @@ impl Bus { match addr { 0xFF07 => self.timer.control.into(), 0xFF0F => self.interrupt.flag.into(), + 0xFF26 => self.sound.status.into(), _ => unimplemented!("Unable to read {:#06X} in I/O Registers", addr), } } @@ -153,6 +157,7 @@ impl Bus { match addr { 0xFF07 => self.timer.control = byte.into(), 0xFF0F => self.interrupt.flag = byte.into(), + 0xFF26 => self.sound.status = byte.into(), // FIXME: Should we control which bytes are written to here? _ => unimplemented!("Unable to write to {:#06X} in I/O Registers", addr), }; } diff --git a/src/lib.rs b/src/lib.rs index e9d0efb..4101db3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,5 +4,6 @@ pub mod cpu; mod instruction; mod interrupt; mod ppu; +mod sound; mod timer; mod work_ram; diff --git a/src/main.rs b/src/main.rs index 2317240..56ac559 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ use gb::cpu::Cpu as LR35902; fn main() { - let mut game_boy = LR35902::new_without_boot(); + let mut game_boy = LR35902::new(); game_boy.load_cartridge("bin/cpu_instrs.gb"); diff --git a/src/sound.rs b/src/sound.rs new file mode 100644 index 0000000..9f2d6d0 --- /dev/null +++ b/src/sound.rs @@ -0,0 +1,35 @@ +#[derive(Debug, Clone, Copy, Default)] +pub struct Sound { + pub status: SoundStatus, +} + +#[derive(Debug, Clone, Copy, Default)] +pub struct SoundStatus { + pub all_enabled: bool, // You can actually write to this one. + sound_4: bool, + sound_3: bool, + sound_2: bool, + sound_1: bool, +} + +impl From for SoundStatus { + fn from(byte: u8) -> Self { + Self { + all_enabled: (byte >> 7) & 0x01 == 0x01, + sound_4: (byte >> 3) & 0x01 == 0x01, + sound_3: (byte >> 2) & 0x01 == 0x01, + sound_2: (byte >> 1) & 0x01 == 0x01, + sound_1: (byte >> 0) & 0x01 == 0x01, + } + } +} + +impl From for u8 { + fn from(status: SoundStatus) -> Self { + (status.all_enabled as u8) << 7 + | (status.sound_4 as u8) << 3 + | (status.sound_3 as u8) << 2 + | (status.sound_2 as u8) << 1 + | (status.sound_1 as u8) << 0 + } +}