diff options
author | Determinant <ted.sybil@gmail.com> | 2017-12-09 15:30:31 +0800 |
---|---|---|
committer | Determinant <ted.sybil@gmail.com> | 2017-12-09 15:30:31 +0800 |
commit | bc6440d96f3226d39a4a56dcc55dc7809f7fbc37 (patch) | |
tree | 45526a847f9dcc6b1bcd56b18dd0b4bb64cc4103 /src/memory.rs | |
parent | 1f664ad8d6a820a73bba52bc78b6e2fbb1b12345 (diff) |
clock by audio
Diffstat (limited to 'src/memory.rs')
-rw-r--r-- | src/memory.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/memory.rs b/src/memory.rs index ecafe86..db7b200 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -1,7 +1,7 @@ #![allow(dead_code)] use ppu::PPU; -use apu::APU; -use mos6502::CPU; +use apu::{APU, Sampler}; +use mos6502::{CPU, CPU_FREQ}; use cartridge::MirrorType; use mapper::Mapper; use controller::Controller; @@ -16,14 +16,17 @@ pub trait VMem { pub struct CPUBus<'a> { cpu: *mut CPU<'a>, ppu: *mut PPU<'a>, - apu: *mut APU<'a> + apu: *mut APU<'a>, + ppu_sampler: RefCell<Sampler>, } impl<'a> CPUBus<'a> { pub fn new() -> Self { CPUBus {ppu: null_mut(), cpu: null_mut(), - apu: null_mut()} + apu: null_mut(), + ppu_sampler: RefCell::new(Sampler::new(CPU_FREQ, 60)), + } } pub fn attach(&mut self, cpu: *mut CPU<'a>, @@ -48,6 +51,9 @@ impl<'a> CPUBus<'a> { if apu.tick() { cpu.trigger_irq() } + if let (true, _) = self.ppu_sampler.borrow_mut().tick() { + ppu.scr.frame() + } cpu.tick(); } } @@ -74,6 +80,7 @@ impl<'a> CPUMemory<'a> { &self.bus } + #[inline(always)] pub fn read_without_tick(&self, addr: u16) -> u8 { let cpu = self.bus.get_cpu(); let ppu = self.bus.get_ppu(); @@ -101,6 +108,7 @@ impl<'a> CPUMemory<'a> { } } + #[inline(always)] pub fn write_without_tick(&mut self, addr: u16, data: u8) { let cpu = self.bus.get_cpu(); let ppu = self.bus.get_ppu(); |