
; HLine(chunky:a0:PTR TO chunky,x1:d0:LONG,x2:d1:LONG,y:d2:LONG,colour:d3:LONG)(LONG)

	machine	mc68020

	xdef	_HLine

_HLine
	movem.l	d2-d5,-(a7)
	move.l	(a0),d4
	move.l	(4,a0),d5
	movea.l	(8,a0),a1
	tst.l	d2
	blt.s	.finish		; above screen
	cmp.l	d2,d5
	ble.s	.finish		; below screen
	cmp.l	d0,d1
	bge.s	.continue
	exg	d0,d1		; forces d0 to contain lower value
.continue	tst.l	d1
	blt.s	.finish		; left to the screen
	cmp.l	d0,d4
	ble.s	.finish		; right to the screen

	tst.l	d0
	bge.s	.next1		; clip by left side
	moveq	#0,d0
.next1	cmp.l	d1,d4
	bgt.s	.next2		; clip by right side
	move.l	d4,d1
	subq.w	#1,d1
.next2
	muls.l	d4,d2
	add.l	d0,d2		; d2 contains position of first pixel
	sub.l	d0,d1		; d1 contains count of pixels
	add.l	d2,a1		; set first position

.loop	move.b	d3,(a1)+
	dbra.s	d1,.loop

.finish	movem.l	(a7)+,d2-d5
	rts
