
; Storm C Compiler
; Bud:C_SRC/powerpc/PPC-mandel2/mandelcalc.c
	mc68030
	mc68881
	XREF	_shared_pens

	SECTION ":0",CODE


;void DrawMandelbrot(struct Rect *view, struct DrawMsg *gfxport, int 
	XDEF	_DrawMandelbrot
_DrawMandelbrot
L118	EQU	-$B0
	link	a5,#L118
	movem.l	d2-d7/a2-a4,-(a7)
	fmovem.x fp2/fp3/fp4/fp5/fp6/fp7,-(a7)
	move.l	$10(a5),d1
	move.l	$C(a5),a1
	move.l	$8(a5),a3
L51
;	width = gfxport->xsize;
	move.l	$C(a1),d7
;	height = gfxport->ysize;
	move.l	$10(a1),-$10(a5)
;	dx = (view->x1 - view->x0) / (double) width;
	move.l	$10(a3),-$28(a5)
	move.l	$14(a3),-$24(a5)
	fmove.d	-$28(a5),fp0
	fsub.d	(a3),fp0
	fmove.d	fp0,-$28(a5)
	fmove.l	d7,fp0
	fmove.d	-$28(a5),fp1
	fdiv.x	fp0,fp1
	fmove.d	fp1,-$28(a5)
;	dy = (view->y1 - view->y0) / (double) height;
	move.l	$18(a3),-$30(a5)
	move.l	$1C(a3),-$2C(a5)
	fmove.d	-$30(a5),fp0
	fsub.d	$8(a3),fp0
	fmove.d	fp0,-$30(a5)
	fmove.l	-$10(a5),fp0
	fmove.d	-$30(a5),fp1
	fdiv.x	fp0,fp1
	fmove.d	fp1,-$30(a5)
;	cy = view->y0;
	fmove.d	$8(a3),fp7
;	for (y = gfxport->offsety;
	move.l	$8(a1),d5
	bra	L116
L52
;	
;		cx = view->x0;
	fmove.d	(a3),fp4
;		for (x = gfxport->offsetx;
	move.l	4(a1),d4
	bra	L114
L53
;		
;			double zx = 0.0;
	fmove.d	#$.00000000.00000000,fp2
;			double zy = 0.0;
	fmove.d	#$.00000000.00000000,fp1
;			int i = N;
	move.l	d1,d0
;			double c = 16.0;
	fmove.d	#$.40300000.00000000,fp5
;			
L54
;			
;				h1 = zx*zx;
	fmove.x	fp2,fp0
	fmul.x	fp2,fp0
;				h2 = zy*zy;
	fmove.x	fp1,fp3
	fmul.x	fp1,fp3
;				g = zx*zy;
	fmul.x	fp2,fp1
;				h3 = h1 - h2;
	fmove.x	fp0,fp2
	fsub.x	fp3,fp2
;				h4 = g+g;
	fmove.x	fp1,fp6
	fadd.x	fp1,fp6
	fmove.x	fp6,fp1
;				zx = h3 + cx;
	fadd.x	fp4,fp2
;				zy = h4 + cy;
	fadd.x	fp7,fp1
;				i--;
	subq.l	#1,d0
	fadd.x	fp3,fp0
	fcmp.x	fp5,fp0
	fboge.b	L56
L55
	tst.l	d0
	bne.b	L54
L56
;			i = N - i;
	move.l	d1,d2
	sub.l	d0,d2
	move.l	d2,d0
;			address = gfxport->memptr + y * gfxport->bytesperrow + x * gfx
	moveq	#0,d2
	move.w	$14(a1),d2
	muls.l	d5,d2
	move.l	(a1),a0
	add.l	d2,a0
	moveq	#0,d2
	move.w	$16(a1),d2
	muls.l	d4,d2
	add.l	d2,a0
;			switch (gfxport->colormodel)
	move.w	$18(a1),d2
	cmp.w	#$D,d2
	bhi	L113
	move.l	L119(pc,d2.w*4),a2
	jmp	(a2)
L119
	dc.l	L57
	dc.l	L61
	dc.l	L65
	dc.l	L69
	dc.l	L73
	dc.l	L77
	dc.l	L81
	dc.l	L85
	dc.l	L89
	dc.l	L93
	dc.l	L97
	dc.l	L101
	dc.l	L105
	dc.l	L109
;			
;				
L57
;					if (i < N)
	cmp.l	d1,d0
	bge.b	L59
L58
;						*address = shared_pens[(UBYTE)(i*256/N)];
	moveq	#$8,d2
	asl.l	d2,d0
	divsl.l	d1,d0
	and.l	#$FF,d0
	move.l	#_shared_pens,a4
	move.b	0(a4,d0.l),(a0)
	bra	L113
L59
;						*address = shared_pens[0];
	move.l	#_shared_pens,a2
	move.b	(a2),(a0)
L60
;					
	bra	L113
L61
;					if (i < N)
	cmp.l	d1,d0
	bge.b	L63
L62
;						*((UWORD *) address) = ((i*32/N) << 10) | ((i*32/N) << 5)
	move.l	d0,d2
	moveq	#5,d3
	asl.l	d3,d2
	divsl.l	d1,d2
	moveq	#$A,d3
	asl.l	d3,d2
	move.l	d0,d3
	moveq	#5,d6
	asl.l	d6,d3
	divsl.l	d1,d3
	moveq	#5,d6
	asl.l	d6,d3
	or.l	d3,d2
	moveq	#5,d3
	asl.l	d3,d0
	divsl.l	d1,d0
	or.l	d0,d2
	move.w	d2,(a0)
	bra	L113
L63
;						*((UWORD *) address) = 0;
	clr.w	(a0)
L64
;					
	bra	L113
L65
;					if (i < N)
	cmp.l	d1,d0
	bge.b	L67
L66
;						*((UWORD *) address) = ((i*32/N) << 10) | ((i*32/N) << 5)
	move.l	d0,d2
	moveq	#5,d3
	asl.l	d3,d2
	divsl.l	d1,d2
	moveq	#$A,d3
	asl.l	d3,d2
	move.l	d0,d3
	moveq	#5,d6
	asl.l	d6,d3
	divsl.l	d1,d3
	moveq	#5,d6
	asl.l	d6,d3
	or.l	d3,d2
	moveq	#5,d3
	asl.l	d3,d0
	divsl.l	d1,d0
	or.l	d0,d2
	move.w	d2,(a0)
	bra	L113
L67
;						*((UWORD *) address) = 0;
	clr.w	(a0)
L68
;					
	bra	L113
L69
;					if (i < N)
	cmp.l	d1,d0
	bge.b	L71
L70
;					
;						UWORD c = ((i*32/N) << 10) | ((i*32/N) << 5) | (i*32/N);
	move.l	d0,d2
	moveq	#5,d3
	asl.l	d3,d2
	divsl.l	d1,d2
	moveq	#$A,d3
	asl.l	d3,d2
	move.l	d0,d3
	moveq	#5,d6
	asl.l	d6,d3
	divsl.l	d1,d3
	moveq	#5,d6
	asl.l	d6,d3
	or.l	d3,d2
	moveq	#5,d3
	asl.l	d3,d0
	divsl.l	d1,d0
	or.l	d0,d2
	move.w	d2,d0
;						*address++ = c;
	move.b	d0,(a0)+
;						*address = c >> 8;
	and.l	#$FFFF,d0
	moveq	#$8,d2
	asr.l	d2,d0
	move.b	d0,(a0)
	bra	L113
L71
;						*((UWORD *) address) = 0;
	clr.w	(a0)
L72
;					
	bra	L113
L73
;					if (i < N)
	cmp.l	d1,d0
	bge.b	L75
L74
;					
;						UWORD c = ((i*32/N) << 10) | ((i*32/N) << 5) | (i*32/N);
	move.l	d0,d2
	moveq	#5,d3
	asl.l	d3,d2
	divsl.l	d1,d2
	moveq	#$A,d3
	asl.l	d3,d2
	move.l	d0,d3
	moveq	#5,d6
	asl.l	d6,d3
	divsl.l	d1,d3
	moveq	#5,d6
	asl.l	d6,d3
	or.l	d3,d2
	moveq	#5,d3
	asl.l	d3,d0
	divsl.l	d1,d0
	or.l	d0,d2
	move.w	d2,d0
;						*address++ = c;
	move.b	d0,(a0)+
;						*address = c >> 8;
	and.l	#$FFFF,d0
	moveq	#$8,d2
	asr.l	d2,d0
	move.b	d0,(a0)
	bra	L113
L75
;						*((UWORD *) address) = 0;
	clr.w	(a0)
L76
;					
	bra	L113
L77
;					if (i < N)
	cmp.l	d1,d0
	bge.b	L79
L78
;						*((UWORD *) address) = ((i*32/N) << 11) | ((i*64/N) << 5)
	move.l	d0,d2
	moveq	#5,d3
	asl.l	d3,d2
	divsl.l	d1,d2
	moveq	#$B,d3
	asl.l	d3,d2
	move.l	d0,d3
	moveq	#6,d6
	asl.l	d6,d3
	divsl.l	d1,d3
	moveq	#5,d6
	asl.l	d6,d3
	or.l	d3,d2
	moveq	#5,d3
	asl.l	d3,d0
	divsl.l	d1,d0
	or.l	d0,d2
	move.w	d2,(a0)
	bra	L113
L79
;						*((UWORD *) address) = 0;
	clr.w	(a0)
L80
;					
	bra	L113
L81
;					if (i < N)
	cmp.l	d1,d0
	bge.b	L83
L82
;						*((UWORD *) address) = ((i*32/N) << 11) | ((i*64/N) << 5)
	move.l	d0,d2
	moveq	#5,d3
	asl.l	d3,d2
	divsl.l	d1,d2
	moveq	#$B,d3
	asl.l	d3,d2
	move.l	d0,d3
	moveq	#6,d6
	asl.l	d6,d3
	divsl.l	d1,d3
	moveq	#5,d6
	asl.l	d6,d3
	or.l	d3,d2
	moveq	#5,d3
	asl.l	d3,d0
	divsl.l	d1,d0
	or.l	d0,d2
	move.w	d2,(a0)
	bra	L113
L83
;						*((UWORD *) address) = 0;
	clr.w	(a0)
L84
;					
	bra	L113
L85
;					if (i < N)
	cmp.l	d1,d0
	bge.b	L87
L86
;					
;						UWORD c = ((i*32/N) << 11) | ((i*64/N) << 5) | (i*32/N);
	move.l	d0,d2
	moveq	#5,d3
	asl.l	d3,d2
	divsl.l	d1,d2
	moveq	#$B,d3
	asl.l	d3,d2
	move.l	d0,d3
	moveq	#6,d6
	asl.l	d6,d3
	divsl.l	d1,d3
	moveq	#5,d6
	asl.l	d6,d3
	or.l	d3,d2
	moveq	#5,d3
	asl.l	d3,d0
	divsl.l	d1,d0
	or.l	d0,d2
	move.w	d2,d0
;						*address++ = c;
	move.b	d0,(a0)+
;						*address = c >> 8;
	and.l	#$FFFF,d0
	moveq	#$8,d2
	asr.l	d2,d0
	move.b	d0,(a0)
	bra	L113
L87
;						*((UWORD *) address) = 0;
	clr.w	(a0)
L88
;					
	bra	L113
L89
;					if (i < N)
	cmp.l	d1,d0
	bge.b	L91
L90
;					
;						UWORD c = ((i*32/N) << 11) | ((i*64/N) << 5) | (i*32/N);
	move.l	d0,d2
	moveq	#5,d3
	asl.l	d3,d2
	divsl.l	d1,d2
	moveq	#$B,d3
	asl.l	d3,d2
	move.l	d0,d3
	moveq	#6,d6
	asl.l	d6,d3
	divsl.l	d1,d3
	moveq	#5,d6
	asl.l	d6,d3
	or.l	d3,d2
	moveq	#5,d3
	asl.l	d3,d0
	divsl.l	d1,d0
	or.l	d0,d2
	move.w	d2,d0
;						*address++ = c;
	move.b	d0,(a0)+
;						*address = c >> 8;
	and.l	#$FFFF,d0
	moveq	#$8,d2
	asr.l	d2,d0
	move.b	d0,(a0)
	bra	L113
L91
;						*((UWORD *) address) = 0;
	clr.w	(a0)
L92
;					
	bra	L113
L93
;					if (i < N)
	cmp.l	d1,d0
	bge.b	L95
L94
;					
;						*((UWORD *) address)++ = ((i*256/N) << 8) | (i*256/N);
	move.l	d0,d2
	moveq	#$8,d3
	asl.l	d3,d2
	divsl.l	d1,d2
	moveq	#$8,d3
	asl.l	d3,d2
	move.l	d0,d3
	moveq	#$8,d6
	asl.l	d6,d3
	divsl.l	d1,d3
	or.l	d3,d2
	move.w	d2,(a0)+
;						*address = i*256/N;
	moveq	#$8,d2
	asl.l	d2,d0
	divsl.l	d1,d0
	move.b	d0,(a0)
	bra	L113
L95
;					
;						*((UWORD *) address)++ = 0;
	clr.w	(a0)+
;						*address = 0;
	clr.b	(a0)
L96
;					
	bra	L113
L97
;					if (i < N)
	cmp.l	d1,d0
	bge.b	L99
L98
;					
;						*((UWORD *) address)++ = ((i*256/N) << 8) | (i*256/N);
	move.l	d0,d2
	moveq	#$8,d3
	asl.l	d3,d2
	divsl.l	d1,d2
	moveq	#$8,d3
	asl.l	d3,d2
	move.l	d0,d3
	moveq	#$8,d6
	asl.l	d6,d3
	divsl.l	d1,d3
	or.l	d3,d2
	move.w	d2,(a0)+
;						*address = i*256/N;
	moveq	#$8,d2
	asl.l	d2,d0
	divsl.l	d1,d0
	move.b	d0,(a0)
	bra	L113
L99
;					
;						*((UWORD *) address)++ = 0;
	clr.w	(a0)+
;						*address = 0;
	clr.b	(a0)
L100
;					
	bra	L113
L101
;					if (i < N)
	cmp.l	d1,d0
	bge.b	L103
L102
;					
;						*((ULONG *) address) = ((i*256/N) << 16) | ((i*256/N) <<
	move.l	d0,d2
	moveq	#$8,d3
	asl.l	d3,d2
	divsl.l	d1,d2
	moveq	#$10,d3
	asl.l	d3,d2
	move.l	d0,d3
	moveq	#$8,d6
	asl.l	d6,d3
	divsl.l	d1,d3
	moveq	#$8,d6
	asl.l	d6,d3
	or.l	d3,d2
	moveq	#$8,d3
	asl.l	d3,d0
	divsl.l	d1,d0
	or.l	d0,d2
	move.l	d2,(a0)
	bra.b	L113
L103
;					
;						*((ULONG *) address) = 0;
	clr.l	(a0)
L104
;					
	bra.b	L113
L105
;					if (i < N)
	cmp.l	d1,d0
	bge.b	L107
L106
;					
;						*((ULONG *) address) = ((i*256/N) << 24) | ((i*256/N) <<
	move.l	d0,d2
	moveq	#$8,d3
	asl.l	d3,d2
	divsl.l	d1,d2
	moveq	#$18,d3
	asl.l	d3,d2
	move.l	d0,d3
	moveq	#$8,d6
	asl.l	d6,d3
	divsl.l	d1,d3
	moveq	#$10,d6
	asl.l	d6,d3
	or.l	d3,d2
	moveq	#$8,d3
	asl.l	d3,d0
	divsl.l	d1,d0
	moveq	#$8,d3
	asl.l	d3,d0
	or.l	d0,d2
	move.l	d2,(a0)
	bra.b	L113
L107
;					
;						*((ULONG *) address) = 0;
	clr.l	(a0)
L108
;					
	bra.b	L113
L109
;					if (i < N)
	cmp.l	d1,d0
	bge.b	L111
L110
;					
;						*((ULONG *) address) = ((i*256/N) << 24) | ((i*256/N) <<
	move.l	d0,d2
	moveq	#$8,d3
	asl.l	d3,d2
	divsl.l	d1,d2
	moveq	#$18,d3
	asl.l	d3,d2
	move.l	d0,d3
	moveq	#$8,d6
	asl.l	d6,d3
	divsl.l	d1,d3
	moveq	#$10,d6
	asl.l	d6,d3
	or.l	d3,d2
	moveq	#$8,d3
	asl.l	d3,d0
	divsl.l	d1,d0
	moveq	#$8,d3
	asl.l	d3,d0
	or.l	d0,d2
	move.l	d2,(a0)
	bra.b	L113
L111
;					
;						*((ULONG *) address) = 0;
	clr.l	(a0)
L112
;					
L113
;			cx += dx;
	fadd.d	-$28(a5),fp4
	addq.l	#1,d4
L114
	cmp.l	d7,d4
	blt	L53
L115
;		cy += dy;
	fmove.x	fp7,fp0
	fadd.d	-$30(a5),fp0
	fmove.d	fp0,fp7
	addq.l	#1,d5
L116
	cmp.l	-$10(a5),d5
	blt	L52
L117
	fmovem.x (a7)+,fp2/fp3/fp4/fp5/fp6/fp7
	movem.l	(a7)+,d2-d7/a2-a4
	unlk	a5
	rts

	END
