This commit is contained in:
Theron Spiegl 2020-01-01 21:50:20 -06:00
parent 0ea8ac6471
commit f4673188d2
3 changed files with 42 additions and 25 deletions

View File

@ -152,7 +152,8 @@ impl Apu {
}
if (self.current_frame == 1)
|| (self.frame_counter == 4 && self.current_frame == 3)
|| (self.frame_counter == 5 && self.current_frame == 4) {
|| (self.frame_counter == 5 && self.current_frame == 4)
{
// step length counters and sweep units
self.square1.clock_sweep();
self.square2.clock_sweep();

View File

@ -200,7 +200,6 @@ impl Square {
// When the enabled bit is cleared (via $4015), the length counter is forced to 0 and cannot be changed until enabled is set again (the length counter's previous value is lost).
if self.enabled {
self.length_counter = super::LENGTH_COUNTER_TABLE[value as usize >> 3];
// println!("val: 0b{:08b}, wrote length_counter {}", value, self.length_counter);
}
let timer_high = value as u16 & 0b0000_0111;
self.timer_period &= 0b11111000_11111111; // mask off high 3 bits of 11-bit timer

View File

@ -1,37 +1,30 @@
// $4008 Hlll.llll Triangle channel length counter halt and linear counter load (write)
// bit 7 H--- ---- Halt length counter (this bit is also the linear counter's control flag)
pub struct Triangle {
pub sample: u16,
timer: usize,
pub length_counter: usize, // (this bit is also the linear counter's control flag)
linear_counter: usize,
pub enabled: bool,
pub sample: u16,
timer: u16,
timer_period: u16,
pub length_counter: usize,
length_counter_halt: false, // (this bit is also the linear counter's control flag) / (this bit is also the length counter halt flag)
linear_counter: usize,
}
impl Triangle {
pub fn new() -> Self {
Triangle {
timer: 0,
length_counter: 0,
linear_counter: 0,
sample: 0,
enabled: false,
sample: 0,
timer: 0,
timer_period: 0,
length_counter: 0,
length_counter_halt: false,
linear_counter: 0,
linear_counter_reload: false,
}
}
pub fn write_timer_low(&mut self, value: u8) {
}
pub fn write_timer_high(&mut self, value: u8) {
}
pub fn write_counter(&mut self, value: u8) {
}
pub fn clock(&mut self) {
}
@ -43,4 +36,28 @@ impl Triangle {
pub fn clock_length_counter(&mut self) {
}
// $4008
pub fn write_counter(&mut self, value: u8) {
self.length_counter_halt = value >> 7 as bool;
self.counter_reload_value = (value << 1) >> 1;
}
// $400A
pub fn write_timer_low(&mut self, value: u8) {
self.timer_period &= 0b00000111_00000000;
self.timer_period |= value;
}
// $400B
pub fn write_timer_high(&mut self, value: u8) {
if self.enabled {
self.length_counter = super::LENGTH_COUNTER_TABLE[value as usize >> 3];
}
self.timer_period &= 0b00000000_11111111;
let timer_high = value & 0b0000_0111;
self.timer_period |= timer_high << 8;
self.linear_counter_reload = true;
}
}