TwistHBL:
        SetVSRAMAddr 0, VDPControl
        move.w (a2)+, VDPDATA
        move.w (a6)+, VDPDATA
        rte
TwistHBL_End:
twistVBL:
        clr.w (RAM_HCount)
        lea (RAM_ScrollTable), a2
        lea (RAM_ScrollTable+512), a6
                SetVSRAMAddr 0, VDPControl
        move.w (a2)+, VDPDATA
        move.w (a6)+, VDPDATA
        move.w #0, VDPDATA
        rte
        
Twister

        DISABLEINTS

        move.l #twistVBL, (RAM_VINTLOC+2)
        move.w #$8B0B, (VDPControl)
        lea (twistHBL), a0
        lea (RAM_HInt), a1
        move.l #((twistHBL_End-twistHBL)/2)-1,d0   
@CopyHINT:
        move.w (a0)+, (a1)+
        dbf d0, @CopyHINT 

        SingleDMAVRAM twisterTiles, 0, 229*32, VDPControl
        SingleDMAVRAM twisterMap, $C000, 64*64*2, VDPControl
        SingleDMACRAM twisterPal, 0, 32, VDPControl 
   
        ENABLEINTS
        
        
    move.w #$9011, (VDPCONTROL)
    move.w #$8D20, (VDPCONTROL)
    move.w #$8520, (VDPCONTROL)
	moveq #0, d0
	moveq #0, d1
	moveq #0, d2
	moveq #0, d3
	moveq #0, d4
	moveq #0, d5
	moveq #0, d6
	move.w #$F0, d6 
	moveq #0, d7
	lea (SINETWISTER2), a1
	lea (SINETWISTER), a0 ; Cosine
        lea (RAM_Scrolltable), a3
        lea (RAM_Scrolltable), a5

     
    
	move.w #224-1, d1
	moveq #0, d4   
        moveq #0, d2
    
    lea (a0), a4
    move.w #$9011, (VDPCONTROL)
    move.w #$8b00, (VDPCONTROL)
    
     setvramaddr $8000, VDPCONTROL
     move.w #50, VDPDATA
    
@Start:
        move.w #224-1, d1
        lea (RAM_ScrollTable), a3
        moveq #0, d2

        lea (a1, d0.w), a4
@start2
        move.w (A4)+, d3
        
        
        add.w d2, d3
        
        add.w (a0, d4.w), d3
        neg.w d3
        
        addq.b #1, d2
        move.w d3, (a3)+
        dbf d1, @start2
        
        
        WaitFrame
        
        Echo_z80request
        move.b ($A01200), d3
        move.b #0, ($A01200)
        echo_z80release
        tst.b d3
        bne.w Twister2
        
        addq.w #4, d4
        cmp.w #$600, d4
        bne.s @checkd0
        moveq #0, d4
@checkd0
        add.w #12, d0        
        cmp.w #1536, d0
        bne.w @Start
        moveq #0, d0
        bra @Start
@Plasma_End:
        rts

        
Twister2:
        
    move.w #$9011, (VDPCONTROL)
    move.w #$8b00, (VDPCONTROL)
	moveq #0, d0
	moveq #0, d1
	moveq #0, d2
	moveq #0, d3
	moveq #0, d4
	moveq #0, d5
	moveq #0, d6
	move.w #$F0, d6 
	moveq #0, d7
    disableints
    singledmavram twister2tiles, $110*32, 343*32, VDPCONTROL
    lea (Twister2MAP), a0
    setvramaddr $E000, vdpcontrol
    move.w #64*64-1, d0
@COPYMAP
    move.w (a0)+, d1
    add.w #$110, d1
    or.w #%0010000000000000, d1
    move.w d1, (VDPDATA)
    dbf d0, @COPYMAP
    moveq #0, d0
    
    
    singledmacram twister2pal, 32, 32, vdpcontrol
	lea (SINETWISTER2), a1
	lea (SINETWISTER), a0 ; Cosine

    
    enableints
	move.w #224-1, d1
	moveq #0, d4   
        moveq #0, d2
    
    lea (a0), a4
    
@Start:

	lea (SINETWISTER2), a1
	lea (SINETWISTER), a0 ; Cosine
        
        lea (RAM_Scrolltable), a3

        move.w #224-1, d1
        lea (a1, d0.w), a4
        moveq #0, d2
@start2
        move.w (A4)+, d3
        add.w d2, d3
        add.w (a0, d4.w), d3
        neg.w d3        
        addq.b #1, d2
        move.w d3, (a3)+
        dbf d1, @start2
        move.w #224-1, d1
        moveq #0, d2
        lea (RAM_Scrolltable+512), a3
	lea (SINETWISTER2+512), a1
	lea (SINETWISTER+256), a0 ; Cosine
        lea (a1, d0.w), a4
@start3
        move.w (A4)+, d3
        add.w d2, d3
        add.w (a0, d4.w), d3
        neg.w d3        
        addq.b #1, d2
        move.w d3, (a3)+
        dbf d1, @start3
        
        
        WaitFrame
        
        Echo_z80request
        move.b ($A01200), d3
        move.b #0, ($A01200)
        echo_z80release
        tst.b d3
        bne.w Twister_END
        
        addq.w #6, d4
        cmp.w #$600, d4
        bne.s @checkd0
        moveq #0, d4
@checkd0
        add.w #08, d0        
        cmp.w #1536, d0
        bne.w @Start
        moveq #0, d0
        bra @Start
Twister_END
    rts

    align 131072
twisterTiles:
        incbin ./gfx/twister.bin
twisterPal:
        incbin ./gfx/twister.pal
twisterMap:
        incbin ./gfx/twister.map
        incbin ./gfx/twister.map
twister2Tiles:
        incbin ./twister/twister2.bin
twister2Pal:
        incbin ./twister/twister2.pal
twister2Map:
        incbin ./twister/twister2.map

SINETWISTER:
        incbin ./twister/SINETWISTER.BIN
        incbin ./twister/SINETWISTER.BIN

SINETWISTER2:
        incbin ./twister/SINETWISTER2.BIN
        incbin ./twister/SINETWISTER2.BIN