This commit is contained in:
Theron 2019-12-10 00:34:21 -06:00
parent b6361738fe
commit 1e59eace50
4 changed files with 17 additions and 4 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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
}

View File

@ -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