;Draw Line
;---------
;This demo draws a line which you can control with the mouse.

	opt	o+,c+

	INCLUDE	"exec/exec_lib.i"
	INCLUDE	"games/games_lib.i"
	INCLUDE	"games/games.i
CALL	MACRO
	jsr	_LVO\1(a6)
	ENDM

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

	SECTION	"DrawLine",CODE

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

	CALL	AllocBlitter
	tst.w	d0
	bne.s	.Error_Blitter

	lea	Screen(pc),a0
	CALL	Add_Screen
	tst.l	d0
	bne.s	.Error_Screen

	CALL	Show_Screen

	bsr.s	Loop

.ReturnToDOS
	move.l	GMS_Base(pc),a6
	lea	Screen(pc),a0
	CALL	Delete_Screen
.Error_Screen
	CALL	FreeBlitter
.Error_Blitter
	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
;===========================================================================;

Loop:	lea	Screen(pc),a0
	moveq	#BUFFER2,d0
	CALL	ClrScreen

	moveq	#JPORT1,d0
	CALL	Read_Mouse
	btst	#MB_LMB,d0
	bne.s	.done
	lea	MouseDXY(pc),a1
	btst	#MB_RMB,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)
.ChkLX	tst.w	(a1)
	bge.s	.ChkRX
	clr.w	(a1)
.ChkRX	cmp.w	#319,(a1)
	ble.s	.ChkTY
	move.w	#319,(a1)
.ChkTY	tst.w	2(a1)
	bge.s	.ChkBY
	clr.w	2(a1)
.ChkBY	cmp.w	#255,2(a1)
	ble.s	.Draw
	move.w	#255,2(a1)

.Draw	moveq	#BUFFER2,d0	;d0 = Buffer
	movem.w	MouseSXY(pc),d1/d2/d3/d4	;d1 = XStart, YStart, XEnd, YEnd.
	moveq	#2,d5	;d5 = Colour
	CALL	Draw_Line
	CALL	Wait_OSVBL
	CALL	SwapBuffers
	bra.s	Loop
.done	rts

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

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

GMS_Name:
	dc.b	"games.library",0
	even
GMS_Base:
	dc.l	0

AMT_PLANES =	2

Screen:	dc.l	GSV1,0	;Structure version.
	dc.l	0,0,0	;Screen_Mem1/2/3
	dc.l	0	;Screen link.
	dc.l	.Palette	;Address of screen palette.
	dc.l	0	;Address of rasterlist.
	dc.l	4	;Amt of colours in palette.
	dc.w	320,256	;Screen Width and Height.
	dc.w	320/8,256	;Picture Width/8 and 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	DBLBUFFER	;Special attributes.
	dc.w	LORES|COL12BIT	;Screen mode.
	dc.b	INTERLEAVED	;Screen type
	dc.b	0	;Reserved.
	even

.Palette
	dc.w	$000,$fff,$f0f,$f00

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