;-------T-------T------------------------T----------------------------------;
;Name:      Pixel Trail #2
;Author:    Paul Manias
;Copyright: DreamWorld Productions (c) 1996-1997.  Freely distributable.
;
;This demo demonstrates the usefulness of LISTs, by drawing a trail of
;pixels attached to the mouse.
;
;Press LMB to exit.

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

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

	SECTION	"Demo",CODE

	STARTGMS

Start:	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	Main

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

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

Main:	move.l	Screen(pc),a0
	lea	Mouse(pc),a2
	moveq	#JPORT1,d0
	moveq	#JT_ZBXY,d1
	CALL	ReadJoyPort
	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)
	bge.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.
	moveq	#32-1,d7
.tloop	move.l	PXL_SIZEOF(a3),PXL_XCoord(a3)
	addq.w	#PXL_SIZEOF,a3
	dbra	d7,.tloop

	move.l	Screen(pc),a0	;a0 = GameScreen
	move.l	GS_Bitmap(a0),a0	;a0 = Bitmap
	lea	PixelList(pc),a1	;a1 = Pixel list.
	CALL	DrawPixelList

	CALL	WaitVBL
	move.l	Screen(pc),a0
	CALL	SwapBuffers
	bra.s	Main
.done	rts

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

ScreenTags:
	dc.l	TAGS_GAMESCREEN
Screen:	dc.l	0
	dc.l	GSA_Palette,.palette
	dc.l	GSA_AmtColours,32
	dc.l	GSA_Attrib,DBLBUFFER
	dc.l	TAGEND
.palette
	dc.l	$000000,$101010,$202020,$303030,$404040,$505050,$606060,$707070
	dc.l	$808080,$909090,$a0a0a0,$b0b0b0,$c0c0c0,$d0d0d0,$e0e0e0,$f0f0f0
	dc.l	$000000,$101010,$202020,$303030,$404040,$505050,$606060,$707070
	dc.l	$808080,$909090,$a0a0a0,$b0b0b0,$c0c0c0,$d0d0d0,$e0e0e0,$ffffff

;---------------------------------------------------------------------------;

PixelList:
	dc.w	33,PXL_SIZEOF	;Amount of entries.
	dc.l	MList	;Pointer to pixel list array.
MList:	PIXEL	160,128,00	;First pixel to draw (at back)
	PIXEL	160,128,00	;X/Y/Colour
	PIXEL	160,128,01	;..
	PIXEL	160,128,02	;..
	PIXEL	160,128,03	;..
	PIXEL	160,128,04	;..
	PIXEL	160,128,05	;..
	PIXEL	160,128,06	;..
	PIXEL	160,128,07	;..
	PIXEL	160,128,08	;..
	PIXEL	160,128,09	;..
	PIXEL	160,128,10	;..
	PIXEL	160,128,11	;..
	PIXEL	160,128,12	;..
	PIXEL	160,128,13	;..
	PIXEL	160,128,14	;..
	PIXEL	160,128,15	;..
	PIXEL	160,128,16	;..
	PIXEL	160,128,17	;..
	PIXEL	160,128,18	;..
	PIXEL	160,128,19	;..
	PIXEL	160,128,20	;..
	PIXEL	160,128,21	;..
	PIXEL	160,128,22	;..
	PIXEL	160,128,23	;..
	PIXEL	160,128,24	;..
	PIXEL	160,128,25	;..
	PIXEL	160,128,26	;..
	PIXEL	160,128,27	;..
	PIXEL	160,128,28	;..
	PIXEL	160,128,29	;..
	PIXEL	160,128,30	;..
Mouse:	PIXEL	160,128,31	;Last pixel to draw (in front)

