Major work
Some checks failed
Cargo Build & Test / Rust project - latest (stable) (push) Failing after 10s
Some checks failed
Cargo Build & Test / Rust project - latest (stable) (push) Failing after 10s
This commit is contained in:
44
src/apu.rs
44
src/apu.rs
@@ -46,13 +46,20 @@ struct DeltaChannel {
|
||||
enabled: bool,
|
||||
}
|
||||
|
||||
struct FrameCounter {
|
||||
count: usize,
|
||||
mode_5_step: bool,
|
||||
interrupt_enabled: bool,
|
||||
irq: bool,
|
||||
}
|
||||
|
||||
pub struct APU {
|
||||
pulse_1: PulseChannel,
|
||||
pulse_2: PulseChannel,
|
||||
triangle: TriangleChannel,
|
||||
noise: NoiseChannel,
|
||||
dmc: DeltaChannel,
|
||||
frame_counter: u8,
|
||||
frame_counter: FrameCounter,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for APU {
|
||||
@@ -74,7 +81,12 @@ impl APU {
|
||||
triangle: TriangleChannel { enabled: false },
|
||||
noise: NoiseChannel { enabled: false },
|
||||
dmc: DeltaChannel { enabled: false },
|
||||
frame_counter: 0,
|
||||
frame_counter: FrameCounter {
|
||||
mode_5_step: false,
|
||||
interrupt_enabled: true,
|
||||
count: 0,
|
||||
irq: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
pub fn read_reg(&mut self, offset: u16) -> u8 {
|
||||
@@ -98,11 +110,28 @@ impl APU {
|
||||
0x11 => {
|
||||
// TODO: load dmc counter with (val & 7F)
|
||||
}
|
||||
_ => panic!("No register at {:X}", offset),
|
||||
_ => (),
|
||||
// _ => panic!("No register at {:X}", offset),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_one_clock_cycle(&mut self) -> bool {
|
||||
pub fn run_one_clock_cycle(&mut self, ppu_cycle: usize) -> bool {
|
||||
if ppu_cycle % 6 == 1 {
|
||||
// APU Frame Counter clock cycle
|
||||
if !self.frame_counter.mode_5_step
|
||||
&& self.frame_counter.interrupt_enabled
|
||||
&& self.frame_counter.count == 14914
|
||||
{
|
||||
self.frame_counter.irq = true;
|
||||
} else if !self.frame_counter.mode_5_step
|
||||
&& self.frame_counter.interrupt_enabled
|
||||
&& self.frame_counter.count == 14915
|
||||
{
|
||||
self.frame_counter.irq = true;
|
||||
self.frame_counter.count = 0;
|
||||
}
|
||||
self.frame_counter.count += 1;
|
||||
}
|
||||
false
|
||||
}
|
||||
pub fn peek_nmi(&self) -> bool {
|
||||
@@ -112,10 +141,11 @@ impl APU {
|
||||
false
|
||||
}
|
||||
pub fn peek_irq(&self) -> bool {
|
||||
false
|
||||
self.frame_counter.irq
|
||||
}
|
||||
pub fn irq_waiting(&mut self) -> bool {
|
||||
// TODO: implement logic
|
||||
false
|
||||
let res = self.frame_counter.irq;
|
||||
self.frame_counter.irq = false;
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user