;-------T-------T------------------------T----------------------------------;
;Name:      Screen Redimension Demo
;Author:    Paul Manias
;Copyright: DreamWorld Productions (c) 1996-1997.  Freely distributable.
;
;Test routine for height and width alteration.  Move the mouse to alter the
;position of the screen's right hand corner.  Hold the LMB and move the
;mouse around to move the entire screen around your monitor.
;
;Press RMB to exit.

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

	SECTION	"Demo",CODE

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

	STARTGMS

Start:	MOVEM.L	A0-A6/D1-D7,-(SP)
	lea	PictureTags(pc),a1
	CALL	LoadPic
	tst.l	d0
	beq.s	.Error_Picture

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

	CALL	InitJoyPorts
	bsr.s	Main

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

;===========================================================================;
;                                MAIN LOOP
;===========================================================================;

Main:	move.l	Screen(pc),a0

	moveq	#JPORT1,d0	;Read from port 1
	moveq	#JT_ZBXY,d1
	CALL	ReadJoyPort	;Go get port status.
	btst	#MB_RMB,d0
	bne.s	Fade_Here
	move.w	d0,d1
	ext.w	d0
	asr.w	#8,d1

	btst	#MB_LMB,d0
	bne.s	.RMB

	add.w	d1,GS_ScrWidth(a0)
	add.w	d0,GS_ScrHeight(a0)
	bra.s	.chkty

.RMB	add.w	d1,GS_ScrXOffset(a0)
	add.w	d0,GS_ScrYOffset(a0)

.chkty	tst.w	GS_ScrHeight(a0)
	bge.s	.chkby
	clr.w	GS_ScrHeight(a0)
.chkby	cmp.w	#256,GS_ScrHeight(a0)
	ble.s	.chklx
	move.w	#256,GS_ScrHeight(a0)
.chklx	tst.w	GS_ScrWidth(a0)
	bge.s	.chkrx
	clr.w	GS_ScrWidth(a0)
.chkrx	cmp.w	#320,GS_ScrWidth(a0)
	ble.s	.done
	move.w	#320,GS_ScrWidth(a0)

.done	CALL	WaitVBL	;Always wait for a VBL first.

	move.w	#$fff,$dff180

	CALL	RemakeScreen	;Reposition the screen now.
	bra.s	Main

Fade_Here:
	moveq	#00,d0
	moveq	#4,d1	;d1 = Speed
	moveq	#$000,d2
	moveq	#00,d3	;d1 = Start at colour zero.
	moveq	#32,d4	;d2 = Amount of colours (32)
	move.l	GS_Palette(a0),a1	;a1 = Palette to fade to.
.Fade	CALL	WaitVBL
	CALL	PaletteToColour
	tst.w	d0
	bne.s	.Fade
	rts

;===========================================================================;
;                           CODE-RELATIVE DATA
;===========================================================================;

ScreenTags:
	dc.l	TAGS_GAMESCREEN
Screen:	dc.l	0
	dc.l	GSA_MemPtr1
GMemPtr	dc.l	0
	dc.l	GSA_Palette
GPalette dc.l	0
	dc.l	GSA_ScrWidth,320
	dc.l	GSA_ScrHeight,256
	dc.l	GSA_AmtColours,32
	;dc.l	GSA_Attrib,CENTRE
	;dc.l	GSA_ScrMode,LACED

	;dc.l	GSA_ScrType,ILBM

	dc.l	TAGEND

PictureTags:
	dc.l	TAGS_PICTURE
Picture	dc.l	0
	dc.l	PCA_Data
PicData	dc.l	0
	dc.l	PCA_Width,320
	dc.l	PCA_Height,256
	dc.l	PCA_AmtColours,32
	dc.l	PCA_Options,GETPALETTE|VIDEOMEM|RESIZE
	dc.l	PCA_File,.file
	dc.l	TAGEND

.file	dc.b	"GMS:demos/data/PIC.Green",0
	even

