;-------T-------T------------------------T----------------------------------;
;Name:      Load Picture
;Author:    Paul Manias
;Copyright: DreamWorld Productions (c) 1996-1997.  Freely distributable.
;
;This demo will load in a picture of any size/type and if it is larger than
;the screen width, it scrolls left and right.  This is easily possible due
;to the fact that GMS likes to fill in fields that have been set at zero
;on initialisation, which is great for loading/displaying things like
;pictures.
;
;The benefits of this will become more apparent when you want to do things
;like changing your graphics format from ECS to AGA and vice versa.  The
;benefits for the user are enormous (full graphical editing capabilities,
;if you program correctly).  And you don't even need to change a line of
;code!

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

SPEED	=	2

	SECTION	"Demo",CODE

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

	STARTGMS

Start:	MOVEM.L	A0-A6/D1-D7,-(SP)
	move.l	GMSBase(pc),a6
	moveq	#VIDEOMEM|GETPALETTE,d0
	lea	PictureFile(pc),a1
	CALL	LoadPicFile
	move.l	d0,Picture
	beq.s	.Error_Picture

	CALL	GetScreen
	move.l	d0,Screen
	beq.s	.Error_Screen

	move.l	Picture(pc),a0	;a0 = Source structure.
	move.l	Screen(pc),a1	;a1 = Destination structure.
	move.l	PIC_Data(a0),GS_MemPtr1(a1)
	move.l	#HSCROLL,GS_Attrib(a1)
	CALL	CopyStructure	;>> = Copy Picture to Screen.

	move.l	Screen(pc),a0
	CALL	AddScreen
	tst.l	d0
	beq.s	.Error_Screen

	CALL	ShowScreen

	bsr.s	Main	;Go and do the main routine.

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

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

Main:	move.l	Screen(pc),a0
	move.l	Picture(pc),a2
	moveq	#0,d0	;d0 = Initialise fader.
	moveq	#2,d1	;d1 = Speed of fade.
	move.l	PIC_Palette(a2),a1
	moveq	#$000000,d2
	moveq	#0,d3
	move.l	PIC_AmtColours(a2),d4
.Fade1	CALL	WaitVBL
	CALL	ColourToPalette	;Do the fade routine.
	tst.w	d0	;Has the fade finished yet?
	bne.s	.Fade1	;If not, keep doing it.

	move.l	Picture(pc),a1
	moveq	#0,d2
.loop	CALL	WaitVBL
	move.w	GS_ScrWidth(a0),d0	;Only scroll the picture if is is
	lsr.w	#3,d0	;bigger than the actual screen.
	cmp.w	GS_PicWidth(a0),d0
	bge.s	.done

	tst.w	d2
	bgt.s	.Right
.Left	tst.w	GS_PicXOffset(a0)
	ble.s	.RRight
.RLeft	moveq	#-SPEED,d2
	bra.s	.scroll
.Right	move.w	GS_PicWidth(a0),d0	;d0 = PicWidth.
	sub.w	#320,d0
	cmp.w	GS_PicXOffset(a0),d0	;d0 = Is (Width-320 < PicOffset)?
	ble.s	.RLeft
.RRight	moveq	#SPEED,d2
.scroll	add.w	d2,GS_PicXOffset(a0)
	CALL	MovePicture

.done	moveq	#JPORT1,d0	;Port 1 (Mouse)
	moveq	#JT_ZBXY,d1
	CALL	ReadJoyPort
	btst	#MB_LMB,d0
	beq.s	.loop
	rts

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

Screen:	dc.l	0
Picture	dc.l	0

PictureFile:
	dc.b	"GMS:demos/data/PIC.Pic640x256",0
	even
