Skip to content

Commit e43c437

Browse files
committed
2026-05-15 12:29:11
1 parent 5196e23 commit e43c437

1 file changed

Lines changed: 17 additions & 21 deletions

File tree

src/apu.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -258,22 +258,18 @@ impl RegCh4 {
258258
}
259259
}
260260

261-
// ────────────────────────────────────────────────────────────────────────────
262-
// Channel sub-units.
263-
// ────────────────────────────────────────────────────────────────────────────
264-
265-
/// 6-bit / 8-bit length counter. Returns true from `clock` iff the channel
266-
/// must be disabled (decrement to zero with length-enable set).
261+
// Length counter. Returns true from step if the channel must be disabled (decrement to zero with
262+
// length-enable set).
267263
struct Lc {
268264
n: u16,
269265
}
270266

271267
impl Lc {
272-
fn new() -> Self {
268+
fn power_up() -> Self {
273269
Self { n: 0 }
274270
}
275271

276-
fn clock(&mut self, en: bool) -> bool {
272+
fn step(&mut self, en: bool) -> bool {
277273
if en && self.n != 0 {
278274
self.n -= 1;
279275
self.n == 0
@@ -283,7 +279,7 @@ impl Lc {
283279
}
284280
}
285281

286-
/// Volume envelope (CH1/CH2/CH4).
282+
// Volume envelope (CH1/CH2/CH4).
287283
struct Env {
288284
t: Tmr,
289285
v: u8,
@@ -437,7 +433,7 @@ impl Sq1 {
437433
r: RegCh1::power_up(),
438434
on: false,
439435
tmr: Tmr::power_up(8192),
440-
lc: Lc::new(),
436+
lc: Lc::power_up(),
441437
env: Env::new(),
442438
swp: Swp::new(),
443439
blip: Blip::power_up(sr),
@@ -486,7 +482,7 @@ impl Sq1 {
486482
let old_en = self.r.r.len_en();
487483
self.r.r.n[4] = v;
488484
self.tmr.p = self.r.period();
489-
if xtra && !old_en && self.r.r.len_en() && self.lc.clock(true) {
485+
if xtra && !old_en && self.r.r.len_en() && self.lc.step(true) {
490486
self.on = false;
491487
}
492488
if v & 0x80 != 0 {
@@ -539,7 +535,7 @@ impl Sq2 {
539535
r: RegCh2::power_up(),
540536
on: false,
541537
tmr: Tmr::power_up(8192),
542-
lc: Lc::new(),
538+
lc: Lc::power_up(),
543539
env: Env::new(),
544540
blip: Blip::power_up(sr),
545541
idx: 1,
@@ -582,7 +578,7 @@ impl Sq2 {
582578
let old_en = self.r.r.len_en();
583579
self.r.r.n[4] = v;
584580
self.tmr.p = self.r.period();
585-
if xtra && !old_en && self.r.r.len_en() && self.lc.clock(true) {
581+
if xtra && !old_en && self.r.r.len_en() && self.lc.step(true) {
586582
self.on = false;
587583
}
588584
if v & 0x80 != 0 {
@@ -648,7 +644,7 @@ impl Wv {
648644
r: RegCh3::power_up(),
649645
on: false,
650646
tmr: Tmr::power_up(8192),
651-
lc: Lc::new(),
647+
lc: Lc::power_up(),
652648
blip: Blip::power_up(sr),
653649
ram: [0; 16],
654650
idx: 0,
@@ -696,7 +692,7 @@ impl Wv {
696692
let old_en = self.r.r.len_en();
697693
self.r.r.n[4] = v;
698694
self.tmr.p = self.r.period();
699-
if xtra && !old_en && self.r.r.len_en() && self.lc.clock(true) {
695+
if xtra && !old_en && self.r.r.len_en() && self.lc.step(true) {
700696
self.on = false;
701697
}
702698
if v & 0x80 != 0 {
@@ -767,7 +763,7 @@ impl Ns {
767763
r: RegCh4::power_up(),
768764
on: false,
769765
tmr: Tmr::power_up(8),
770-
lc: Lc::new(),
766+
lc: Lc::power_up(),
771767
env: Env::new(),
772768
lfsr: Lfsr::new(),
773769
blip: Blip::power_up(sr),
@@ -809,7 +805,7 @@ impl Ns {
809805
fn write_nrx4(&mut self, v: u8, xtra: bool) {
810806
let old_en = self.r.r.len_en();
811807
self.r.r.n[4] = v;
812-
if xtra && !old_en && self.r.r.len_en() && self.lc.clock(true) {
808+
if xtra && !old_en && self.r.r.len_en() && self.lc.step(true) {
813809
self.on = false;
814810
}
815811
if v & 0x80 != 0 {
@@ -1249,16 +1245,16 @@ impl Ticker for Apu {
12491245

12501246
let s = self.fs.step();
12511247
if Fseq::len(s) {
1252-
if self.ch1.lc.clock(self.ch1.r.r.len_en()) {
1248+
if self.ch1.lc.step(self.ch1.r.r.len_en()) {
12531249
self.ch1.on = false;
12541250
}
1255-
if self.ch2.lc.clock(self.ch2.r.r.len_en()) {
1251+
if self.ch2.lc.step(self.ch2.r.r.len_en()) {
12561252
self.ch2.on = false;
12571253
}
1258-
if self.ch3.lc.clock(self.ch3.r.r.len_en()) {
1254+
if self.ch3.lc.step(self.ch3.r.r.len_en()) {
12591255
self.ch3.on = false;
12601256
}
1261-
if self.ch4.lc.clock(self.ch4.r.r.len_en()) {
1257+
if self.ch4.lc.step(self.ch4.r.r.len_en()) {
12621258
self.ch4.on = false;
12631259
}
12641260
}

0 commit comments

Comments
 (0)