Learning the APU

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
battagline
Posts: 152
Joined: Wed Sep 05, 2018 11:13 am
Location: Colorado
Contact:

Learning the APU

Post 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
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Learning the APU

Post by lidnariq »

What are you writing to $4000 and $4001?
User avatar
battagline
Posts: 152
Joined: Wed Sep 05, 2018 11:13 am
Location: Colorado
Contact:

Re: Learning the APU

Post 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
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Learning the APU

Post 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.
Post Reply