!animation_states = 3 !ticks_next_bar = $0F00 !curr_bar_index = $0F02 !loop_bar_index = $0F03 init: REP #$20 STZ !curr_bar_index ; STZ !loop_bar_index LDA music_bars STA !ticks_next_bar SEP #$20 main: REP #$20 ; read apu i/o 0-1 again if it's fucked until it isn't - LDA $2140 CMP $2140 BNE - CMP !ticks_next_bar BMI .return ; flip on/off ; SEP #$20 ; LDA $14AF ; EOR #$01 ; STA $14AF ; LDA #$0B ; STA $1DF9 ; REP #$20 ; cycle through the animation states SEP #$20 LDA $7FC070 INC CMP.b #!animation_states BCC + TDC + STA $7FC070 REP #$20 ; handle the next bar LDX !curr_bar_index INX INX LDA music_bars,x BNE .check_track_end ; place song loop start on next bar INX INX STX !loop_bar_index LDA music_bars,x BRA .update_stuff .check_track_end: BPL .update_stuff ; the track ended so go back to the loop point (or the start) LDX !loop_bar_index LDA music_bars,x .update_stuff: CLC ADC !ticks_next_bar STA !ticks_next_bar STX !curr_bar_index .return: SEP #$20 RTL ; how to: ; the duration of each bar is expressed in ticks ; use $0000 at the start of the loop point (if there's one) ; use $FFFF at the end of the track so it can loop back !quarter = $0030 !quarterdot = $0048 music_bars: dw !quarter, !quarter, !quarterdot dw $FFFF