n6 wrote:
When writing to an APU port is it updated immediatly or is everything updated each frame? is it the same for all ports?
Immediately for all ports. $4017 is a little bit special in this regard in that when it is written to, the
APU Frame is reset (note: the APU frame is 100% unrelated to the PPU frame -- in fact I dislike the use of the term "frame" and prefer to just call that part of the APU the "Sequencer")
Quote:
2. If ive understand it correctly the square channels and the triangle lenghts are decremented once per frame and when it reached 0 it should stop
Not every frame -- see the sequencer takes another step though the sequence every so many cycles. On certain steps... certain parts of the APU (such as length, linear, decay, sweep, etc) get clocked.
The Length unit for each channel gets clocked on two of the steps. In the 4-step sequence, this means it will be clocked roughly 120 times every second.
Your understanding of the length unit is correct though -- it simply counts down until it reaches 0, at which point it silences the channel.
Quote:
I don't understand how to implement the linear counter for the triangle channel, infact I don't understand what it is.
The Linear Counter is more or less the same idea as the Length Counter -- except it provides a higher resolution and is clocked more often (roughly 240 times every second instead of 120). When enabled, it too will simply count down until it hits 0, at which point the Tri will be silenced.
Blargg's APU docs cover the details on it pretty well -- if it's still hazy, try rereading it a few times until it clicks.
Quote:
3. When sweep is enabled is it updated once per frame?
Like Length/Linear/Decay, the sweep is clocked by the sequencer.
The CPU clock rate (1789772.7272 cycles/sec) drives each channel's frequency divider, which in turn drives each channel's "shape" (duty cycle for the squares, tri-step for the tri, pRNG for the Noise), which is what actually generates the tone of the channel. All other "sub systems" of the channels: Length, Linear, Sweep, Decay are driven by the sequencer.