style: code refactoring

This commit is contained in:
2022-10-10 20:31:12 -03:00
parent dc7cad9691
commit bcacac64df
9 changed files with 65 additions and 89 deletions

View File

@@ -25,22 +25,6 @@ pub fn sample(self: *const Self) i8 {
return if ((~self.shift & 1) == 1) 1 else -1;
}
/// Update the sate of the Channel Length TImer
pub fn updateLength(_: *Self, fs: *const FrameSequencer, ch4: *Noise, nr44: io.NoiseControl) void {
// Write to NRx4 when FS's next step is not one that clocks the length counter
if (!fs.isLengthNext()) {
// If length_enable was disabled but is now enabled and length timer is not 0 already,
// decrement the length timer
if (!ch4.cnt.length_enable.read() and nr44.length_enable.read() and ch4.len_dev.timer != 0) {
ch4.len_dev.timer -= 1;
// If Length Timer is now 0 and trigger is clear, disable the channel
if (ch4.len_dev.timer == 0 and !nr44.trigger.read()) ch4.enabled = false;
}
}
}
/// Reload LFSR Timer
pub fn reload(self: *Self, poly: io.PolyCounter) void {
self.sched.removeScheduledEvent(.{ .ApuChannel = 3 });

View File

@@ -21,23 +21,6 @@ pub fn init(sched: *Scheduler) Self {
};
}
/// Updates the State of either Ch1 or Ch2's Length Timer
pub fn updateLength(_: *const Self, comptime T: type, fs: *const FrameSequencer, ch: *T, nrx34: io.Frequency) void {
comptime std.debug.assert(T == ToneSweep or T == Tone);
// Write to NRx4 when FS's next step is not one that clocks the length counter
if (!fs.isLengthNext()) {
// If length_enable was disabled but is now enabled and length timer is not 0 already,
// decrement the length timer
if (!ch.freq.length_enable.read() and nrx34.length_enable.read() and ch.len_dev.timer != 0) {
ch.len_dev.timer -= 1;
// If Length Timer is now 0 and trigger is clear, disable the channel
if (ch.len_dev.timer == 0 and !nrx34.trigger.read()) ch.enabled = false;
}
}
}
/// Scheduler Event Handler for Square Synth Timer Expire
pub fn onSquareTimerExpire(self: *Self, comptime T: type, nrx34: io.Frequency, late: u64) void {
comptime std.debug.assert(T == ToneSweep or T == Tone);

View File

@@ -77,19 +77,3 @@ pub fn shift(_: *const Self, nr32: io.WaveVolume) u2 {
0b11 => 2, // 25% Volume
};
}
/// Update state of Channel 3 Length Device
pub fn updateLength(_: *Self, fs: *const FrameSequencer, ch3: *Wave, nrx34: io.Frequency) void {
// Write to NRx4 when FS's next step is not one that clocks the length counter
if (!fs.isLengthNext()) {
// If length_enable was disabled but is now enabled and length timer is not 0 already,
// decrement the length timer
if (!ch3.freq.length_enable.read() and nrx34.length_enable.read() and ch3.len_dev.timer != 0) {
ch3.len_dev.timer -= 1;
// If Length Timer is now 0 and trigger is clear, disable the channel
if (ch3.len_dev.timer == 0 and !nrx34.trigger.read()) ch3.enabled = false;
}
}
}