;-------T-------T------------------------T----------------------------------;
;AGA Palette Morph
;-----------------
;Fades in a 32 colour AGA picture (24 bit colour).  Then fades it into
;a second purple palette, and then out to black.
;
;Press left mouse button to exit.

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

CALL	MACRO
	jsr	_LVO\1(a6)
	ENDM

	SECTION	"AGAFade",CODE

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

	STARTGMS

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

	move.l	Screen(pc),a0
	lea	PictureTags(pc),a1
	move.l	GS_MemPtr1(a0),PicData
	CALL	LoadPic
	tst.l	d0
	beq.s	.Error_Picture

	CALL	ShowScreen

	bsr.s	Main

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

;===========================================================================;
;                                MAIN CODE
;===========================================================================;

Main:	move.l	Screen(pc),a0
	move.l	Picture(pc),a1
	move.l	PIC_Palette(a1),a1	;a1 = Palette to fade to.
	moveq	#$00,d0	;d0 = FadeState
	moveq	#5,d1	;d1 = Speed of fade.
	moveq	#$000000,d2
	moveq	#00,d3
	move.l	GS_AmtColours(a0),d4
.f_in	CALL	WaitVBL
	CALL	ColourToPalette	;Do the fade routine.
	tst.w	d0	;Has the fade finished yet?
	bne.s	.f_in	;If not, keep doing it.

	moveq	#50,d0
	CALL	WaitTime

	moveq	#$00,d0	;d0 = FadeState
	moveq	#2,d1	;d1 = Speed of fade.
	lea	MorphPalette(pc),a2	;a2 = Destination Palette.
.f_mid	CALL	WaitVBL
	CALL	PaletteMorph	;Do the fade routine.
	tst.w	d0	;Has the fade finished yet?
	bne.s	.f_mid	;If not, keep doing it.

	moveq	#50,d0
	CALL	WaitTime

	moveq	#$00,d0	;d0 = FadeState
	moveq	#2,d1	;d1 = Speed of fade.
	lea	MorphPalette(pc),a1
	moveq	#$000000,d2
.f_out	CALL	WaitVBL
	CALL	PaletteToColour	;Do the fade routine.
	tst.w	d0	;Has the fade finished yet?
	bne.s	.f_out	;If not, keep doing it.

	moveq	#50,d0
	CALL	WaitTime
	rts

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

ScreenTags:
	dc.l	TAGS_GAMESCREEN
Screen:	dc.l	0
	dc.l	GSA_AmtColours,32
	dc.l	GSA_ScrWidth,320
	dc.l	GSA_ScrHeight,256
	dc.l	GSA_Planes,5
	dc.l	GSA_ScrMode,LORES
	dc.l	TAGEND

MorphPalette:
	dc.l	$000000,$0A0107,$14020E,$1D0314
	dc.l	$27041B,$310522,$3B0629,$45082F
	dc.l	$4E0936,$580A3D,$620B44,$6C0C4A
	dc.l	$760D51,$800E58,$890F5F,$931066
	dc.l	$9D116C,$A71273,$B1137A,$BA1481
	dc.l	$C41687,$CE178E,$D81895,$E2199C
	dc.l	$EB1AA2,$F51BA9,$FF1CB0,$D71C9F
	dc.l	$557D55,$707082,$443300,$1E1E1E

PictureTags:
	dc.l	TAGS_PICTURE
Picture	dc.l	0
	dc.l	PCA_Data
PicData	dc.l	0
	dc.l	PCA_Width,320
	dc.l	PCA_Height,256
	dc.l	PCA_Planes,5
	dc.l	PCA_AmtColours,32
	dc.l	PCA_ScrMode,LORES
	dc.l	PCA_Options,GETPALETTE
	dc.l	PCA_File,.file
	dc.l	TAGEND
.file	dc.b	"GMS:demos/data/PIC.Loading",0
	even
