; this function writes a coloured pixel into the chunky buffer and returns
; colour of pixel that was in these coords originaly

; PutPixel(chunky:a0:PTR TO chunky,x:d0:LONG,y:d1:LONG,colour:d2:LONG)(LONG)

	machine	mc68020

	xdef	_PutPixel

_PutPixel
	cmpa.l	#0,a0
	beq.s	.finish
	tst.l	d0
	blt.s	.finish
	tst.l	d1
	blt.s	.finish
	cmp.l	(a0),d0
	bge.s	.finish
	cmp.l	(4,a0),d1
	bge.s	.finish

	movea.l	(8,a0),a1
	muls.l	(a0),d1
	add.l	d0,d1		; d1 now contains position in buffer
	move.b	(a1,d1.l),d0
	and.l	#$ff,d0
	move.b	d2,(a1,d1.l)

.finish	rts
