style: improve code quality

This commit is contained in:
2022-10-12 22:57:44 -03:00
parent 785135a074
commit 21eddac31e
9 changed files with 139 additions and 131 deletions

View File

@@ -67,12 +67,12 @@ pub fn tick(self: *Self, comptime kind: Tick) void {
}
/// NR41, NR42
pub fn getSoundCntL(self: *const Self) u16 {
pub fn sound4CntL(self: *const Self) u16 {
return @as(u16, self.envelope.raw) << 8;
}
/// NR41, NR42
pub fn setSoundCntL(self: *Self, value: u16) void {
pub fn setSound4CntL(self: *Self, value: u16) void {
self.setNr41(@truncate(u8, value));
self.setNr42(@truncate(u8, value >> 8));
}
@@ -90,12 +90,12 @@ pub fn setNr42(self: *Self, value: u8) void {
}
/// NR43, NR44
pub fn getSoundCntH(self: *const Self) u16 {
pub fn sound4CntH(self: *const Self) u16 {
return @as(u16, self.poly.raw & 0x40) << 8 | self.cnt.raw;
}
/// NR43, NR44
pub fn setSoundCntH(self: *Self, fs: *const FrameSequencer, value: u16) void {
pub fn setSound4CntH(self: *Self, fs: *const FrameSequencer, value: u16) void {
self.poly.raw = @truncate(u8, value);
self.setNr44(fs, @truncate(u8, value >> 8));
}

View File

@@ -68,12 +68,12 @@ pub fn onToneEvent(self: *Self, late: u64) void {
}
/// NR21, NR22
pub fn getSoundCntL(self: *const Self) u16 {
pub fn sound2CntL(self: *const Self) u16 {
return @as(u16, self.envelope.raw) << 8 | (self.duty.raw & 0xC0);
}
/// NR21, NR22
pub fn setSoundCntL(self: *Self, value: u16) void {
pub fn setSound2CntL(self: *Self, value: u16) void {
self.setNr21(@truncate(u8, value));
self.setNr22(@truncate(u8, value >> 8));
}
@@ -91,12 +91,12 @@ pub fn setNr22(self: *Self, value: u8) void {
}
/// NR23, NR24
pub fn getSoundCntH(self: *const Self) u16 {
pub fn sound2CntH(self: *const Self) u16 {
return self.freq.raw & 0x4000;
}
/// NR23, NR24
pub fn setSoundCntH(self: *Self, fs: *const FrameSequencer, value: u16) void {
pub fn setSound2CntH(self: *Self, fs: *const FrameSequencer, value: u16) void {
self.setNr23(@truncate(u8, value));
self.setNr24(fs, @truncate(u8, value >> 8));
}

View File

@@ -78,18 +78,18 @@ pub fn onToneSweepEvent(self: *Self, late: u64) void {
}
/// NR10, NR11, NR12
pub fn setSoundCnt(self: *Self, value: u32) void {
self.setSoundCntL(@truncate(u8, value));
self.setSoundCntH(@truncate(u16, value >> 16));
pub fn setSound1Cnt(self: *Self, value: u32) void {
self.setSound1CntL(@truncate(u8, value));
self.setSound1CntH(@truncate(u16, value >> 16));
}
/// NR10
pub fn getSoundCntL(self: *const Self) u8 {
pub fn sound1CntL(self: *const Self) u8 {
return self.sweep.raw & 0x7F;
}
/// NR10
pub fn setSoundCntL(self: *Self, value: u8) void {
pub fn setSound1CntL(self: *Self, value: u8) void {
const new = io.Sweep{ .raw = value };
if (self.sweep.direction.read() and !new.direction.read()) {
@@ -104,12 +104,12 @@ pub fn setSoundCntL(self: *Self, value: u8) void {
}
/// NR11, NR12
pub fn getSoundCntH(self: *const Self) u16 {
pub fn sound1CntH(self: *const Self) u16 {
return @as(u16, self.envelope.raw) << 8 | (self.duty.raw & 0xC0);
}
/// NR11, NR12
pub fn setSoundCntH(self: *Self, value: u16) void {
pub fn setSound1CntH(self: *Self, value: u16) void {
self.setNr11(@truncate(u8, value));
self.setNr12(@truncate(u8, value >> 8));
}
@@ -127,12 +127,12 @@ pub fn setNr12(self: *Self, value: u8) void {
}
/// NR13, NR14
pub fn getSoundCntX(self: *const Self) u16 {
pub fn sound1CntX(self: *const Self) u16 {
return self.freq.raw & 0x4000;
}
/// NR13, NR14
pub fn setSoundCntX(self: *Self, fs: *const FrameSequencer, value: u16) void {
pub fn setSound1CntX(self: *Self, fs: *const FrameSequencer, value: u16) void {
self.setNr13(@truncate(u8, value));
self.setNr14(fs, @truncate(u8, value >> 8));
}

View File

@@ -60,24 +60,24 @@ pub fn tick(self: *Self, comptime kind: Tick) void {
}
/// NR30, NR31, NR32
pub fn setSoundCnt(self: *Self, value: u32) void {
self.setSoundCntL(@truncate(u8, value));
self.setSoundCntH(@truncate(u16, value >> 16));
pub fn setSound3Cnt(self: *Self, value: u32) void {
self.setSound3CntL(@truncate(u8, value));
self.setSound3CntH(@truncate(u16, value >> 16));
}
/// NR30
pub fn setSoundCntL(self: *Self, value: u8) void {
pub fn setSound3CntL(self: *Self, value: u8) void {
self.select.raw = value;
if (!self.select.enabled.read()) self.enabled = false;
}
/// NR31, NR32
pub fn getSoundCntH(self: *const Self) u16 {
pub fn sound3CntH(self: *const Self) u16 {
return @as(u16, self.length & 0xE0) << 8;
}
/// NR31, NR32
pub fn setSoundCntH(self: *Self, value: u16) void {
pub fn setSound3CntH(self: *Self, value: u16) void {
self.setNr31(@truncate(u8, value));
self.vol.raw = (@truncate(u8, value >> 8));
}
@@ -89,7 +89,7 @@ pub fn setNr31(self: *Self, len: u8) void {
}
/// NR33, NR34
pub fn setSoundCntX(self: *Self, fs: *const FrameSequencer, value: u16) void {
pub fn setSound3CntX(self: *Self, fs: *const FrameSequencer, value: u16) void {
self.setNr33(@truncate(u8, value));
self.setNr34(fs, @truncate(u8, value >> 8));
}