;Draw Pixel List (OCS/ECS)
;-------------------------
;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

	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:	CALL	InitJoyPorts
	lea	Screen(pc),a0
	lea	Mouse(pc),a2

.loop	moveq	#JPORT1,d0
	CALL	Read_Mouse
	btst	#MB_LMB,d0
	bne.s	.done

	move.w	d0,d1
	ext.w	d1
	add.w	d1,2(a2)
	asr.w	#8,d0
	add.w	d0,(a2)

.ChkLX	tst.w	(a2)
	bgt.s	.ChkRX
	clr.w	(a2)
.ChkRX	cmp.w	#319,(a2)
	ble.s	.ChkTY
	move.w	#319,(a2)
.ChkTY	tst.w	2(a2)
	bge.s	.ChkBY
	clr.w	2(a2)
.ChkBY	cmp.w	#255,2(a2)
	ble.s	.Draw
	move.w	#255,2(a2)

.Draw	lea	MList(pc),a3	;Shift the list up a place so that
	moveq	#16-1,d7
.tloop	move.l	6(a3),(a3)
	addq.w	#6,a3
	dbra	d7,.tloop

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

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

PixelList:
	dc.w	17	;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,01	;..
	dc.w	160,128,02	;..
	dc.w	160,128,03	;..
	dc.w	160,128,04	;..
	dc.w	160,128,05	;..
	dc.w	160,128,06	;..
	dc.w	160,128,07	;..
	dc.w	160,128,08	;..
	dc.w	160,128,09	;..
	dc.w	160,128,10	;..
	dc.w	160,128,11	;..
	dc.w	160,128,12	;..
	dc.w	160,128,13	;..
	dc.w	160,128,14	;..
Mouse:	dc.w	160,128,15	;Last pixel to draw (in front)

;===========================================================================;
;                                  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	16	;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	4	;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|COL12BIT	;Screen mode.
	dc.b	INTERLEAVED	;Screen type
	dc.b	0	;Reserved.
	even

.Palette
	dc.w	$000,$111,$222,$333,$444,$555,$666,$777
	dc.w	$888,$999,$AAA,$BBB,$CCC,$DDD,$EEE,$FFF

