tick_length   =         880
sample_buffer   =       $80340000
updatesamplemusic:
                lw      t0,AI_STATUS_REG
                and     t0,$80000000 ;8
                bne     t0,zero,@no_refresh

                lw      t2,whatbuffer
                li      t3,880*4
                multu   t3,t2
                mflo    t3
                li      t4,sample_buffer|$A0000000
                addu    a1,t4,t3
                xori    t2,1
                sw      t2,whatbuffer

                lw      a0,current_sample
                lw      t0,current_pos
                addu    a0,t0
                li      t5,tick_length
@loop1          lb     t1,0(a0)
                sll     t1,8
                addu    a0,1
                sh      t1,0(a1)
                sh      t1,2(a1)
                addu    a1,4
                bnez    t5,@loop1
                addu    t5,-1



                lw      t1,current_pos
                lw      t2,end_sample
                subu    t4,t2,t1
                li      t3,tick_length*4
                addu    t6,t1,tick_length
                sw      t6,current_pos
                bgt     t4,tick_length,@here
                li      t5,1
                sw      r0,current_pos
                sw      t5,samplefinish
                move    t3,t4
                sll     t3,2
@here           LI      A0,$A4500000
                lw      t5,whatbuffer
                xori    t5,1
                li      t6,tick_length*4
                multu   t5,t6
                mflo    t5
                li      t7,sample_buffer|$A0000000
                addu    t5,t7
                sw      t5,0(A0)        ;AI_DRAM_ADDR_REG
                sw      t3,4(a0)        ;AI_LEN_REG
                li      t4,1
                sw      t4,8(a0)        ;ai_control
                lw      t5,dacrate
                sw      t5,$10(a0)      ;ai_dacrate
                lw      t6,bitrate
                sw      t6,$14(a0)      ;ai_bitrate


@no_refresh     jr      ra
                nop
Audio_INIT      
        lui     t0,$a450        ; init THE audio
        sw      r0,0(t0)
        li      t1,1
        sw      t1,8(t0)
        li      t1,$d000
        sw      t1,$10(t0)
        li      t1,1
        sw      t1,$14(t0)
        la      t1,0
        sw      t1,4(t0)
        jr      ra
        nop

whatbuffer:     dw      0
dacrate         dw      $C00  ;16 bit 16000 hz
bitrate         dw      $F
current_pos     dw      0
end_sample      dw      (endsample1-sample1)
current_sample  dw      sample1
samplefinish    dw      0
whatsample      dw      0

 
sample1
 incbin sample.raw      ;933
endsample1

sample2:
 incbin sample3.raw     ;931
endsample2:
sample3:
 incbin sample2.raw     ;928
endsample3:
sample4:
 incbin sample4.raw
endsample4:
