;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  the games.library 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
;Update_RasterList 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
;Update_RasterList.
;
;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.

	opt	o+,c+

	INCLUDE	"exec/exec_lib.i"
	INCLUDE	"games/games_lib.i"
	INCLUDE	"games/games.i
CALL	MACRO
	jsr	_LVO\1(a6)
	ENDM

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

	SECTION	"ColourList",CODE

Start:	MOVEM.L	A0-A6/D1-D7,-(SP)
	move.l	($4).w,a6
	lea	GMS_Name(pc),a1
	moveq	#$00,d0
	CALL	OpenLibrary
	move.l	d0,GMS_Base
	beq.s	.Error_GMS

	move.l	GMS_Base(pc),a6
	sub.l	a0,a0
	CALL	SetUserPrefs

	lea	Screen(pc),a0
	CALL	Add_Screen
	tst.l	d0
	bne.s	.Error_Screen

	CALL	Show_Screen

	moveq	#JPORT1,d0	;Port 1
	CALL	Read_Mouse	;Initialise the port.

	bsr.s	Loop

.ReturnToDOS
	move.l	GMS_Base(pc),a6
	lea	Screen(pc),a0
	CALL	Delete_Screen
.Error_Screen
	move.l	GMS_Base(pc),a1
	move.l	($4).w,a6
	CALL	CloseLibrary
.Error_GMS
	MOVEM.L	(SP)+,A0-A6/D1-D7
	moveq	#$00,d0
	rts

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

Loop:	moveq	#JPORT1,d0	;Port 1
	CALL	Read_Mouse
	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	Update_RasterLines	;Update our rasterlist.
	CALL	Wait_OSVBL
	bra.s	Loop
.done	rts

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

GMS_Name:
	dc.b	"games.library",0
	even
GMS_Base:
	dc.l	0

AMT_PLANES =	5

Screen:	dc.l	GSV1,0	;Structure version.
	dc.l	0,0,0	;Screen_Mem1/2/3
	dc.l	0	;Screen link.
	dc.l	0	;Address of screen palette.
	dc.l	RasterList	;Address of rasterlist.
	dc.l	0	;Amt of colours in palette.
	dc.w	320,256	;Screen Width and Height
	dc.w	320/8,256	;Picture Width/8 and Height.
	dc.w	AMT_PLANES	;Amt_Planes
	dc.w	0,0	;X/Y screen offset.
	dc.w	0,0	;X/Y picture offset.
	dc.l	BLKBDR	;Special attributes.
	dc.w	LORES|COL12BIT	;Screen mode.
	dc.b	INTERLEAVED	;Screen type
	dc.b	0	;Reserved
	even

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

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

ColourBar1:
	dc.w	$100,$200,$300,$400,$500,$600,$700,$800,$900,$a00
	dc.w	$b00,$c00,$d00,$e00,$e00,$e00,$d00,$c00,$b00,$a00
	dc.w	$900,$800,$700,$600,$500,$400,$300,$200,$100,$000
	dc.w	-1

ColourBar2:
	dc.w	$010,$020,$030,$040,$050,$060,$070,$080,$090,$0a0
	dc.w	$0b0,$0c0,$0d0,$0e0,$0f0,$0e0,$0d0,$0c0,$0b0,$0a0
	dc.w	$090,$080,$070,$060,$050,$040,$030,$020,$010,$000
	dc.w	-1

ColourBar3:
	dc.w	$001,$002,$003,$004,$005,$006,$007,$008,$009,$00a
	dc.w	$00b,$00c,$00d,$00e,$00f,$00e,$00d,$00c,$00b,$00a
	dc.w	$009,$008,$007,$006,$005,$004,$003,$002,$001,$000
	dc.w	-1
