Master the fundamental concepts of emulation through this focused micro-challenge.
The Audio Processing Unit mixes two pulse channels, triangle, noise, and DMC sample playback. Even silent emulation must advance APU timers in sync with CPU cycles or some games hang waiting for length counters.
Pulse 1 and 2:
Triangle, noise, DMC occupy \`0x4008-0x4013\` and \`0x4010-0x4013\`.
Frame sequencer clocks envelopes and sweeps at 240 Hz (4-step mode).
For example, setting pulse 1 timer low registers plays a square wave near 440 Hz when the game writes note values each frame.
\`\`\`c apu_tick(cpu_cycles); // must run every CPU cycle batch \`\`\`
Length counters silence channels even when the timer still runs. Games depend on automatic note cutoff; skipping length clocking produces notes that never end.
This exercise asks you to model APU register writes and timer stepping. You will advance sound channels in lockstep with the CPU so ROMs that synchronize on APU state do not deadlock.
You will use the same mental model here when reading production interpreter source later in the track. Sketch one concrete input on paper, predict the outcome, then confirm with code. That discipline catches logic errors early and makes debugging far faster when you extend the implementation in follow-on tasks.
Document NES APU concepts in C.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github