;-------T-------T------------------------T----------------------------------;
;Name:      Palette Morph
;Author:    Paul Manias
;Copyright: DreamWorld Productions © 1996-1997.  Freely distributable.
;
;Fades in a 32 colour picture, 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"

	SECTION	"Morph",CODE

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

Start:	STARTGMS

	MOVEM.L	A0-A6/D1-D7,-(SP)
	move.l	GMSBase(pc),a6
	lea	PicFile(pc),a1
	moveq	#GETPALETTE|VIDEOMEM,d0
	CALL	LoadPicFile
	move.l	d0,Picture
	beq.s	.Error_Picture

	CALL	GetScreen
	move.l	d0,Screen
	beq.s	.Error_Screen

	move.l	Picture(pc),a0
	move.l	Screen(pc),a1
	move.l	PIC_Data(a0),GS_MemPtr1(a1)
	CALL	CopyStructure

	move.l	Screen(pc),a0
	CALL	AddScreen
	tst.l	d0
	beq.s	.Error_Screen

	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
;===========================================================================;

Screen:	dc.l	0
Picture	dc.l	0

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

PicFile	dc.b	"GMS:demos/data/PIC.Loading",0
	even

