style(apu): split apu.zig into multiple files + refactor
This commit is contained in:
28
src/core/apu/device/Envelope.zig
Normal file
28
src/core/apu/device/Envelope.zig
Normal file
@@ -0,0 +1,28 @@
|
||||
const io = @import("../../bus/io.zig");
|
||||
|
||||
const Self = @This();
|
||||
|
||||
/// Period Timer
|
||||
timer: u3,
|
||||
/// Current Volume
|
||||
vol: u4,
|
||||
|
||||
pub fn create() Self {
|
||||
return .{ .timer = 0, .vol = 0 };
|
||||
}
|
||||
|
||||
pub fn tick(self: *Self, nrx2: io.Envelope) void {
|
||||
if (nrx2.period.read() != 0) {
|
||||
if (self.timer != 0) self.timer -= 1;
|
||||
|
||||
if (self.timer == 0) {
|
||||
self.timer = nrx2.period.read();
|
||||
|
||||
if (nrx2.direction.read()) {
|
||||
if (self.vol < 0xF) self.vol += 1;
|
||||
} else {
|
||||
if (self.vol > 0x0) self.vol -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user