If the goal is illustration would ditching the loop help? Instead of a very "opaque" table of values, you'd get something you could lightly annotate:
Code: Select all
init_apu:
lda #$40
sta $4017 ; disable APU IRQ
lda #$00
sta $4015 ; disable all channels
lda #$30
sta $4000 ; initialize squares
sta $4004
sta $400C ; initialize noise
lda #$80
sta $4008 ; initialize triangle
lda #$08
sta $4001 ; disable sweep
sta $4005
lda #$00
sta $4002 ; set low pitch to 0
sta $4006
sta $400A
sta $400E
sta $4003 ; set high pitch to 0
sta $4007
sta $400B
sta $400F
sta $4010 ; initialize DMC
sta $4011
sta $4012
sta $4013
lda #$0F
sta $4015 ; enable all channels
rts
The loop saves a few bytes and/or lines of code, but for teaching purposes it makes everything that it's actually doing pretty obscure. You could skip the pitch setting in this example, too, if you wanted to make it shorter (initialized pitch isn't important to the examples, AFAIK).
I think the "don't mess with this" statement that follows the code is more vexing than the code itself, though:
This writes values that are most useful for basic use of the channels. It's not important exactly what they do, just that they establish a known state. Be careful: if you alter this code, the APU might not behave in the simpler way described on this page.
I don't think telling someone that "it's not important" or not to alter this code is helpful; it kind of gives the impression that this is mysterious and understanding shouldn't be attempted, similar to how I felt about "the skinny about NES scrolling" being presented as this advanced and unapproachable knowledge. I think something like this would suffice:
The initialization above will prepare the APU to a known state, ready to be used by the examples below.
Someone who doesn't think they understand that code wouldn't try to alter it anyway, you don't need to pre-load them with an expectation that it's hard to understand to prevent this. Just let them look it up and learn if they're interested.