************************************************************************
**            Written by Dino Papararo            25-April-2001
**
**  FUNCTION
**
**    Mandel68K -- perform Z = Zē + C iteration.
**
**  SYNOPSIS
**
**    WORD Mandel68K (WORD Iterations,double Cre,double Cim)
**
**
**  DESCRIPTION
**
**  C equivalent function:
**
**      ***************************************************************
**      *WORD Mandel68K (WORD Iterazioni,double Cre,double Cim)     ***
**      *{                                                          ***
**      *register double zr,zi,zi2,dist,maxdist;                    ***
**      *                                                           ***
**      *  zi = Cim;                                                ***
**      *                                                           ***
**      *  zr = Cre;                                                ***
**      *                                                           ***
**      *  maxdist = 4;                                             ***
**      *                                                           ***
**      *  do {                                                     ***
**      *       zi2 = zi;                                           ***
**      *                                                           ***
**      *       zi  *= zr;                                          ***
**      *                                                           ***
**      *       zr  *= zr;                                          ***
**      *                                                           ***
**      *       zi2 *= zi2;                                         ***
**      *                                                           ***
**      *       dist = zr;                                          ***
**      *                                                           ***
**      *       dist += zi2;                                        ***
**      *                                                           ***
**      *       if (dist > maxdist) return Iterazioni;              ***
**      *                                                           ***
**      *       zi += zi;                                           ***
**      *                                                           ***
**      *       zr -= zi2;                                          ***
**      *                                                           ***
**      *       zi += Cim;                                          ***
**      *                                                           ***
**      *       zr += Cre;                                          ***
**      *                                                           ***
**      *     } while (-- Iterazioni);                              ***
**      *                                                           ***
**      *  return 0;                                                ***
**      *}                                                          ***
**      ***************************************************************
**
**  This function tests if a point belongs or not at mandelbrot's set
**
**  Optimized for pipelines of 68882+ coprocessors
**
**  NOTICE: ALL VARIABLES ARE INTO REGISTERS FOR FULL SPEEEED
**
**  d0:Iterations
**
**  fp0:Cre fp1:Cim fp2:Zr fp3:Zi fp4:Zi2 fp5:Zr2/Dist fp6:MaxDist fp7:NotUsed ;-)
**********************************************************************************

*        MACHINE  68060

        XDEF  _Mandel68K

        section data

Radius  dc.x  4.0

        section code

_Mandel68K:


        fmove.x fp1,fp3      * Zi = Cim
        fmove.x fp0,fp2      * Zr = Cre
        fmove.x Radius,fp6   * MaxDist = 4.0

Loop:
        fmove.x fp3,fp4      * zi2   = zi
        fmul.x  fp2,fp3      * zi    = zr * zi
        fmul.x  fp2,fp2      * zr    = zr * zr
        fmul.x  fp4,fp4      * zi2   = zi * zi

        fmove.x fp2,fp5      * dist  = zr2
        fadd.x  fp4,fp5      * dist += zi2
        fcmp.x  fp6,fp5      * Compare MaxDist & Dist
        fbgt.w  Exit         * if Dist > MaxDist then goto Exit

        fadd.x  fp3,fp3      * zi   += zi
        fsub.x  fp4,fp2      * zr   -= zi2

        fadd.x  fp1,fp3      * zi   += Cim
        fadd.x  fp0,fp2      * zr   += Cre

        dbra.w  d0,Loop      * if --Iterations != -1 go to Loop
        clr.w   d0           * Iterations = 0

Exit:

        rts                  * return Iterations

        end
