;Draw Pixel List
;---------------
;This demo demonstrates the usefulness of LISTs, by drawing a trail of
;pixels attached to the mouse.  In the case of pixels there are special
;routines for drawing with lists, so the drawing is very fast.
;
;Press LMB to exit.

	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	"DrawPixel",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
	CALL	InitJoyPorts
	bsr.s	Main

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

Main:	lea	Screen(pc),a0
	lea	MList(pc),a2		;a2 = Pointer to pixel list.
.loop	moveq	#BUFFER2,d0
	CALL	ClrScreen

	lea	2(a2),a3		;Drop the pixels here.
	moveq	#31-1,d7
.drop	addq.w	#1,(a3)
	subq.w	#1,2(a3)		;a3 = (Colour)-1
	bge.s	.colok
	clr.w	2(a3)
.colok	addq.w	#6,a3
	dbra	d7,.drop

	lea	MouseX(pc),a5
	moveq	#JPORT1,d0
	CALL	Read_Mouse
	btst	#MB_LMB,d0
	bne.s	.done
	move.w	d0,d1
	ext.w	d1			;d1 = Extend the Y byte.
	add.w	d1,2(a5)		;d1 = (MouseY)+ChangeY
	asr.w	#8,d0			;d0 = Extend the X byte.
	add.w	d0,(a5)			;d0 = (MouseX)+ChangeX

	move.l	(a5),-(sp)
	moveq	#2,d1
	CALL	FastRandom
	subq.w	#1,d0
	add.w	d0,(a5)

	moveq	#2,d1
	CALL	FastRandom
	subq.w	#1,d0
	add.w	d0,2(a5)

	move.l	a2,a3
	moveq	#31-1,d7
.tloop	move.l	6(a3),(a3)
	move.w	10(a3),4(a3)
	addq.w	#6,a3
	dbra	d7,.tloop

	lea	PixelList(pc),a1	;a1 = Pixel list.
	moveq	#BUFFER2,d0		;d0 = Destination buffer.
	CALL	Draw_PixelList		;>> = Draw pixels with clipping.

	move.l	(sp)+,(a5)

	CALL	Wait_OSVBL
	CALL	SwapBuffers
	bra.s	.loop
.done	rts

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

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

Screen:	dc.l	GSV1,0			;Structure version.
	dc.l	0,0,0			;Screen memory pointers 1/2/3.
	dc.l	0			;Screen link.
	dc.l	.Palette		;Address of screen palette.
	dc.l	0			;Address of rasterlist.
	dc.l	32			;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	5			;Amount of 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|COL24BIT		;Screen mode.
	dc.b	INTERLEAVED		;Screen type
	dc.b	0			;Reserved.
	even

.Palette
	dc.l	$000000,$101010,$171717,$202020
	dc.l	$272727,$303030,$373737,$404040
	dc.l	$474747,$505050,$575757,$606060
	dc.l	$676767,$707070,$777777,$808080
	dc.l	$878787,$909090,$979797,$a0a0a0
	dc.l	$a7a7a7,$b0b0b0,$b7b7b7,$c0c0c0
	dc.l	$c7c7c7,$d0d0d0,$d7d7d7,$e0e0e0
	dc.l	$e0e0e0,$f0f0f0,$f7f7f7,$ffffff

PixelList:
	dc.w	32			;Amount of entries.
MList	dc.w	160,128,00		;First pixel to draw (at back)
	dc.w	160,128,00		;X/Y/Colour
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
	dc.w	160,128,00		;..
MouseX	dc.w	160,128,31		;Last pixel to draw (in front)

