We're putting the band back together!
I've never attempted to write a music engine or really look into one. It wasn't that hard but I bet someone knows a more efficient and/or fancy way to do it. (Yes I know my table is inside the loop but its just easier to look at that way for now. Also I snagged the note values from Kirk Israel) I haven't quite figured out why I get a high pitched beep when the song repeats either.
MusicRoutine: dec NoteDuration ; Have we gone 30 or 60 frames yet? bne OSwait ; If not, then skip to the end inc NoteCounter ; Go to the next note inc NoteCounter ; Twice because durations are in the table as well ldx NoteCounter ; Put the note location in the index lda Tune,x ; Load the frequency sta AUDF0 ; Store the frequency lda Tune,x+1 ; Load the duration sta NoteDuration ; Store the new duration in RAM lda NoteCounter ; See if its time to repeat the song cmp #72 ; 36 notes plus 36 note durations beq ResetCounter ; if so, reset the counter jmp OSwait ; Don't reset the counter ResetCounter lda #0 sta NoteCounter jmp OSwait Tune: ; 35 notes and pauses .byte 0,0,24,30,27,30,30,30,27,30,24,28,-1,2,24,28,-1,2,24,60 ;9 notes .byte 27,28,-1,2,27,28,-1,2,27,60,24,30,20,28,-1,2,20,60 ;9 .byte 24,30,27,30,30,30,27,30,24,28,-1,2,24,28,-1,2,24,28,-1,2 ;10 .byte 24,30,27,28,-1,2,27,30,24,30,27,30,30,120 ;7 OSwait: