/*
 * MandelVroom 2.0
 *
 * (c) Copyright 1987,1989  Kevin L. Clague, San Jose, CA
 *
 * All rights reserved.
 *
 * Permission is hereby granted to distribute this program's source
 * executable, and documentation for non-comercial purposes, so long as the
 * copyright notices are not removed from the sources, executable or
 * documentation.  This program may not be distributed for a profit without
 * the express written consent of the author Kevin L. Clague.
 *
 * This program is not in the public domain.
 *
 * Fred Fish is expressly granted permission to distribute this program's
 * source and executable as part of the "Fred Fish freely redistributable
 * Amiga software library."
 *
 * Permission is expressly granted for this program and it's source to be
 * distributed as part of the Amicus Amiga software disks, and the
 * First Amiga User Group's Hot Mix disks.
 *
 * contents: this file contains the function that calculates the
 * Mandelbrot/Julia caluclation in 68881 assembly.  This funtion needs
 * work, so that it is all assembly instead of C and assembly.
 */

#include "mandp.h"
#include "parms.h"

Height_68881( p )
  struct PotentialParms *p;
{
  register LONG k;
  register double *P;

  k = p->MaxIteration;

  P = (double *) p;

#asm
;       mc68881
;
;four     equ   fp1
;curx     equ   fp2
;cury     equ   fp3
;cura     equ   fp4
;curb     equ   fp5
;cura2    equ   fp6
;curb2    equ   fp7
;
;
;  set up modulus
        fmove.d #"$4010000000000000",fp1
;
;  move posx and posy into fp4 and fp5
;  move curx and cury into fp2 and fp3
;
        fmove.d (a2)+,fp4
        fmove.d (a2)+,fp5
        fmove.d (a2)+,fp2
        fmove.d (a2),fp3
;
        fmove.x fp4,fp6
        fmove.x fp5,fp7
        fmul.x  fp6,fp6
        fmul.x  fp7,fp7
Loop
;
;    curb *= cura;
;    curb += curb + cury;
        fmul.x  fp4,fp5
        fadd.x  fp5,fp5
        fadd.x  fp3,fp5
;
;    cura = cura2 - curb2 + curx
        fsub.x  fp7,fp6
        fadd.x  fp2,fp6
;
;    curb2 = curb * curb;
        fmove.x fp5,fp7
        fmul.x  fp5,fp7
;
;    cura2 = cura * cura;
        fmove.x fp6,fp4
        fmul.x  fp6,fp6
;
;    if (cura2+curb2 > 4.0)
;      return( k );
        fmove.x fp6,fp0
        fadd.x  fp7,fp0
        fcmp.x  fp1,fp0
        fdbgt   d4,Loop
;       addq.l  #2,d4
;
#endasm
     ;
     return( p->MaxIteration - k );
}
