RAM_SPRITEBG EQU $FF8000
RAM_SPRITEPOS EQU $FF9000

Circles:

   
   move.w #$8114, vdpcontrol
   ; move.w #$8551, vdpcontrol
   ; move.w #$8c00, vdpcontrol
    ;move.w #$8D2B, VDPCONTROL
    setvramaddr 32, vdpcontrol
    
    lea (CircleTiles), a0
    lea (vdpdata), a1
    move.w #$180*32/4-1, d0
@CopyCircles
    move.l (a0)+, (a1)
    dbf d0, @CopyCircles
	
    setvramaddr $1A0*32+5*32, vdpcontrol
    
    lea (Foreground), a0
    lea (vdpdata), a1
    move.w #364*32/4-1, d0
@CopyBorder
    move.l (a0)+, (a1)
    dbf d0, @CopyBorder
	
    move.w #$8174, vdpcontrol
    
    
    
    singledmavram CircleBGMAp, $E000, 28*64*2, vdpcontrol
	
	
    
    ;HSCROLL = AC00
         singledmacram Pal2, 0,128, vdpcontrol
		 
		 setcramaddr 0, vdpcontrol
		 move.w #$0000, vdpdata
    
 ;   move.w #%0000000110000000, ($C0001c) ; UNDOCUMENTED TEST REGISTER :D
    
    move.w #8*5*2*8/4-1, d0
    lea SpriteBG, a0
    lea RAM_SpriteBG, a1
@LoadTable
    move.l (a0)+, (a1)+
    dbf d0, @LoadTable

    setvramaddr $F800, VDPCONTROL
    move.w #224-1, d0
@LDSCROLL:
    move.w #0, (VDPDATA)
    move.w #96, (VDPDATA)
    dbf d0, @LDSCROLL
	
    setvsramaddr $0, VDPCONTROL
    move.w #0, VDPDATA
    
    singledmavram Borders+5*4*4*32*2, $400*32, 4*4*32*18, vdpcontrol
    
    
    move.w #$8B03, VDPCONTROL
    
    setvramaddr $C000, vdpcontrol
    
    lea (CircleFGMAP+128), a0
    lea (vdpdata), a1
    move.w #64*2*28/2-1, d0
@CopyFGMAP
    move.w (a0)+, d1
    add.w #$1A0, d1
    or.w #%0110000000000000, d1
    move.w d1, (a1)
    dbf d0, @CopyFGMAP
	
    move.w #$8174, vdpcontrol
	lea sines2, a0
    lea cosine2, a1
    lea ram_spritebg, a2
    lea ram_spritepos, a3
    
    move.w #80-1, d0
    move.l #256, d2
@CopySpriteData
    move.w 6(a2), (a3)+
    move.w (a2), (a3)+
    lea 8(a2), a2
    dbf d0, @CopySpriteData
    
	
	move.w #$8F04, VDPCONTROL
;	SETVRAMADDR $F802+200*4, VDPCONTROL
;	rept 24/2
;	move.w #256+96, (VDPDATA)
;	move.w #-25+96, (VDPDATA)
;	endr
	move.w #$8F02, VDPCONTROL
	move.w #127, (RAM_AmountScroll)
    moveq #0, d7

@SPRTLOOP
    lea ram_spritebg+32*8, a2
    lea ram_spritepos+32*4, a3
    move.w (a0, d7.w), d6		;; 1st poll
    move.w (a1, d7.w), d5    	;; 
    move.w #24-1, d1
@UpdateData
    move.w (a3)+, d4    ;x
    move.w (a3)+, d3    ;y
    
    ADD.W d6, d4
    ADD.W d5, d3
    
    move.w d4, 6(a2)
    move.w d3, (a2)
    lea 8(a2),a2
    
    dbf d1, @UpdateData

    move.w (a0, d2.w), d6	;; 2nd poll
    move.w (a1, d2.w), d5    
    
    cmp.w #0, d5
    ble.s @NoCorrect
    move.b #52, (RAM_SpriteBG+8*51+3)
    move.b #80, (RAM_SpriteBG+8*(51+24)+3)
    bra.s @continue
@NoCorrect
    move.b #32+24, (RAM_SpriteBG+8*51+3)
    move.b #76, (RAM_SpriteBG+8*(51+24)+3)
@Continue 

    move.w #24-1, d1
