;Draw Pixel
;----------
;This demo draws a pixel to the screen 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	"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:	lea	Screen(pc),a0
.loop	moveq	#JPORT1,d0
	CALL	Read_Mouse
	btst	#MB_LMB,d0
	bne.s	.done

	move.w	d0,d1
	ext.w	d1
	add.w	d1,.MouseY
	asr.w	#8,d0
	add.w	d0,.MouseX

.ChkLX	tst.w	.MouseX
	bge.s	.ChkRX
	clr.w	.MouseX
.ChkRX	cmp.w	#319,.MouseX
	ble.s	.ChkTY
	move.w	#319,.MouseX
.ChkTY	tst.w	.MouseY
	bge.s	.ChkBY
	clr.w	.MouseY
.ChkBY	cmp.w	#255,.MouseY
	ble.s	.Draw
	move.w	#255,.MouseY

.Draw	moveq	#BUFFER1,d0
	move.w	.MouseX(pc),d1	;d1 = X Coordinate
	move.w	.MouseY(pc),d2	;d2 = Y Coordinate
	moveq	#6,d3	;d3 = Colour.
	CALL	Draw_Pixel

	CALL	Wait_OSVBL

	moveq	#0,d3	;d3 = Colour (0)
	CALL	Draw_Pixel

	bra.s	.loop
.done	rts

.MouseX	dc.w	40
.MouseY	dc.w	40

;===========================================================================;
;                                  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_Mem1/2/3
	dc.l	0	;Screen link.
	dc.l	.Palette	;Address of screen palette.
	dc.l	0	;Address of rasterlist.
	dc.l	1<<3	;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	3	;Amt_Planes
	dc.w	0,0	;X/Y screen offset.
	dc.w	0,0	;X/Y picture offset.
	dc.l	0	;Special attributes.
	dc.w	LORES|COL12BIT	;Screen mode.
	dc.b	INTERLEAVED	;Screen type
	dc.b	0	;Reserved.
	even

.Palette
	dc.w	$000,$fff,$0f0,$f00,$ff0,$f0f,$ff0,$0ff
