;-------T-------T------------------------T----------------------------------;
;Name:      White Fade
;Author:    Paul Manias
;Copyright: DreamWorld Productions © 1996-1997.  Freely distributable.
;
;Fades the screen to white, then down to a palette, and exits with a fade
;to black.  This demo can load and fade any picture that you specify at
;the end of this file.
;
;Press left mouse button to exit.

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

	SECTION	"WhiteFade",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
	moveq	#$00,d0	;d0 = FadeState (reset).
	moveq	#5,d1	;d1 = Speed of fade.
	moveq	#$000000,d2	;d2 = Source colour
	move.l	#$ffffff,d5	;d5 = Destination colour.
	moveq	#00,d3	;d3 = Start colour
	move.l	GS_AmtColours(a0),d4	;d4 = Amount of colours.
.f_in	CALL	WaitVBL
	CALL	ColourMorph	;Do the fade routine.
	tst.w	d0	;Has the fade finished yet?
	bne.s	.f_in	;If not, keep doing it.

	moveq	#2,d1	;d1 = Speed of fade.
	move.l	Picture(pc),a1
	move.l	PIC_Palette(a1),a1	;a1 = Palette to fade to.
	move.l	#$ffffff,d2	;d2 = Colour we are fading from.
.f_mid	CALL	WaitVBL
	CALL	ColourToPalette	;Do the fade routine.
	tst.w	d0	;Has the fade finished yet?
	bne.s	.f_mid	;If not, keep doing it.

	moveq	#2,d1	;d0 = Speed of fade.
	move.l	Picture(pc),a1
	move.l	PIC_Palette(a1),a1	;a1 = Palette to fade to.
	moveq	#$000000,d2	;d2 = Destination colour.
.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	#20,d0
	CALL	WaitTime
	rts

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

Screen:	dc.l	0
Picture	dc.l	0

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

