Compare commits
No commits in common. "109561310ed170e407d6f6e0a6a17acd23cd5a88" and "c9b0030b4b9b25df6566ce0104c40b0cd18665fe" have entirely different histories.
109561310e
...
c9b0030b4b
43
src/apu.zig
43
src/apu.zig
|
@ -966,20 +966,24 @@ const WaveDevice = struct {
|
|||
|
||||
fn reloadTimer(self: *Self, value: u11) void {
|
||||
self.sched.removeScheduledEvent(.{ .ApuChannel = 2 });
|
||||
const timer = (2048 - @as(u64, value)) * 4;
|
||||
self.timer = @truncate(u11, timer);
|
||||
|
||||
self.timer = (@as(u16, 2048) - value) * 2;
|
||||
self.sched.push(.{ .ApuChannel = 2 }, @as(u64, self.timer) * tickInterval);
|
||||
self.sched.push(.{ .ApuChannel = 2 }, (timer + 1) * tickInterval);
|
||||
}
|
||||
|
||||
fn handleTimerOverflow(self: *Self, cnt_freq: io.Frequency, cnt_sel: io.WaveSelect, late: u64) void {
|
||||
const timer = (2048 - @as(u64, cnt_freq.frequency.read())) * 2;
|
||||
|
||||
self.timer = @truncate(u12, timer);
|
||||
|
||||
if (cnt_sel.dimension.read()) {
|
||||
self.offset = (self.offset + 1) % 0x40; // 0x20 bytes (both banks), which contain 2 samples each
|
||||
} else {
|
||||
self.offset = (self.offset + 1) % 0x20; // 0x10 bytes, which contain 2 samples each
|
||||
}
|
||||
|
||||
self.timer = (@as(u16, 2048) - cnt_freq.frequency.read()) * 2;
|
||||
self.sched.push(.{ .ApuChannel = 2 }, @as(u64, self.timer) * tickInterval -| late);
|
||||
self.sched.push(.{ .ApuChannel = 2 }, (timer + 1) * tickInterval -| late);
|
||||
}
|
||||
|
||||
fn sample(self: *const Self, cnt: io.WaveSelect) u4 {
|
||||
|
@ -1042,7 +1046,7 @@ const SquareWave = struct {
|
|||
|
||||
pos: u3,
|
||||
sched: *Scheduler,
|
||||
timer: u16,
|
||||
timer: u12,
|
||||
|
||||
pub fn init(sched: *Scheduler) Self {
|
||||
return .{
|
||||
|
@ -1085,19 +1089,22 @@ const SquareWave = struct {
|
|||
}
|
||||
|
||||
fn handleTimerOverflow(self: *Self, comptime kind: ChannelKind, cnt: io.Frequency, late: u64) void {
|
||||
const timer = (2048 - @as(u64, cnt.frequency.read())) * 4;
|
||||
|
||||
self.timer = @truncate(u12, timer);
|
||||
self.pos +%= 1;
|
||||
|
||||
self.timer = (@as(u16, 2048) - cnt.frequency.read()) * 4;
|
||||
self.sched.push(.{ .ApuChannel = if (kind == .Ch1) 0 else 1 }, @as(u64, self.timer) * tickInterval -| late);
|
||||
self.sched.push(.{ .ApuChannel = if (kind == .Ch1) 0 else 1 }, (timer + 1) * tickInterval -| late);
|
||||
}
|
||||
|
||||
fn reloadTimer(self: *Self, comptime kind: ChannelKind, value: u11) void {
|
||||
self.sched.removeScheduledEvent(.{ .ApuChannel = if (kind == .Ch1) 0 else 1 });
|
||||
|
||||
const tmp = (@as(u16, 2048) - value) * 4; // What Freq Timer should be assuming no weird behaviour
|
||||
self.timer = (tmp & ~@as(u16, 0x3)) | self.timer & 0x3; // Keep the last two bits from the old timer;
|
||||
const tmp: u64 = (2048 - @as(u64, value)) * 4; // What Freq Timer should be assuming no weird behaviour
|
||||
const timer = (tmp & ~@as(u64, 0x3)) | self.timer & 0x3; // Keep the last two bits from the old timer
|
||||
self.timer = @truncate(u12, timer);
|
||||
|
||||
self.sched.push(.{ .ApuChannel = if (kind == .Ch1) 0 else 1 }, @as(u64, self.timer) * tickInterval);
|
||||
self.sched.push(.{ .ApuChannel = if (kind == .Ch1) 0 else 1 }, (timer + 1) * tickInterval);
|
||||
}
|
||||
|
||||
fn sample(self: *const Self, cnt: io.Duty) u1 {
|
||||
|
@ -1156,17 +1163,17 @@ const Lfsr = struct {
|
|||
self.sched.removeScheduledEvent(.{ .ApuChannel = 3 });
|
||||
|
||||
const div = Self.divisor(poly.div_ratio.read());
|
||||
const timer = div << poly.shift.read();
|
||||
self.sched.push(.{ .ApuChannel = 3 }, @as(u64, timer) * tickInterval);
|
||||
const timer = @as(u64, div << poly.shift.read());
|
||||
|
||||
self.sched.push(.{ .ApuChannel = 3 }, (timer + 1) * tickInterval);
|
||||
}
|
||||
|
||||
fn handleTimerOverflow(self: *Self, poly: io.PolyCounter, late: u64) void {
|
||||
// Obscure: "Using a noise channel clock shift of 14 or 15
|
||||
// results in the LFSR receiving no clocks."
|
||||
if (poly.shift.read() >= 14) return;
|
||||
|
||||
const div = Self.divisor(poly.div_ratio.read());
|
||||
const timer = div << poly.shift.read();
|
||||
const timer = @as(u64, div << poly.shift.read());
|
||||
|
||||
// Obscure: Clock Shift of 14 or 15 results in LSFR receiving no clocks
|
||||
if (poly.shift.read() > 14) return;
|
||||
|
||||
const tmp = (self.shift & 1) ^ ((self.shift & 2) >> 1);
|
||||
self.shift = (self.shift >> 1) | (tmp << 14);
|
||||
|
@ -1174,7 +1181,7 @@ const Lfsr = struct {
|
|||
if (poly.width.read())
|
||||
self.shift = (self.shift & ~@as(u15, 0x40)) | tmp << 6;
|
||||
|
||||
self.sched.push(.{ .ApuChannel = 3 }, @as(u64, timer) * tickInterval -| late);
|
||||
self.sched.push(.{ .ApuChannel = 3 }, (timer + 1) * tickInterval -| late);
|
||||
}
|
||||
|
||||
fn divisor(code: u3) u16 {
|
||||
|
|
Loading…
Reference in New Issue