wavevtx:
        la      a6,VTX_GRID|$A0000000
        la      a1,sintable
        lw      d6,wavesin
        li      d0,6-1
@loop3                   

        move    a0,a6
        li      d1,6-1
@loop2                    ;one column left side
        andi    d5,d6,$1ff
        li      d2,2-1
@loop1                    ;one tile
        sll     d7,d5,2
        addu    a2,a1,d7
        lw      d7,0(a2)
        lw      d8,waveamplitude
        multu   d7,d8
        mflo    d7
        sra     d7,16
        sh      d7,4(a0)
        addu    a0,4*4*3
        addu    d5,0     ;tri speed
        andi    d5,$1ff
        bnez    d2,@loop1
        addu    d2,-1

        addu    a0,6*(4*4*4)-(2*4*4*3)
        bnez    d1,@loop2
        addu    d1,-1

        addu    a0,a6,4*4
        addu    d6,40     ;speed
        li      d1,6-1
@loop2a                    ;one column right side
        andi    d5,d6,$1ff
        li      d2,2-1
@loop1a                    ;one tile
        sll     d7,d5,2
        addu    a2,a1,d7
        lw      d7,0(a2)
        lw      d8,waveamplitude
        multu   d7,d8
        mflo    d7
        sra     d7,16
        sh      d7,4(a0)
        addu    a0,4*4*1
        bnez    d2,@loop1a
        addu    d2,-1

        addu    a0,6*(4*4*4)-(2*4*4*1)
        bnez    d1,@loop2a
        addu    d1,-1

;        addu    d6,-20

        addu    a6,4*4*4
        bnez    d0,@loop3
        addu    d0,-1

        lw      d6,wavesin
        addu    d6,4    ;overall speed
        sw      d6,wavesin
        jr      ra
        nop

wavesin dw      0
waveamplitude   dw 0 ;60

