apu
This commit is contained in:
parent
b6361738fe
commit
1e59eace50
|
@ -3,6 +3,10 @@ mod square;
|
||||||
mod triangle;
|
mod triangle;
|
||||||
mod dmc;
|
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 {
|
pub struct Apu {
|
||||||
square1: Square,
|
square1: Square,
|
||||||
square2: Square,
|
square2: Square,
|
||||||
|
@ -83,6 +87,10 @@ impl Apu {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn clock(&mut self) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
fn write_reg(&mut self, address: usize, value: u8) {
|
fn write_reg(&mut self, address: usize, value: u8) {
|
||||||
match address {
|
match address {
|
||||||
0x4000 => self.square1.duty(value),
|
0x4000 => self.square1.duty(value),
|
||||||
|
@ -118,6 +126,11 @@ impl Apu {
|
||||||
square_out + tnd_out
|
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) {
|
fn step_frame_counter(&mut self, value: u8) {
|
||||||
// 0 selects 4-step sequence, 1 selects 5-step sequence
|
// 0 selects 4-step sequence, 1 selects 5-step sequence
|
||||||
if value & (1<<7) == 0 {
|
if value & (1<<7) == 0 {
|
||||||
|
|
|
@ -3,7 +3,7 @@ extern crate sdl2;
|
||||||
use sdl2::audio::{AudioCallback, AudioSpecDesired};
|
use sdl2::audio::{AudioCallback, AudioSpecDesired};
|
||||||
|
|
||||||
pub struct Speaker {
|
pub struct Speaker {
|
||||||
buffer: [u8; 4096],
|
buffer: [f32; 4096],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AudioCallback for Speaker {
|
impl AudioCallback for Speaker {
|
||||||
|
|
|
@ -190,7 +190,7 @@ impl Cpu {
|
||||||
// look up instruction in table and execute
|
// look up instruction in table and execute
|
||||||
self.opcode_table[opcode](self, address, mode);
|
self.opcode_table[opcode](self, address, mode);
|
||||||
// maintain 1 apu cycle per 2 cpu cycles
|
// 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
|
// return how many cycles it took
|
||||||
self.clock - clock
|
self.clock - clock
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,8 +64,8 @@ pub struct Ppu {
|
||||||
grayscale: bool,
|
grayscale: bool,
|
||||||
show_background_left: bool, // 1: Show background in leftmost 8 pixels of screen, 0: Hide
|
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_sprites_left: bool, // 1: Show sprites in leftmost 8 pixels of screen, 0: Hide
|
||||||
show_background: bool, // 1: Show background
|
show_background: bool, // 1: Show background
|
||||||
show_sprites: bool, // 1: Show sprites
|
show_sprites: bool, // 1: Show sprites
|
||||||
emphasize_red: bool, // Emphasize red
|
emphasize_red: bool, // Emphasize red
|
||||||
emphasize_green: bool, // Emphasize green
|
emphasize_green: bool, // Emphasize green
|
||||||
emphasize_blue: bool, // Emphasize blue
|
emphasize_blue: bool, // Emphasize blue
|
||||||
|
|
Loading…
Reference in New Issue