;-------T-------T------------------------T----------------------------------;
;Name:      Scroll Memory
;Author:    Paul Manias
;Copyright: DreamWorld Productions (c) 1996-1997.  Freely distributable.
;
;This demo shows you the power of the scrolling features by allowing you
;to scroll all over your chip ram :-).  Usually you would set limits to stop
;you from going over the boundaries, but that's up to you.
;
;Use mouse to move around, LMB exits.

	INCDIR	"GMSDev:Includes/"
	INCLUDE	"dpkernel/dpkernel.i"

	SECTION	"Demo",CODE

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

	STARTDPK

Start:	MOVEM.L	A0-A6/D1-D7,-(SP)
	move.l	DPKBase(pc),a6
	lea	ScreenTags(pc),a0
	sub.l	a1,a1
	CALL	Init
	tst.l	d0
	beq.s	.Exit

	lea	PictureTags(pc),a0
	move.l	Screen(pc),a1
	move.l	GS_MemPtr1(a1),PicData
	sub.l	a1,a1
	CALL	Init
	tst.l	d0
	beq.s	.Exit

	moveq	#ID_JOYDATA,d0	;Get joydata structure.
	CALL	Get
	move.l	d0,JoyData
	beq.s	.Exit
	move.l	d0,a0	;Initialise the joydata structure.
	sub.l	a1,a1
	CALL	Init
	tst.l	d0
	beq.s	.Exit

	move.l	Screen(pc),a0
	CALL	Display

	bsr.s	Main

.Exit	move.l	DPKBase(pc),a6
	move.l	JoyData(pc),a0
	CALL	Free
	move.l	Picture(pc),a0
	CALL	Free
	move.l	Screen(pc),a0
	CALL	Free
	MOVEM.L	(SP)+,A0-A6/D1-D7
	moveq	#ERR_OK,d0
	rts

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

Main:
.loop	move.l	DPKBase(pc),a6
	move.l	JoyData(pc),a0
	CALL	Query

	move.l	JoyData(pc),a0
	move.w	JD_XChange(a0),d0
	move.w	JD_YChange(a0),d1
	move.l	JD_Buttons(a0),d2
	btst	#JB_RMB,d2
	bne.s	.done
	;btst	#JB_LMB,d2
	;bne.s	.MoveScreen
.MovePicture
	move.l	SCRBase(pc),a6
	move.l	Screen(pc),a0
	add.w	d0,GS_BmpXOffset(a0)
	add.w	d1,GS_BmpYOffset(a0)
	CALL	scrRemakeScreen
	move.l	Screen(pc),a0
	CALL	scrMoveBitmap
	CALL	scrWaitAVBL
	bra.s	.loop

.MoveScreen
	move.l	SCRBase(pc),a6
	move.l	Screen(pc),a0
	add.w	d0,GS_XOffset(a0)
	add.w	d1,GS_YOffset(a0)
	move.l	Screen(pc),a0
	CALL	scrRemakeScreen
	move.l	Screen(pc),a0
	CALL	scrMoveBitmap
	CALL	scrWaitAVBL
	bra.s	.loop
.done	rts

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

JoyData:	dc.l  0

ScreenTags:	dc.l  TAGS_SCREEN
Screen:		dc.l  0
		dc.l  GSA_Palette,SPalette
		dc.l  GSA_Width,320
		dc.l  GSA_Height,256
		dc.l    GSA_BitmapTags,0
		dc.l    BMA_AmtColours,32
		dc.l    TAGEND,0
		dc.l  GSA_Attrib,HSCROLL|VSCROLL|SBUFFER|CENTRE
		dc.l  TAGEND

PictureTags:	dc.l  TAGS_PICTURE
Picture:	dc.l  0
		dc.l    PCA_BitmapTags,0
		dc.l    BMA_Data
PicData:	dc.l    0
		dc.l    BMA_Width,320
		dc.l    BMA_Height,256
		dc.l    BMA_AmtColours,32
		dc.l    TAGEND,0
		dc.l  PCA_Palette,SPalette
		dc.l  PCA_Source,.file
		dc.l  TAGEND

.file		FILENAME "GMS:demos/data/PIC.Green"

SPalette:	dc.l  PALETTE,32
		dc.l  $000000,$103000,$F0C0B0,$F0A090,$D08080,$906050
		dc.l  $604040,$201010,$400000,$404040,$F0F000,$403020
		dc.l  $C0C000,$105000,$500010,$808000,$206010,$207010
		dc.l  $308020,$409020,$50A030,$50B040,$607070,$60C040
		dc.l  $708080,$90A0A0,$B0C0C0,$800010,$900010,$A00020
		dc.l  $700010,$600010

;===========================================================================;

ProgName:	dc.b  "Scroll Memory",0
ProgAuthor:	dc.b  "Paul Manias",0
ProgDate:	dc.b  "10 December 1997",0
ProgCopyright:	dc.b  "DreamWorld Productions (c) 1996-1997.  Freely distributable.",0
ProgShort:	dc.b  "Allows you to scroll over your video memory.",0
		even
