;* Play the SFX currently set in memory, one frame every VBI
play_sfx
lda #$FF ; #$00 -> Play SFX until it's ended, #$FF -> SFX has finished playing and is stopped
is_playing_sfx equ *-1
bmi play_sfx_done
lda #2 ; 2 frames
sta is_playing_sfx
lda #0
sfx_offset equ *-1
asl @
tax
inc sfx_offset
lda #0
sfx_channel equ *-1
asl @
tay
bpl begin_play_sfx
play_sfx_loop
inx
iny
begin_play_sfx
lda $ffff,x
sfx_src equ *-2
sta SDWPOK0,y
dec is_playing_sfx
bne play_sfx_loop
lda SDWPOK0,y
bne play_sfx_done
dec is_playing_sfx
play_sfx_done
rts
;-----------------