;AGA White Fade
;--------------
;Fades the screen to white, then down to a palette, and exits with a fade
;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	"AGAWhiteFade",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          ;Initialise our screen.
	lea	ScreenStruct(pc),a0     
	CALL	Add_Screen
	tst.l	d0
	bne.s	Error

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

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

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

	moveq	#$00,d0                  ;d0 = FadeState (reset).
	moveq	#10,d1                   ;d1 = Speed of fade.
.f_in	CALL	Wait_OSVBL
	CALL	B24_FadeToWhite          ;Do the fade routine.
	tst.w	d0                       ;Has the fade finished yet?
	bne.s	.f_in                    ;If not, keep doing it.

	moveq	#$00,d0                  ;d0 = FadeState
	moveq	#2,d1                    ;d1 = Speed of fade.
	lea	Palette(pc),a1           ;a1 = Palette to fade to.
.f_mid	CALL	Wait_OSVBL
	CALL	B24_FadeToPalette        ;Do the fade routine.
	tst.w	d0                       ;Has the fade finished yet?
	bne.s	.f_mid                   ;If not, keep doing it.

	moveq	#100,d0
	CALL	Wait_Time

	moveq	#$00,d0
	moveq	#2,d1                    ;d0 = Speed of fade.
.f_out	CALL	Wait_OSVBL
	CALL	B24_FadeToBlack          ;Do the fade routine.
	tst.w	d0                       ;Has the fade finished yet?
	bne.s	.f_out                   ;If not, keep doing it.

;===========================================================================;
;                              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	($4).w,a6
	move.l	GMS_Base(pc),a1
	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 =	5

ScreenStruct:
	dc.l	"GSV1",0
	dc.l	0,0,0               ;Screen_Mem1/2/3
	dc.l	0                   ;Screen link.
	dc.l	0 ;Palette          ;Address of palette.
	dc.l	0                   ;Address of rasterlist.
	dc.l	32                  ;Amt of colours in palette.
	dc.w	320,256,320,256     ;Screen & Pic Height/Width.
	dc.w	AMT_PLANES          ;Amt of planes.
	dc.w	0,0                 ;X/Y top of screen offsets
	dc.w	0,0                 ;X/Y pic offsets.
	dc.l	0                   ;Special attributes.
	dc.w	LORES|COL24BIT      ;Screen mode.
	dc.b	INTERLEAVED         ;Screen type
	dc.b	0                   ;Reserved.
	even

Palette	dc.l	$000000,$080808,$101010,$191919
	dc.l	$212121,$292929,$313131,$3A3A3A
	dc.l	$424242,$4A4A4A,$525252,$5A5A5A
	dc.l	$636363,$6B6B6B,$737373,$7B7B7B
	dc.l	$848484,$8C8C8C,$949494,$9C9C9C
	dc.l	$A5A5A5,$ADADAD,$B5B5B5,$BDBDBD
	dc.l	$C5C5C5,$CECECE,$D6D6D6,$7F7F7F
	dc.l	$9B9B9B,$707070,$444444,$1E1E1E

Picture	dc.l	"PCV1",0	;Version header.
	dc.l	0	;Source data.
	dc.w	320,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|COL24BIT	;Screen mode.
	dc.w	INTERLEAVED	;Destination
	dc.l	0	;Parameters.

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