@UpdateData2
    move.w (a3)+, d4    ;x
    move.w (a3)+, d3    ;y
    
    ADD.W d6, d4
    ADD.W d5, d3
    
   
    move.w d4, 6(a2)
    move.w d3, (a2)
    lea 8(a2),a2
    
    dbf d1, @UpdateData2

	
    jsr UpdateText
	bsr UpdateCycle
    addq.w #1, (RAM_FRAMECNT)
	and.w #2047, (RAM_FRAMECNT)
	
    
    singledmaVRAM RAM_SpriteBG, $F000, 8*5*2*8,vdpcontrol
    
    addq.w #4, d7
    and.w #%0000000111111111, d7
    addq.w #4, d2
    and.w #%0000000111111111, d2 
    ; d7 = index
    waitframe
    echo_z80request
    move.b ($A01200), d0
    move.b #0, ($A01200)
    echo_z80release
    tst.b d0
    bne.w @LetsEnd
	
    bra.w @SPRTLOOP
@LetsEnd:


	rts
	
UpdateCycle:
    movem.l  d0/a0, -(SP)
	move.w (RAM_FRaMECNT), d0
	and.w #$FE, d0
	lea (pallettecycle), a0
	setcramaddr 2, VDPCONTROL
	move.w (a0,d0.w), VDPDATA
	add.w #32, d0
	setcramaddr 64+2, VDPCONTROL
	move.w (a0,d0.w), VDPDATA
	
    movem.l (SP)+, d0/a0
	rts
RAM_GreetzID: EQU $FF1000 ; WORD
RAM_FRAMECNT: EQU $FF1002 ; WORD
RAM_AmountScroll: EQU $FF1004 ; WORD
RAM_CurrentAction: EQU $FF1005 ; BYTE 0=nothing 1= gfx onscreen, 2= gfx scrolling off,  3= scrolling on
    
UpdateText:
;   0 RELOAD
;	1-128 SCROLL IN
;   128-208 STAY
;   208-336 SCROLL OUT, set 0
;   REDO

    movem.l  d0-d4/a0-a4, -(SP)
	move.w (RAM_FRAMECNT), d0
	
	cmp.w #336, d0
	ble.s @DontReload
	clr.w (RAM_FRAMECNT)
	clr.w d0
@DontReload:
	tst.w d0
	beq.w PutGFX
	cmp.w #64, d0
	ble.w ScrollIn
	cmp.w #128, d0
	ble.w Stay
	cmp.w #192, d0
	ble.w ScrollOut
    movem.l (SP)+, d0-d4/a0-a4
	rts
ScrollOut:
	move.w #$8F04, VDPCONTROL
	move.w (RAM_AmountScroll), d0
	move.w d0, d1
	neg.w d1
	add.w #96, d0
	add.w #96, d1
	SETVRAMADDR $F802+200*4, VDPCONTROL
	rept 24/2
	move.w d0, (VDPDATA)
	move.w d1, (VDPDATA)
	endr
	addq.w #4, (RAM_AmountScroll)
	move.w #$8F02, VDPCONTROL
    movem.l (SP)+, d0-d4/a0-a4
	rts
Stay:
    movem.l (SP)+, d0-d4/a0-a4
	rts

ScrollIn:
	move.w #$8F04, VDPCONTROL
	move.w (RAM_AmountScroll), d0
	move.w d0, d1
	neg.w d1
	add.w #96, d0
	add.w #96, d1
	SETVRAMADDR $F802+200*4, VDPCONTROL
	rept 24/2
	move.w d0, (VDPDATA)
	move.w d1, (VDPDATA)
	endr
	subq.w #4, (RAM_AmountScroll)
	move.w #$8F02, VDPCONTROL
    movem.l (SP)+, d0-d4/a0-a4
	rts
PutGFX:
	 move.w RAM_GreetzID, d1
    lea (Greetz), a0
    lea (a0, d1.w), a0
    SETVRAMADDR $5D0*32, VDPCONTROL
    lea (VDPDATA), a1
    move.w #16*3*32/4-1, d1
@updateGFX:
    move.l (a0)+, (a1)
    dbf d1, @updateGFX
 ;  move.w #224, (RAM_AmountScroll)

	
    add.w #16*3*32, (RAM_GreetzID)
