;WideScroll with mirror
;----------------------
;Mirror test for large width screens.

	opt	o+

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

CALL	MACRO
	jsr	_LVO\1(a6)
	ENDM

	SECTION	"WideMirror",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	Error

	lea	Picture(pc),a1	;a1 = Picture struct.
	move.l	SS_MemPtr1(a0),PIC_Data(a1)
	lea	PicFile(pc),a0	;a0 = Picture file.
	CALL	LoadPic	;>> = Load the picture.
	tst.w	d0
	bne.s	ReturnToDOS

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

	moveq	#JPORT1,d0               ;Initialise the mouse port.
	CALL	Read_Mouse

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

Loop:	moveq	#JPORT1,d0               ;Port 1
	CALL	Read_Mouse
	btst	#MB_LMB,d0
	bne.s	ReturnToDOS
	move.w	d0,d1
	asr.w	#8,d0
	ext.w	d1
	add.w	d0,SS_PicXOffset(a0)
	add.w	d1,SS_PicYOffset(a0)

.chkty	tst.w	SS_PicYOffset(a0)
	bge.s	.chkby
	clr.w	SS_PicYOffset(a0)

.chkby	cmp.w	#255-190,SS_PicYOffset(a0)
	blt.s	.chklx
	move.w	#255-190,SS_PicYOffset(a0)

.chklx	tst.w	SS_PicXOffset(a0)
	bge.s	.chkrx
	clr.w	SS_PicXOffset(a0)

.chkrx	cmp.w	#16,SS_PicXOffset(a0)
	ble.s	.move
	move.w	#16,SS_PicXOffset(a0)

.move	CALL	Move_Picture
	CALL	Wait_OSVBL
	bra.s	Loop

;===========================================================================;
;                              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 =	5

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

RasterList:
	WAITLINE 190
	MIRROR
	NEWPALETTE 0,32,WaterPalette
	RASTEND

Palette	dc.w	$0000,$0130,$0FCB,$0FA9,$0D88,$0965,$0644,$0211
	dc.w	$0400,$0444,$0FF0,$0432,$0CC0,$0150,$0501,$0880
	dc.w	$0261,$0271,$0382,$0492,$05A3,$05B4,$0677,$06C4
	dc.w	$0788,$09AA,$0BCC,$0801,$0901,$0A02,$0701,$0601

WaterPalette:
	dc.w	$0000,$0010,$0765,$0754,$0644,$0432,$0322,$0100
	dc.w	$0200,$0222,$0770,$0211,$0660,$0020,$0200,$0440
	dc.w	$0130,$0130,$0141,$0241,$0251,$0252,$0333,$0362
	dc.w	$0344,$0455,$0666,$0400,$0400,$0501,$0300,$0300

Picture	dc.l	"PCV1",0	;Version header.
	dc.l	0	;Source data.
	dc.w	336,256	;Width, Height.
	dc.w	AMT_PLANES	;Amount of Planes.
	dc.l	32	;Amount of colours.
	dc.l	Palette	;Source palette (remap).
	dc.w	LORES	;Screen mode.
	dc.w	INTERLEAVED	;Destination
	dc.l	0	;Parameters.

PicFile:
	dc.b	"GAMESLIB:data/IFF.Pic336",0
	even
