;-------T-------T------------------------T----------------------------------;
;Name:      Green Fade
;Author:    Paul Manias
;Copyright: DreamWorld Productions © 1996-1997.  Freely distributable.
;
;Fades in a 32 colour picture, then up to a specified colour (greenish
;yellow), and then out to black.  Press left mouse button to exit.

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

	SECTION	"GreenFade",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

	move.l	Picture(pc),a1
	lea	ScreenTags(pc),a0
	move.l	PIC_Data(a1),GMem
	CALL	ShowScreen
	tst.l	d0
	beq.s	.Error_Screen

	bsr.s	Main

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

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

Main:	move.l	Screen(pc),a0	;a0 = GameScreen
	moveq	#$00,d0	;d0 = FadeState
	moveq	#5,d1	;d1 = Speed of fade.
	move.l	Picture(pc),a1	;a1 = Picture structure.
	move.l	PIC_Palette(a1),a1	;a1 = Palette to fade to.
	moveq	#$000000,d2	;d2 = Fading from black.
	moveq	#00,d3	;d3 = Start colour.
	move.l	GS_AmtColours(a0),d4	;d4 = Amount of colours.
.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	#2,d1	;d1 = Speed of fade.
	move.l	Picture(pc),a1	;a1 = Picture structure.
	move.l	PIC_Palette(a1),a1	;a1 = Palette we are fading from.
	move.l	#$75F343,d2	;d2 = Colour we are fading to.
.f_mid	CALL	WaitVBL
	CALL	PaletteToColour	;Do the fade routine.
	tst.w	d0	;Has the fade finished yet?
	bne.s	.f_mid	;If not, keep doing it.

	moveq	#2,d1	;d1 = Speed of fade.
	move.l	#$a5F343,d2	;d2 = Colour.
	moveq	#$000000,d5	;d5 = Colour.
.f_out	CALL	WaitVBL
	CALL	ColourMorph	;Do the fade routine.
	tst.w	d0	;Has the fade finished yet?
	bne.s	.f_out	;If not, keep doing it.
	rts

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

ScreenTags:
	dc.l	TAGS_GAMESCREEN
Screen:	dc.l	0
	dc.l	GSA_MemPtr1
GMem:	dc.l	0
	dc.l	GSA_AmtColours,32
	dc.l	GSA_ScrWidth,320
	dc.l	GSA_ScrHeight,256
	dc.l	TAGEND

Picture	dc.l	0

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

