;-------T-------T------------------------T----------------------------------;
;Colour List Example
;-------------------
;Colourlists are those nice colour gradients used in demos and games,
;usually  sitting in the background of your screen.  Colourlists are mostly
;good for getting more colours on screen than what there really is.
;Although  GMS allows you to do other screen effects based on raster lines,
;we'll just stick to changing colours in this demo.
;
;You can move the green colour bar by moving the joystick up and down.
;You will notice that if you move the green bar into the upper red bar,
;your bar will disappear.  This is because:
;
;	WAITLINE  95        ;Wait for line 95
;	WAITLINE 100        ;Wait for line 100
;	WAITLINE  90        ;Wait for line 90 <--Error! 
;
;Is not allowed.  The monitor beam travels down the screen, and so the
;UpdateRasterlist() routine will expect all lines to be in sequential order.
;Moving two colourbars into each other breaks this rule, causing the wait
;command to be ignored.  If you want to get around this, you will have to
;have just one large colourlist and sort your colours before each call to
;UpdateRasterlist().
;
;Similarly if you move the colour bar too far down the screen the hardware
;won't like it because lines > 311 don't exist.  It's up to you to be
;responsible enough to stop this from happening!
;
;Press FIRE to exit the demo.

	INCDIR	"INCLUDES:"
	INCLUDE	"games/games_lib.i"
	INCLUDE	"games/games.i"

CALL	MACRO
	jsr	_LVO\1(a6)
	ENDM

;===========================================================================;
;                             INITIALISE DEMO
;===========================================================================;

	SECTION	"Colourlist",CODE

	STARTGMS

Start:	MOVEM.L	A0-A6/D1-D7,-(SP)
	move.l	GMSBase(pc),a6
	lea	ScreenTags(pc),a0
	CALL	ShowScreen
	tst.l	d0
	beq.s	.Error_Screen

	CALL	InitJoyPorts

	bsr.s	Loop

.ReturnToDOS
	move.l	GMSBase(pc),a6
	move.l	Screen(pc),a0
	CALL	DeleteScreen
.Error_Screen
	MOVEM.L	(SP)+,A0-A6/D1-D7
	moveq	#ERR_OK,d0
	rts

;===========================================================================;
;                                MAIN LOOP
;===========================================================================;

Loop:	move.l	Screen(pc),a0
	moveq	#JPORT1,d0
	CALL	ReadMouse
	btst	#MB_LMB,d0
	bne.s	.done
	ext.w	d0
	lea	Bar2(pc),a1
	add.w	d0,2(a1)
.chkhi	cmp.w	#226,2(a1)
	blt.s	.chklo
	move.w	#226,2(a1)
.chklo	tst.w	2(a1)
	bgt.s	.update
	clr.w	2(a1)
.update	CALL	UpdateRasterLines	;Update our rasterlist.
	CALL	WaitVBL
	bra.s	Loop
.done	rts

;===========================================================================;
;                                  DATA
;===========================================================================;

ScreenTags:
	dc.l	TAGS_GAMESCREEN
Screen:	dc.l	0
	dc.l	GSA_Rasterlist,Rasterlist
	dc.l	GSA_Planes,1
	dc.l	GSA_Attrib,BLKBDR
	dc.l	TAGEND

;===========================================================================;

RasterList:
Bar1:	COLOURLIST 000,3,00,ColourBar1	;Line, Skip, Colnum, ColourList.
Bar2:	COLOURLIST 160,1,00,ColourBar2	;Line, Skip, Colnum, ColourList.
	COLOURLIST 230,1,00,ColourBar3	;Line, Skip, Colnum, ColourList.
	RASTEND

ColourBar1:
	dc.l	$100000,$200000,$300000,$400000,$500000
	dc.l	$600000,$700000,$800000,$900000,$a00000
	dc.l	$b00000,$c00000,$d00000,$e00000,$e00000
	dc.l	$e00000,$d00000,$c00000,$b00000,$a00000
	dc.l	$900000,$800000,$700000,$600000,$500000
	dc.l	$400000,$300000,$200000,$100000,$000000
	dc.l	-1

ColourBar2:
	dc.l	$001000,$002000,$003000,$004000,$005000
	dc.l	$006000,$007000,$008000,$009000,$00a000
	dc.l	$00b000,$00c000,$00d000,$00e000,$00f000
	dc.l	$00e000,$00d000,$00c000,$00b000,$00a000
	dc.l	$009000,$008000,$007000,$006000,$005000
	dc.l	$004000,$003000,$002000,$001000,$000000
	dc.l	-1

ColourBar3:
	dc.l	$000010,$000020,$000030,$000040,$000050
	dc.l	$000060,$000070,$000080,$000090,$0000a0
	dc.l	$0000b0,$0000c0,$0000d0,$0000e0,$0000f0
	dc.l	$0000e0,$0000d0,$0000c0,$0000b0,$0000a0
	dc.l	$000090,$000080,$000070,$000060,$000050
	dc.l	$000040,$000030,$000020,$000010,$000000
	dc.l	-1

