Page 1 of 1

Learning the APU

Posted: Wed Oct 24, 2018 3:46 pm
by battagline
I'm messing around with the APU, and I'm running into a problem.

I wrote / stole this little macro to play notes out of a note table:

Code: Select all

.macro play_note note
    .local @play_note_end

    lda note_countdown
    bne @play_note_end

    lda #80
    sta note_countdown

    lda #%00000001
    sta $4015 ;enable square 1

    lda note
    tay
    lda note_table, y
    sta $4002
    iny
    lda note_table, y
    sta $4003

    @play_note_end:

.endmacro
The only problem is after the note plays it seems to play again over and over

kind of like this:
beeeeeeeeeeeeep [nothing] beep [nothing] beep

So what am I failing to understand about the APU?

Thanks

Re: Learning the APU

Posted: Wed Oct 24, 2018 4:09 pm
by lidnariq
What are you writing to $4000 and $4001?

Re: Learning the APU

Posted: Wed Oct 24, 2018 5:49 pm
by battagline
lidnariq wrote:What are you writing to $4000 and $4001?
I wrote to $4000 earlier in the code to set the volume. I have a different macro that writes to $4001. I'm not sure what the sweep is supposed to do. Does that modify the tone or the volume. I played with that register a little and I'm not exactly sure what it does.

Thanks

Re: Learning the APU

Posted: Wed Oct 24, 2018 6:01 pm
by lidnariq
If you write the wrong value to $4000 - something with the $20s bit = "C"onstant Volume bit clear - you'll get a sound that repeatedly goes from maximum volume to minimum volume until the length counter times out.

But that's the only way the hardware would be doing anything like what you're describing. If that's not it, your problem has to be something your code is doing.



Relatedly, the "correct" value to write to $4001 is 8, unless you intend on using the hardware pitch sweeps.