;-------T-------T------------------------T----------------------------------;
;Name:      Draw Pixel
;Author:    Paul Manias
;Copyright: DreamWorld Productions (c) 1996-1997.  Freely distributable.
;
;Draws a pixel on a screen without destroying the background.

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

	SECTION	"DrawPixel",CODE

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

	STARTGMS

Start:	MOVEM.L	A0-A6/D1-D7,-(SP)
	move.l	GMSBase(pc),a6	;Activate user preferences.
	CALL	AllocBlitter	;Allocate the blitter.
	tst.l	d0
	bne	.Error_Blitter

	lea	FILE_Background(pc),a1	;Load the picture.
	moveq	#GETPALETTE|VIDEOMEM,d0
	CALL	LoadPicFile
	move.l	d0,PIC_Background
	beq.s	.Error_Picture

	CALL	GetScreen
	move.l	d0,Screen
	beq.s	.Error_Screen
	move.l	d0,a0
	move.l	PIC_Background(pc),a1
	move.w	#320,GS_ScrWidth(a0)
	move.w	#256,GS_ScrHeight(a0)
	move.l	PIC_AmtColours(a1),GS_AmtColours(a0)
	move.w	PIC_Planes(a1),GS_Planes(a0)
	move.w	PIC_Width(a1),GS_PicWidth(a0)
	move.w	PIC_Height(a1),GS_PicHeight(a0)
	move.l	PIC_Palette(a1),GS_Palette(a0)
	move.l	PIC_Data(a1),GS_MemPtr1(a0)
	move.w	PIC_ScrMode(a1),GS_ScrMode(a0)
	move.w	PIC_ScrType(a1),GS_ScrType(a0)
	CALL	AddScreen
	tst.l	d0
	beq.s	.Error_Screen

	CALL	ShowScreen

	CALL	InitJoyPorts

	bsr.s	Main

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

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

Main:	move.l	GMSBase(pc),a6

	moveq	#100,d6
	moveq	#100,d7

.loop	move.l	Screen(pc),a0
	move.l	GS_Bitmap(a0),a0
	movem.w	OldPixel(pc),d1/d2/d3
	tst.w	d3
	blt.s	.read
	CALL	DrawPixel	;>> = Draw the old background pixel.

.read	move.l	Screen(pc),a0
	move.l	GS_Bitmap(a0),a0
	move.w	d6,d1	;d1 = X Coordinate.
	move.w	d7,d2	;d2 = Y Coordinate.
	CALL	ReadPixel	;>> = Read the pixel.
	movem.w	d6/d7,OldPixel	;MA = Save coords of next pixel.
	move.w	d0,OldPixel+4	;MA = Save colour of next pixel.

	move.l	Screen(pc),a0
	move.l	GS_Bitmap(a0),a0
	move.w	#3,d3	;d3 = Colour.
	CALL	DrawPixel	;>> = Draw our pixel.

	CALL	WaitVBL	;>> = Wait for VBL.

	moveq	#JPORT1,d0	;Read the mouse, then update the
	moveq	#JT_ZBXY,d1	;BOB's X and Y co-ordinates.
	CALL	ReadJoyPort
	move.w	d0,d1
	ext.w	d0
	asr.w	#8,d1
	add.w	d0,d7
	add.w	d1,d6
	btst	#MB_LMB,d0
	beq.s	.loop
	rts

OldPixel:
	dc.w	0,0,-1

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

Screen:	dc.l	0

PIC_Background:
	dc.l	0

FILE_Background:
	dc.b	"GMS:demos/data/PIC.Green",0
	even

