;AGA Water Demo
;---------------
;Demo of the mirroring and newpalette commands, used to create a water
;effect.
;
;Use  the  joystick  to  move  the water up and down.

	opt	o+

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

LOCAL	=	1

CALL	MACRO
	jsr	_LVO\1(a6)
	ENDM

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

	move.l	SS_MemPtr1(a0),a1        ;a1 = Destination [SS_MemPtr1].
	lea	PackedPicFile(pc),a0     ;a0 = File Name.
	moveq	#$00,d0                  ;d0 = Password
	CALL	SmartLoad
	tst.l	d0
	beq.s	ReturnToDOS

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

	moveq	#JPORT1,d0               ;Initialise Mouse Port 1.
	CALL	Read_Mouse

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

Loop:	CALL	Wait_OSVBL
	CALL	Update_RasterLines

	moveq	#JPORT1,d0
	CALL	Read_Mouse
	ext.w	d0
	add.w	d0,RasterList+2

.chk129	cmp.w	#129,RasterList+2
	bgt.s	.chk256
	move.w	#129,RasterList+2

.chk256	cmp.w	#255,RasterList+2
	blt.s	.chklmb
	move.w	#255,RasterList+2

.chklmb	btst	#MB_LMB,d0
	beq.s	Loop

	moveq	#0,d0                    ;d0 = FadeState
	moveq	#2,d1                    ;d1 = Speed of fade.
Fade:	CALL	Wait_OSVBL
	CALL	B24_FadeToBlack          ;Do the fade routine.
	tst.w	d0                       ;Has the fade finished yet?
	bne.s	Fade                     ;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	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 =	7

ScreenStruct:
	dc.l	"GSV1",0
	dc.l	0,0,0             ;Screen_Mem1/2/3
	dc.l	0                 ;Screen link.
	dc.l	ScreenPalette     ;Address of screen palette.
	dc.l	RasterList        ;Address of rasterlist.
	dc.l	256               ;Amt of colours in palette.
	dc.w	320,256,320,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|COL24BIT    ;Screen mode.
	dc.b	INTERLEAVED       ;Screen type
	dc.b	0                 ;Reserved
	even

RasterList:
	WAITLINE 164
	MIRROR
	NEWPALETTE 0,128,WaterPalette
	RASTEND

ScreenPalette:
	dc.l	$000000,$FFFFFF,$FAF5F2,$FAE8E7
	dc.l	$EEDED5,$E8D4C8,$DDC0AF,$D7B5A2
	dc.l	$D1AC96,$DCA491,$CBA38B,$C5997E
	dc.l	$BD8E74,$B5846A,$AD7A5F,$A57056
	dc.l	$9D674D,$955D44,$8C533B,$844B34
	dc.l	$7C432D,$743B26,$6C3320,$642D1B
	dc.l	$5C2616,$532010,$4A1D0C,$411A09
	dc.l	$381606,$2F1204,$260F02,$1D0C00
	dc.l	$AC783A,$A67139,$A06C39,$986638
	dc.l	$995F36,$906037,$8C5C36,$945733
	dc.l	$865735,$905030,$7E5133,$8D4B2E
	dc.l	$764B31,$6E4630,$8A462D,$64412B
	dc.l	$5D3D27,$593A24,$543822,$50351F
	dc.l	$4B341D,$47301A,$592218,$402D17
	dc.l	$382813,$3B2007,$302310,$2B200D
	dc.l	$331100,$430907,$3C0504,$2E0202
	dc.l	$B48038,$B7743D,$AE6350,$A85D4A
	dc.l	$A35644,$9E503E,$994A39,$944534
	dc.l	$9F4336,$8E3F30,$87412B,$87382A
	dc.l	$823628,$803226,$792C21,$72251C
	dc.l	$E1AB98,$DBA28C,$D79C89,$D29582
	dc.l	$CD8D7A,$C88672,$C27E6B,$BD7764
	dc.l	$B8705D,$B36A57,$BB5244,$AD4A3D
	dc.l	$C8594A,$7F7444,$847D49,$67271E
	dc.l	$6C2219,$651D15,$5E1711,$57130E
	dc.l	$500F0B,$4A0C09,$350303,$270000
	dc.l	$89874E,$8C8E53,$8C9358,$8E9D62
	dc.l	$C6904A,$9AA467,$CD9E51,$AFAE6F
	dc.l	$E3D765,$D5AE58,$BCAD78,$C1AC7C
	dc.l	$CBAA82,$D5A588,$EAA09B,$ECA7A2
	dc.l	$EDADA9,$EFB5B1,$F0BBB8,$F2C2BF
	dc.l	$F4CBC8,$F5D1CF,$F7D9D7,$FDF7F7

WaterPalette:
	dc.l	$000000,$A3A3A3,$A09D9B,$A09494
	dc.l	$988E88,$948880,$8D7B70,$8A7468
	dc.l	$866E60,$8D695D,$826859,$7E6251
	dc.l	$795B4A,$745444,$6F4E3D,$6A4837
	dc.l	$644231,$5F3C2C,$5A3526,$543021
	dc.l	$4F2B1D,$4A2618,$452114,$401D11
	dc.l	$3B180E,$35140A,$2F1308,$2A1106
	dc.l	$240E04,$1E0C03,$180A01,$130800
	dc.l	$6E4D25,$6A4824,$664524,$614124
	dc.l	$623D23,$5C3D23,$5A3B23,$5F3821
	dc.l	$563822,$5C331F,$513421,$5A301D
	dc.l	$4C301F,$462D1F,$582D1D,$402A1C
	dc.l	$3C2719,$392517,$362416,$332214
	dc.l	$302113,$2D1F11,$39160F,$291D0F
	dc.l	$241A0C,$261404,$1F160A,$1C1408
	dc.l	$210B00,$2B0604,$260303,$1D0101
	dc.l	$735224,$754A27,$6F3F33,$6C3C2F
	dc.l	$68372C,$653328,$622F24,$5F2C21
	dc.l	$662B23,$5B281F,$562A1C,$56241B
	dc.l	$53231A,$522018,$4D1C15,$491812
	dc.l	$906D61,$8C685A,$8A6458,$865F53
	dc.l	$835A4E,$805649,$7C5144,$794C40
	dc.l	$76483C,$734438,$78342C,$6F2F27
	dc.l	$80392F,$514A2C,$54502F,$421913
	dc.l	$451610,$41130D,$3C0F0B,$380C09
	dc.l	$330A07,$2F0806,$220202,$190000
	dc.l	$585632,$5A5B35,$5A5E38,$5B643F
	dc.l	$7F5C2F,$636942,$836534,$706F47
	dc.l	$918A41,$886F38,$786F4D,$7C6E4F
	dc.l	$826D53,$886A57,$966663,$976B68
	dc.l	$986F6C,$997471,$9A7876,$9B7C7A
	dc.l	$9C8280,$9D8684,$9E8B8A,$A29E9E


PackedPicFile:
	IFNE	LOCAL
	dc.b	"GAMESLIB:"
	ENDC
	dc.b	"data/Yattering128.pak",0
	even