@NoMove
    movem.l (SP)+, d0-d4/a0-a4
    rts
    
EmptyTile:
    rept 16
    
    hex ffffffff
    hex ffffffff
    hex ffffffff
    hex ffffffff
    hex ffffffff
    hex ffffffff
    hex ffffffff
    hex ffffffff
    
    endr
    align 131072
SpriteBG:
; ECKPUNKTE
    
    ; Oben links
   
x = 0	
	while x<5
    dc.w 128 
    dc.b %00001111, x+1
    dc.w %1000000000000000|($400+x*4*4)
    dc.w 128+80+x*32+1
x = x+1
    endw
x = 0	
	while x<5
    dc.w 128+5*32
    dc.b %00001111, x+1+5
    dc.w %1000000000000000|($400+(x+13)*4*4)
    dc.w 128+80+x*32+1
x = x+1
    endw
	
    dc.w 128+1*32
    dc.b %00001111, 11
    dc.w %1000000000000000|($400+5*4*4)
    dc.w 128+80+1
    dc.w 128+2*32
    dc.b %00001111, 12
    dc.w %1000000000000000|($400+7*4*4)
    dc.w 128+80+1
    dc.w 128+3*32
    dc.b %00001111, 13
    dc.w %1000000000000000|($400+9*4*4)
    dc.w 128+80+1
    dc.w 128+4*32
    dc.b %00001111, 14
    dc.w %1000000000000000|($400+11*4*4)
    dc.w 128+80+1
	
	
	
    dc.w 128+1*32
    dc.b %00001111, 15
    dc.w %1000000000000000|($400+6*4*4)
    dc.w 128+80+4*32+1
    dc.w 128+2*32
    dc.b %00001111, 16
    dc.w %1000000000000000|($400+8*4*4)
    dc.w 128+80+4*32+1
    dc.w 128+3*32
    dc.b %00001111, 17
    dc.w %1000000000000000|($400+10*4*4)
    dc.w 128+80+4*32+1
    dc.w 128+4*32
    dc.b %00001111, 18
    dc.w %1000000000000000|($400+12*4*4)
    dc.w 128+80+4*32+1
	
	
    
    dc.w 0
    dc.b %00001111, 32
    dc.w %1000000000000000|0
    dc.w 0
	
    align 32*8
y   = 0
    while y<6
x   = 0
    while x<4 
    dc.w 128+y*32
    dc.b %00001111, 32+y*4+x+1
    dc.w %0000000000000000|1+(y*4+x)*16
    dc.w 128+96+x*32+1
    
x   = x+1
   endw

	
y   = y+1
    endw

y   = 0
    while y<6
x   = 0
    while x<4 
    dc.w 128+y*32
    dc.b %00001111, 32+24+y*4+x+1
    dc.w %1100000000000000|1+(y*4+x)*16
    dc.w 128+96+x*32+1
    
x   = x+1
    endw
    
y   = y+1
    endw    
    
    align 131072
CircleBGMap:
    incbin ./circles/circlebg.map

    even
CircleTiles:
    incbin ./circles/circles.bin
    even
CircleMaps:
    incbin ./circles/circles.map
    even
    
Foreground:
	incbin ./circles/fg.bin
	even
CircleFgMAP:
	incbin ./circles/fg.map
	even

borders:
    incbin ./circles/border.bin

    even
Sines2:
    incbin ./circles/SINE.BIN

    even
CoSine2:
    incbin ./circles/COSINE.BIN
FilledTile:
    rept 4*8
    hex 11111111
    endr
Pal2:
    incbin ./circles/border.pal
    dc.w $0000, $0468, $02e6, $0844, $0248, $0c64, $0442, $088e 
    dc.w $0e20, $02a2, $048a, $08c8, $04a6, $0c4a, $0a46, $0EEE 
    incbin ./circles/greetz.pal
	incbin ./circles/fg.pal

PalletteCycle:
	incbin ./circles/cycle.pal
	incbin ./circles/cycle.pal
	
	incbin ./circles/cycle.pal
	incbin ./circles/cycle.pal
	
Greetz:
    incbin ./circles/greetz.bin
    incbin ./circles/greetz.bin
    incbin ./circles/greetz.bin
    incbin ./circles/greetz.bin
    incbin ./circles/greetz.bin
    incbin ./circles/greetz.bin
    even