;-------T-------T------------------------T----------------------------------;
;Name:      Draw Line
;Author:    Paul Manias
;Copyright: DreamWorld Productions (c) 1996-1997.  Freely distributable.
;
;This demo draws a line which you can control with the mouse.

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

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

	SECTION	"DrawLine",CODE

Start:	STARTGMS

	MOVEM.L	A0-A6/D1-D7,-(SP)
	move.l	GMSBase(pc),a6
	CALL	AllocBlitter
	tst.l	d0
	bne.s	.Error_Blitter

	lea	ScreenTags(pc),a0
	CALL	ShowScreen
	tst.l	d0
	beq.s	.Error_Screen

	CALL	InitJoyPorts

	bsr.s	Loop

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

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

Loop:	move.l	Screen(pc),a0
	move.l	GS_Bitmap(a0),a0
	CALL	ClearBitmap

	moveq	#JPORT1,d0
	moveq	#JT_ZBXY,d1
	CALL	ReadJoyPort
	btst	#MB_RMB,d0
	bne.s	.done
	lea	MouseDXY(pc),a1
	btst	#MB_LMB,d0
	beq.s	.no
	lea	MouseSXY(pc),a1
.no	move.w	d0,d1
	ext.w	d1
	add.w	d1,2(a1)
	asr.w	#8,d0
	add.w	d0,(a1)

.Draw	move.l	Screen(pc),a0
	move.l	GS_Bitmap(a0),a0
	movem.w	MouseSXY(pc),d1/d2/d3/d4	;d1 = XStart, YStart, XEnd, YEnd.
	moveq	#2,d5	;d5 = Colour
	CALL	DrawLine
	CALL	WaitVBL
	move.l	Screen(pc),a0
	CALL	SwapBuffers
	bra.s	Loop
.done	rts

MouseSXY
	dc.w	160,128
MouseDXY
	dc.w	40,40

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

ScreenTags:
	dc.l	TAGS_GAMESCREEN
Screen:	dc.l	0
	dc.l	GSA_Palette,.palette
	dc.l	GSA_AmtColours,4
	dc.l	GSA_ScrWidth,640
	dc.l	GSA_ScrHeight,256
	dc.l	GSA_Attrib,DBLBUFFER
	dc.l	GSA_ScrMode,HIRES
	dc.l	TAGEND
.palette
	dc.l	$000000,$f0f0f0,$f000f0,$f00000
