From 739d38533a670a262295f46e4fe32215be27ee67 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:13:04 -0300 Subject: [PATCH] style(scheduler): rename scheduler event handlers --- src/core/apu.zig | 4 ++-- src/core/apu/Noise.zig | 2 +- src/core/apu/Tone.zig | 2 +- src/core/apu/ToneSweep.zig | 2 +- src/core/apu/Wave.zig | 2 +- src/core/bus/gpio.zig | 2 +- src/core/bus/timer.zig | 2 +- src/core/ppu.zig | 4 ++-- src/core/scheduler.zig | 18 +++++++++--------- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/core/apu.zig b/src/core/apu.zig index e5880be..9ad8d1c 100644 --- a/src/core/apu.zig +++ b/src/core/apu.zig @@ -373,7 +373,7 @@ pub const Apu = struct { return @as(u64, 1) << (15 + @as(u6, cycle)); } - pub fn tickFrameSequencer(self: *Self, late: u64) void { + pub fn onSequencerTick(self: *Self, late: u64) void { self.fs.tick(); switch (self.fs.step) { @@ -403,7 +403,7 @@ pub const Apu = struct { self.ch4.tickEnvelope(); } - pub fn handleTimerOverflow(self: *Self, cpu: *Arm7tdmi, tim_id: u3) void { + pub fn onDmaAudioSampleRequest(self: *Self, cpu: *Arm7tdmi, tim_id: u3) void { if (!self.cnt.apu_enable.read()) return; if (@boolToInt(self.dma_cnt.chA_timer.read()) == tim_id) { diff --git a/src/core/apu/Noise.zig b/src/core/apu/Noise.zig index fd8e30a..a3ad7bd 100644 --- a/src/core/apu/Noise.zig +++ b/src/core/apu/Noise.zig @@ -128,7 +128,7 @@ pub fn setNr44(self: *Self, fs: *const FrameSequencer, byte: u8) void { self.cnt = new; } -pub fn channelTimerOverflow(self: *Self, late: u64) void { +pub fn onNoiseEvent(self: *Self, late: u64) void { self.lfsr.onLfsrTimerExpire(self.poly, late); self.sample = 0; diff --git a/src/core/apu/Tone.zig b/src/core/apu/Tone.zig index 3b4b7f5..3044f4f 100644 --- a/src/core/apu/Tone.zig +++ b/src/core/apu/Tone.zig @@ -58,7 +58,7 @@ pub fn tickEnvelope(self: *Self) void { self.env_dev.tick(self.envelope); } -pub fn channelTimerOverflow(self: *Self, late: u64) void { +pub fn onToneEvent(self: *Self, late: u64) void { self.square.onSquareTimerExpire(Self, self.freq, late); self.sample = 0; diff --git a/src/core/apu/ToneSweep.zig b/src/core/apu/ToneSweep.zig index 8af7efb..60d73bd 100644 --- a/src/core/apu/ToneSweep.zig +++ b/src/core/apu/ToneSweep.zig @@ -71,7 +71,7 @@ pub fn tickEnvelope(self: *Self) void { self.env_dev.tick(self.envelope); } -pub fn channelTimerOverflow(self: *Self, late: u64) void { +pub fn onToneSweepEvent(self: *Self, late: u64) void { self.square.onSquareTimerExpire(Self, self.freq, late); self.sample = 0; diff --git a/src/core/apu/Wave.zig b/src/core/apu/Wave.zig index 9a64657..64738a1 100644 --- a/src/core/apu/Wave.zig +++ b/src/core/apu/Wave.zig @@ -116,7 +116,7 @@ pub fn setNr34(self: *Self, fs: *const FrameSequencer, byte: u8) void { self.freq = new; } -pub fn channelTimerOverflow(self: *Self, late: u64) void { +pub fn onWaveEvent(self: *Self, late: u64) void { self.wave_dev.onWaveTimerExpire(self.freq, self.select, late); self.sample = 0; diff --git a/src/core/bus/gpio.zig b/src/core/bus/gpio.zig index 03c7690..c5d8dce 100644 --- a/src/core/bus/gpio.zig +++ b/src/core/bus/gpio.zig @@ -288,7 +288,7 @@ pub const Clock = struct { cpu.sched.push(.RealTimeClock, 1 << 24); // Every Second } - pub fn updateTime(self: *Self, late: u64) void { + pub fn onClockUpdate(self: *Self, late: u64) void { self.cpu.sched.push(.RealTimeClock, (1 << 24) -| late); // Reschedule const now = DateTime.now(); diff --git a/src/core/bus/timer.zig b/src/core/bus/timer.zig index 7273f1a..72f232a 100644 --- a/src/core/bus/timer.zig +++ b/src/core/bus/timer.zig @@ -154,7 +154,7 @@ fn Timer(comptime id: u2) type { // DMA Sound Things if (id == 0 or id == 1) { - cpu.bus.apu.handleTimerOverflow(cpu, id); + cpu.bus.apu.onDmaAudioSampleRequest(cpu, id); } // Perform Cascade Behaviour diff --git a/src/core/ppu.zig b/src/core/ppu.zig index 8c10999..d1b3f11 100644 --- a/src/core/ppu.zig +++ b/src/core/ppu.zig @@ -562,7 +562,7 @@ pub const Ppu = struct { }; } - pub fn handleHDrawEnd(self: *Self, cpu: *Arm7tdmi, late: u64) void { + pub fn onHdrawEnd(self: *Self, cpu: *Arm7tdmi, late: u64) void { // Transitioning to a Hblank if (self.dispstat.hblank_irq.read()) { cpu.bus.io.irq.hblank.set(); @@ -578,7 +578,7 @@ pub const Ppu = struct { self.sched.push(.HBlank, 68 * 4 -| late); } - pub fn handleHBlankEnd(self: *Self, cpu: *Arm7tdmi, late: u64) void { + pub fn onHblankEnd(self: *Self, cpu: *Arm7tdmi, late: u64) void { // The End of a Hblank (During Draw or Vblank) const old_scanline = self.vcount.scanline.read(); const scanline = (old_scanline + 1) % 228; diff --git a/src/core/scheduler.zig b/src/core/scheduler.zig index 9369a2d..e58c66e 100644 --- a/src/core/scheduler.zig +++ b/src/core/scheduler.zig @@ -43,7 +43,7 @@ pub const Scheduler = struct { .Draw => { // The end of a VDraw cpu.bus.ppu.drawScanline(); - cpu.bus.ppu.handleHDrawEnd(cpu, late); + cpu.bus.ppu.onHdrawEnd(cpu, late); }, .TimerOverflow => |id| { switch (id) { @@ -55,10 +55,10 @@ pub const Scheduler = struct { }, .ApuChannel => |id| { switch (id) { - 0 => cpu.bus.apu.ch1.channelTimerOverflow(late), - 1 => cpu.bus.apu.ch2.channelTimerOverflow(late), - 2 => cpu.bus.apu.ch3.channelTimerOverflow(late), - 3 => cpu.bus.apu.ch4.channelTimerOverflow(late), + 0 => cpu.bus.apu.ch1.onToneSweepEvent(late), + 1 => cpu.bus.apu.ch2.onToneEvent(late), + 2 => cpu.bus.apu.ch3.onWaveEvent(late), + 3 => cpu.bus.apu.ch4.onNoiseEvent(late), } }, .RealTimeClock => { @@ -66,12 +66,12 @@ pub const Scheduler = struct { if (device.kind != .Rtc or device.ptr == null) return; const clock = @ptrCast(*Clock, @alignCast(@alignOf(*Clock), device.ptr.?)); - clock.updateTime(late); + clock.onClockUpdate(late); }, - .FrameSequencer => cpu.bus.apu.tickFrameSequencer(late), + .FrameSequencer => cpu.bus.apu.onSequencerTick(late), .SampleAudio => cpu.bus.apu.sampleAudio(late), - .HBlank => cpu.bus.ppu.handleHBlankEnd(cpu, late), // The end of a HBlank - .VBlank => cpu.bus.ppu.handleHDrawEnd(cpu, late), // The end of a VBlank + .HBlank => cpu.bus.ppu.onHblankEnd(cpu, late), // The end of a HBlank + .VBlank => cpu.bus.ppu.onHdrawEnd(cpu, late), // The end of a VBlank } } }