initial apu

This commit is contained in:
Alex Janka 2023-02-13 10:51:52 +11:00
parent 3af4772363
commit 04fcb000a1
3 changed files with 17 additions and 2 deletions

7
src/processor/apu.rs Normal file
View file

@ -0,0 +1,7 @@
pub(super) struct Apu {}
impl Apu {
pub(super) fn init() -> Self {
Self {}
}
}

View file

@ -101,6 +101,7 @@ pub struct Memory {
io: [u8; 76], io: [u8; 76],
pub(super) user_mode: bool, pub(super) user_mode: bool,
joypad: Joypad, joypad: Joypad,
pub(super) apu_enabled: bool,
} }
impl Memory { impl Memory {
@ -120,6 +121,7 @@ impl Memory {
io: [0xFF; 76], io: [0xFF; 76],
user_mode: false, user_mode: false,
joypad: Joypad::default(), joypad: Joypad::default(),
apu_enabled: true,
} }
} }
@ -227,7 +229,10 @@ impl Memory {
0xFF1C => self.masked_io(addr_l, data, 0b1100000), 0xFF1C => self.masked_io(addr_l, data, 0b1100000),
0xFF20 => self.masked_io(addr_l, data, 0b111111), 0xFF20 => self.masked_io(addr_l, data, 0b111111),
0xFF23 => self.io[addr_l] = (self.io[addr_l] & 0b10111111) | (data & 0b01000000), 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 => { 0xFF11 | 0xFF14 | 0xFF16 | 0xFF19 | 0xFF1E => {
// sound // sound
self.io[addr_l] = data; self.io[addr_l] = data;

View file

@ -1,4 +1,4 @@
use self::{gpu::Gpu, memory::Memory, timer::Timers}; use self::{apu::Apu, gpu::Gpu, memory::Memory, timer::Timers};
use crate::{ use crate::{
util::{clear_bit, get_bit}, util::{clear_bit, get_bit},
verbose_println, verbose_println,
@ -6,6 +6,7 @@ use crate::{
use gilrs::Gilrs; use gilrs::Gilrs;
use minifb::Window; use minifb::Window;
mod apu;
pub mod gpu; pub mod gpu;
mod instructions; mod instructions;
pub mod memory; pub mod memory;
@ -35,6 +36,7 @@ pub struct Cpu {
halted: bool, halted: bool,
timers: Timers, timers: Timers,
gamepad_handler: Gilrs, gamepad_handler: Gilrs,
apu: Apu,
} }
// Hz // Hz
@ -62,6 +64,7 @@ impl Cpu {
halted: false, halted: false,
timers: Timers::init(), timers: Timers::init(),
gamepad_handler, gamepad_handler,
apu: Apu::init(),
} }
} }