*************************************************
*
*	Colour cycling routine
*
*	Copyright free
*
*	Written by Martin Jones
*
*	To be called on the Vblank
*	Incbin the palette file you require
*	Colcyc governs whether the routine is
*	running
*
*************************************************


colcycle	move.w colcyc,d0	cycle the colours
	bne colc1		colour table located
	rts		at (colstart)
colc1	move.l colstart,a0	defined as:
	move.l a0,a1	
	add.l #6,a1		1b cycle (0=no)
	lea $dff180,a2	1b position of colour
	move.l #32,d7	1b speed (1=50 per sec)
colc6	sub.l #1,d7		1b limit (highest colour)
	bpl colc2		1b speed pos (counter)
	rts		1b nothing (even)
colc2	move.b (a0),d0	64w colour info
	bne colc3		
	move.b #0,1(a0)	next colour
	jmp colc5
colc3	add.b #1,4(a0)
	move.b 4(a0),d1
	move.b 2(a0),d2
	cmp.b d1,d2
	bne colc5
	move.b #0,4(a0)
	move.b 1(a0),d1
	move.b 3(a0),d2
	cmp.b d1,d2
	beq colc4
	add.b #1,1(a0)
	jmp colc5
colc4	move.b #0,1(a0)
colc5	move.b 1(a0),d0
	and.b #$ff,d0
	mulu #2,d0
	move.w (a1,d0),(a2)
	add.l #134,a0
	add.l #134,a1
	add.l #2,a2
	jmp colc6
	
colstart	dc.l palette
colcyc	dc.w 1

palette	incbin "ram:palette"


