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

	opt	o+

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

	SECTION	"AGAFade",CODE

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

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

	lea	Picture(pc),a1
	move.l	GS_MemPtr1(a0),PIC_Data(a1)
	CALL	LoadPic
	tst.w	d0
	bne.s	.Error_Picture

	CALL	Show_Screen

	bsr.s	Main

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

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

Main:	lea	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
	moveq	#32,d4
.f_in	CALL	Wait_OSVBL
	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	Wait_Time

	moveq	#$00,d0	;d0 = FadeState
	moveq	#2,d1	;d1 = Speed of fade.
	lea	MorphPalette(pc),a2	;a2 = Destination Palette.
.f_mid	CALL	Wait_OSVBL
	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	Wait_Time

	moveq	#$00,d0	;d0 = FadeState
	moveq	#2,d1	;d1 = Speed of fade.
	lea	MorphPalette(pc),a1
	moveq	#$000000,d2
.f_out	CALL	Wait_OSVBL
	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	Wait_Time
	rts

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

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

AMT_PLANES =	5

Screen:	dc.l	GSV1,0
	dc.l	0,0,0	;Screen_Mem1/2/3
	dc.l	0	;Screen link.
	dc.l	0	;Address of palette.
	dc.l	0	;Address of rasterlist.
	dc.l	32	;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 of planes.
	dc.w	0,0	;X/Y screen offsets.
	dc.w	0,0	;X/Y picture offsets.
	dc.l	0	;Special attributes.
	dc.w	LORES|COL24BIT	;Screen mode.
	dc.b	INTERLEAVED	;Screen type
	dc.b	0	;Reserved.
	even

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

Picture	dc.l	PCV1,0	;Version header.
	dc.l	0	;Source data.
	dc.w	320/8,256	;Width, Height.
	dc.w	AMT_PLANES	;Amount of Planes.
	dc.l	32	;Amount of colours.
	dc.l	0	;Source palette.
	dc.w	LORES|COL24BIT	;Screen mode.
	dc.w	INTERLEAVED	;Destination
	dc.l	GETPALETTE	;Parameters.
	dc.l	.File
.File	dc.b	"GAMESLIB:data/IFF.Loading",0
	even
