Skip to content

Commit 8ee265b

Browse files
committed
2026-05-15 15:30:54
1 parent ca89ea9 commit 8ee265b

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

src/apu.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -305,38 +305,34 @@ impl Swp {
305305
}
306306
}
307307

308-
/// 15-bit LFSR with optional 7-bit feedback path for CH4.
308+
// 15-bit LFSR with optional 7-bit feedback path for CH4.
309309
struct Lfsr {
310310
n: u16,
311311
}
312312

313313
impl Lfsr {
314-
fn new() -> Self {
314+
fn power_up() -> Self {
315315
Self { n: 0x7fff }
316316
}
317317

318318
fn reload(&mut self) {
319319
self.n = 0x7fff;
320320
}
321321

322-
/// Returns true iff the new low bit is 1 (the channel outputs `~bit0`).
323-
fn step(&mut self, w7: bool) -> bool {
322+
// Returns true if the new low bit is 1 (the channel outputs ~bit0).
323+
fn step(&mut self, reg: &Reg) -> bool {
324324
let b = ((self.n ^ (self.n >> 1)) & 1) as u16;
325325
self.n = (self.n >> 1) | (b << 14);
326-
if w7 {
326+
if reg.width7() {
327327
self.n = (self.n & !(1 << 6)) | (b << 6);
328328
}
329329
self.n & 1 == 0
330330
}
331331
}
332332

333-
// ────────────────────────────────────────────────────────────────────────────
334-
// Square channels.
335-
// ────────────────────────────────────────────────────────────────────────────
336-
337333
const DUTY: [u8; 4] = [0b0000_0001, 0b1000_0001, 0b1000_0111, 0b0111_1110];
338334

339-
/// CH1: square wave with sweep.
335+
// CH1: square wave with sweep.
340336
struct Sq1 {
341337
r: Reg,
342338
on: bool,
@@ -690,15 +686,15 @@ impl Ns {
690686
tmr: Tmr::power_up(8),
691687
lc: Lc::power_up(),
692688
env: Env::power_up(),
693-
lfsr: Lfsr::new(),
689+
lfsr: Lfsr::power_up(),
694690
blip: Blip::power_up(sr),
695691
}
696692
}
697693

698694
fn tick(&mut self, c: u32) {
699695
let v = i32::from(self.env.v);
700696
for _ in 0..self.tmr.step(c) {
701-
let hi = self.lfsr.step(self.r.width7());
697+
let hi = self.lfsr.step(&self.r);
702698
let a = if !self.on || self.env.v == 0 {
703699
0
704700
} else if hi {

0 commit comments

Comments
 (0)