From 1e59eace50608c5f56d54ec2dc295b48cceb1fc2 Mon Sep 17 00:00:00 2001 From: Theron Date: Tue, 10 Dec 2019 00:34:21 -0600 Subject: [PATCH] apu --- src/apu/mod.rs | 13 +++++++++++++ src/audio.rs | 2 +- src/cpu/mod.rs | 2 +- src/ppu/mod.rs | 4 ++-- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/apu/mod.rs b/src/apu/mod.rs index a90589a..ba4ebed 100644 --- a/src/apu/mod.rs +++ b/src/apu/mod.rs @@ -3,6 +3,10 @@ mod square; mod triangle; mod dmc; +// APU clock ticks every other CPU cycle. +// Frame counter only ticks every 3728.5 APU ticks, and in audio frames of 4 or 5. +// Length counter controls note durations. + pub struct Apu { square1: Square, square2: Square, @@ -83,6 +87,10 @@ impl Apu { } } + pub fn clock(&mut self) { + + } + fn write_reg(&mut self, address: usize, value: u8) { match address { 0x4000 => self.square1.duty(value), @@ -118,6 +126,11 @@ impl Apu { square_out + tnd_out } + // mode 0: mode 1: function + // --------- ----------- ----------------------------- + // - - - f - - - - - IRQ (if bit 6 is clear) + // - l - l - l - - l Length counter and sweep + // e e e e e e e - e Envelope and linear counter fn step_frame_counter(&mut self, value: u8) { // 0 selects 4-step sequence, 1 selects 5-step sequence if value & (1<<7) == 0 { diff --git a/src/audio.rs b/src/audio.rs index bc6b249..e1b9334 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -3,7 +3,7 @@ extern crate sdl2; use sdl2::audio::{AudioCallback, AudioSpecDesired}; pub struct Speaker { - buffer: [u8; 4096], + buffer: [f32; 4096], } impl AudioCallback for Speaker { diff --git a/src/cpu/mod.rs b/src/cpu/mod.rs index a4c6e66..f11ffcc 100644 --- a/src/cpu/mod.rs +++ b/src/cpu/mod.rs @@ -190,7 +190,7 @@ impl Cpu { // look up instruction in table and execute self.opcode_table[opcode](self, address, mode); // maintain 1 apu cycle per 2 cpu cycles - if self. + self.even = if self.even { self.apu.step(); false } else { true }; // return how many cycles it took self.clock - clock } diff --git a/src/ppu/mod.rs b/src/ppu/mod.rs index d838de8..46e46c8 100644 --- a/src/ppu/mod.rs +++ b/src/ppu/mod.rs @@ -64,8 +64,8 @@ pub struct Ppu { grayscale: bool, show_background_left: bool, // 1: Show background in leftmost 8 pixels of screen, 0: Hide show_sprites_left: bool, // 1: Show sprites in leftmost 8 pixels of screen, 0: Hide - show_background: bool, // 1: Show background - show_sprites: bool, // 1: Show sprites + show_background: bool, // 1: Show background + show_sprites: bool, // 1: Show sprites emphasize_red: bool, // Emphasize red emphasize_green: bool, // Emphasize green emphasize_blue: bool, // Emphasize blue