;Alteration of screen dimensions
;-------------------------------
;Test routine for height and width alteration.
;
;Move the mouse to alter the position of the screen's right hand corner.
;
;Hold the RMB and move the mouse around to move the entire screen around
;your monitor.
;
;Press LMB to exit.

	opt	o+

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

CALL	MACRO
	jsr	_LVO\1(a6)
	ENDM

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

	move.l	PIC_Palette(a1),GS_Palette(a0)
	CALL	UpdatePalette

	CALL	Show_Screen
	CALL	InitJoyPorts
	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	;Give back screen memory etc.
.Error_Screen
	move.l	GMS_Base(pc),a1
	move.l	($4).w,a6
	CALL	CloseLibrary
.Error_GMS
	MOVEM.L	(SP)+,A0-A6/D1-D7
	moveq	#$00,d0
	rts

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

Main:	moveq	#JPORT1,d0	;Read from port 1
	moveq	#JT_ZBXY,d1
	CALL	Read_JoyPort	;Go get port status.
	btst	#MB_LMB,d0
	bne	Fade_Here
	move.w	d0,d1
	ext.w	d0
	asr.w	#8,d1

	btst	#MB_RMB,d0
	bne.s	.RMB

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

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

.chksrx	cmp.w	#35,GS_ScrXOffset(a0)
	ble.s	.chkslx
	move.w	#35,GS_ScrXOffset(a0)

.chkslx	cmp.w	#-40,GS_ScrXOffset(a0)
	bge.s	.chksty
	move.w	#-40,GS_ScrXOffset(a0)

.chksty	cmp.w	#-20,GS_ScrYOffset(a0)
	bge.s	.chkty
	move.w	#-20,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	cmp.w	#0,GS_ScrWidth(a0)
	bge.s	.chkrx
	move.w	#0,GS_ScrWidth(a0)

.chkrx	cmp.w	#320,GS_ScrWidth(a0)
	ble.s	.done
	move.w	#320,GS_ScrWidth(a0)

.done	CALL	Wait_OSVBL	;Always wait for a VBL first.
	CALL	Remake_Screen	;Reposition the screen now.
	bra	Main

Fade_Here:
	moveq	#00,d0
	moveq	#1,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	Wait_OSVBL
	CALL	PaletteToColour
	tst.w	d0
	bne.s	.Fade
	rts

;===========================================================================;
;                           CODE-RELATIVE 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 screen palette
	dc.l	0	;Address of rasterlist.
	dc.l	0	;Amt of colours in palette.
	dc.w	320,256	;Screen Width, Height.
	dc.w	320/8,256	;Pic Width in bytes, Height.
	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|COL12BIT	;Screen mode
	dc.b	INTERLEAVED	;Screen type
	dc.b	0	;Reserved
	even

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 (remap).
	dc.w	LORES|COL12BIT	;Screen mode.
	dc.w	INTERLEAVED	;Destination
	dc.l	GETPALETTE	;Parameters.
	dc.l	.File
.File	dc.b	"GAMESLIB:data/IFF.Pic320",0
	even

