;audio.asm

dosound
;handle audio 0
   lda snd0dur
   bne :ss0
   lda snd0adr+1
   bne :oks0
   lda #0
   sta AUDF1
   sta AUDC1
   beq :dones0 ;always
:oks0
   ldy #0
   lda (snd0adr),y
   cmp #254
   bcc :sfreq0
   beq :setv0
   lda #0
   sta snd0adr+1
   beq :dones0
:setv0
   iny
   lda (snd0adr),y
   eor #160
   sta snd0vol
   jmp :incadr0
:sfreq0
   sta AUDF1
   lda snd0vol
   sta AUDC1
   iny
   lda (snd0adr),y
   sta snd0dur
:incadr0
   lda snd0adr
   clc
   adc #2
   sta snd0adr
   bcc *+2+2
   inc snd0adr+1
   bne :dones0 ;always
:ss0
   dec snd0dur
:dones0

;handle audio 1
   lda snd1dur
   bne :ss1
   lda snd1adr+1
   bne :oks1
   lda #0
   sta AUDF2
   sta AUDC2
   beq :dones1 ;always
:oks1
   ldy #0
   lda (snd1adr),y
   cmp #254
   bcc :sfreq1
   beq :setv1
   lda #0
   sta snd1adr+1
   beq :dones1
:setv1
   iny
   lda (snd1adr),y
   eor #160
   sta snd1vol
   jmp :incadr1
:sfreq1
   sta AUDF2
   lda snd1vol
   sta AUDC2
   iny
   lda (snd1adr),y
   sta snd1dur
:incadr1
   lda snd1adr
   clc
   adc #2
   sta snd1adr
   bcc *+2+2
   inc snd1adr+1
   bne :dones1 ;always
:ss1
   dec snd1dur
:dones1
   rts


