;Fade Demo
;---------
;There are three examples of fading in this program:  Fade_To_White,
;Fade_To_Palette, and Fade_To_Black.
;
;Press fire to see the end of the fade sequence.

	opt	o+

	INCLUDE	"exec/exec_lib.i"
	INCLUDE	"games/games_lib.i"
	INCLUDE	"games/games.i

CALL	MACRO
	jsr	_LVO\1(a6)
	ENDM

	SECTION	"FadingDemo",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	Quit

	move.l	GMS_Base(pc),a6
	CALL	SetUserPri

	move.l	GMS_Base(pc),a6          ;Tell GMS that we want to add a
	lea	ScreenStruct(pc),a0      ;screen for use.
	CALL	Add_Screen
	tst.l	d0
	bne.s	Error

	lea	Picture(pc),a1           ;a1 = Picture struct.
	move.l	SS_MemPtr1(a0),PIC_Data(a1)
	lea	PicFile(pc),a0           ;a0 = Picture file.
	CALL	LoadPic
	tst.w	d0
	bne.s	ReturnToDOS

	lea	ScreenStruct(pc),a0      ;Now show the screen/pic.
	CALL	Show_Screen

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

	moveq	#30,d0
	CALL	Wait_Time

	moveq	#00,d0                   ;d0 = Initialise fader.
	moveq	#00,d1                   ;d1 = Start at colour zero.
	moveq	#16,d2                   ;d2 = Amount of colours (32)
	lea	Palette(pc),a1
.Fade	CALL	Wait_VBL
	CALL	Wait_OSVBL
	CALL	B12_FadeToPalette
	tst.w	d0
	bne.s	.Fade

	CALL	Wait_LMB

	moveq	#00,d0                   ;This is the fade loop.  It will
	moveq	#00,d1
	moveq	#16,d2                   ;are white).  Notice the start
.Fade1	CALL	Wait_OSVBL               ;keep on looping until all colours
	CALL	B12_FadeToWhite          ;colour is 00 and the amt of
	tst.w	d0                       ;colours is 32, so that all the
	bne.s	.Fade1                   ;cols are included in the range.

	moveq	#30,d0
	CALL	Wait_Time

	moveq	#$00,d0                  ;Now we fade down to black. Note
.Fade2	CALL	Wait_OSVBL               ;that we have calld Initialise_Fader
	CALL	B12_FadeToBlack          ;every time - otherwise each fade
	tst.w	d0                       ;would not even attempt to start!
	bne.s	.Fade2                   ;Also of interest is that Fading
		                         ;to Black covers ALL colours.
	moveq	#50,d0
	CALL	Wait_Time

;===========================================================================;
;                              RETURN TO DOS
;===========================================================================;

ReturnToDOS:
	move.l	GMS_Base(pc),a6
	lea	ScreenStruct(pc),a0
	CALL	Delete_Screen            ;Give back screen memory etc.
Error	move.l	GMS_Base(pc),a1
	move.l	($4).w,a6
	CALL	CloseLibrary
Quit	MOVEM.L	(SP)+,A0-A6/D1-D7
	moveq	#$00,d0
	rts

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

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

AMT_PLANES =	4

ScreenStruct:
	dc.l	"GSV1",0
	dc.l	0,0,0             ;Screen_Mem1/2/3
	dc.l	0                 ;Screen link.
	dc.l	0                 ;Address of screen palette.
	dc.l	0                 ;Address of rasterlist.
	dc.l	0                 ;Amt of colours in palette.
	dc.w	320,256,640,256   ;Screen & Pic Height/Width
	dc.w	AMT_PLANES        ;Amt_Planes
	dc.w	0,0               ;X/Y screen offset
	dc.w	0,0               ;X/Y picture offset
	dc.l	0                 ;Special attributes.
	dc.w	LORES             ;Screen mode.
	dc.b	INTERLEAVED       ;Screen type
	dc.b	0                 ;Reserved.
	even

Palette	dc.w	$0000,$0400,$0501,$0501,$0601,$0701,$0701,$0801
	dc.w	$0901,$0A01,$0B02,$0432,$0CC0,$0F00,$0211,$0880

Picture	dc.l	"PCV1",0           ;Version header.
	dc.l	0                  ;Source data.
	dc.w	640,256            ;Width, Height.
	dc.w	AMT_PLANES         ;Amount of Planes.
	dc.l	32                 ;Amount of colours.
	dc.l	Palette            ;Source palette (remap).
	dc.w	LORES              ;Screen mode.
	dc.w	INTERLEAVED        ;Destination
	dc.l	0                  ;Parameters.

PicFile	dc.b	"GAMESLIB:data/IFF.Pic640x256",0
	even

