Date sent:        Thu, 30 Oct 1997 17:17:36 +0200 (EET)
From:             Harry Sintonen <sintonen@jyu.fi>
To:               amycoders@ibm.net
Subject:          sizeopt entry for #amycoders trianglefilling compo

*********************************************************************
*
* Your init code comes here.
*
*********************************************************************

_initcode
a

b
	rts
		
	
*********************************************************************
*
* Your line routine.
* Every time you are given: A0.L : Chunky Screen (256x256x8)
*
* D0.l  color
* A1    {x1,y1,x2,y2,x3,y3}.w
*
* other registers are in undefined state !!
* you may trash all regs except a7
*
*********************************************************************

	CNOP	0,4
_triangle
c

;****************************************************************************
;**
;*       Size-optimized chunky triangledraw routine
;*
;*  This is one of my contributions to #amycoders triangledrawing-compo. This
;*  routine will participate size-optimizing competition. This code works
;*  with all 0x0 processors with any cache setup.
;*
;*  Code size without rts: 42 bytes.
;*  Average time (dec): dead slow
;*
;*  Coded by Harry "Piru" Sintonen <sintonen@jyu.fi>.
;*  This code is copyright © 1997 by Harry Sintonen, and was written 24th-
;*  30th october 1997.
;*
;****************************************************************************
;*

;  IN: d0.l=color
;      a0=chunky buffer (256x256x8)
;      a1={x1,y1,x2,y2,x3,y3}.w
; OUT: d1-d3/a1 trashed

	movem.l	(a1),d1-d3	4 d1=x1y1, d2=x2y2, d3=x3y3

.tri	addq.b	#8,(a1)		2 recursion done? (a1).b is initially zero
	bmi.b	.ret		2 and will be restored to this value ;)

	move.l	d1,-(sp)	2 store point 1
	add.l	d2,d1		2
	lsr.l	#1,d1		2
	and.w	#$7FFF,d1	4 m=(1+2)/2

	exg	d1,d3		2 swap m & 3
	bsr.b	.tri		2 tri(3,2,m)
	move.l	(sp),d2		2 get 1
	bsr.b	.tri		2 tri(3,1,m)
				; 00xm00ym
	swap	d3		2 00ym00xm
	lsl.w	#8,d3		2 00ymxm00
	lsr.l	#8,d3		2 0000ymxm
	move.b	d0,0(a0,d3.l)	4 putpixel(xm,ym,color)
	move.l	(sp)+,d3	2 restore orig 1
	exg	d1,d3		2 swap 1 & 3
.ret	subq.b	#8,(a1)		2
d				;=42
	rts


;	Comment this out on Asmone for auto length-output

;	printt	"Length of your code:"
;	printv	((b-a)+(d-c))

;len	dc.l	((b-a)+(d-c))

