home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff214.lzh / MandelVroom / src / orbitint.c < prev    next >
C/C++ Source or Header  |  1989-05-30  |  7KB  |  265 lines

  1. /*
  2.  * MandelVroom 2.0
  3.  *
  4.  * (c) Copyright 1987,1989  Kevin L. Clague, San Jose, CA
  5.  *
  6.  * All rights reserved.
  7.  *
  8.  * Permission is hereby granted to distribute this program's source
  9.  * executable, and documentation for non-comercial purposes, so long as the
  10.  * copyright notices are not removed from the sources, executable or
  11.  * documentation.  This program may not be distributed for a profit without
  12.  * the express written consent of the author Kevin L. Clague.
  13.  *
  14.  * This program is not in the public domain.
  15.  *
  16.  * Fred Fish is expressly granted permission to distribute this program's
  17.  * source and executable as part of the "Fred Fish freely redistributable
  18.  * Amiga software library."
  19.  *
  20.  * Permission is expressly granted for this program and it's source to be
  21.  * distributed as part of the Amicus Amiga software disks, and the
  22.  * First Amiga User Group's Hot Mix disks.
  23.  *
  24.  * contents: this file contains functions to calculate and draw orbits for
  25.  * fixed point (scaled int) math mode.
  26.  */
  27.  
  28. #include "mandp.h"
  29.  
  30. #include "parms.h"
  31.  
  32. static double x_scale,  y_scale;
  33. static int    x_center, y_center;
  34. static int    rightedge,botedge;
  35. static struct RastPort *Rp;
  36.  
  37. extern SHORT MaxOrbit;
  38.  
  39. #define ORBSHIFT 27
  40. #define ORBINT(f) ((int)((f)*(double)(1<<ORBSHIFT)))
  41.  
  42. InitIntOrbit()
  43. {
  44.   register struct Window *Window;
  45.   register int    width,  height;
  46.  
  47.   Window = OrbitWind;
  48.   Rp = Window->RPort;
  49.  
  50.   width  = (Window->Width-LEFTMARG-RIGHTMARG);
  51.   height = (Window->Height-TOPMARG-BOTMARG);
  52.  
  53.   rightedge = width + LEFTMARG - 1;
  54.   botedge   = height + TOPMARG - 1;
  55.  
  56.   x_scale = y_scale = (float) height / (2.0 * (double)(1<<ORBSHIFT));
  57.  
  58.   x_center = width/2 + LEFTMARG;
  59.   y_center = height/2 + TOPMARG;
  60. }
  61.  
  62. static char first_flag;
  63.  
  64. DrawOrbitInt( Pict )
  65.   struct Picture *Pict;
  66. {
  67.   struct IntPotParms Parms;
  68.   LONG creal, cimag;
  69.   LONG sreal, simag;
  70.  
  71.   InitIntOrbit();
  72.  
  73.   creal = ORBINT( Pict->RealLow + (MouseX-Pict->LeftMarg) * Pict->RealGap );
  74.   cimag = ORBINT( Pict->ImagLow + (MouseY-Pict->TopMarg)  * Pict->ImagGap );
  75.  
  76.   sreal = ORBINT( Pict->Real );
  77.   simag = ORBINT( Pict->Imag );
  78.  
  79.   if ( Pict->pNode.ln_Type == MANDPICT ) {
  80.  
  81.     Parms.C_Real = creal;
  82.     Parms.C_Imag = cimag;
  83.  
  84.     Parms.ScreenReal = sreal;
  85.     Parms.ScreenImag = simag;
  86.   } else {
  87.  
  88.     Parms.C_Real = sreal;
  89.     Parms.C_Imag = simag;
  90.  
  91.     Parms.ScreenReal = creal;
  92.     Parms.ScreenImag = cimag;
  93.   }
  94.  
  95.   Parms.MaxIteration = MaxOrbit;
  96.  
  97.   /* Clear the window for next display plot */
  98.  
  99.   SetAPen(Rp, 0);
  100.   RectFill(Rp, LEFTMARG,TOPMARG, rightedge, botedge);
  101.   SetAPen(Rp, HIGHLIGHTPEN);
  102.  
  103.   first_flag = 0;
  104.  
  105.   Orbit3216( &Parms );
  106. }
  107.  
  108. PlotIntOrbit( zreal, zimag )
  109.   LONG zreal, zimag;
  110. {
  111.   int x,y;
  112.  
  113.   x = x_center + (int)((double) zreal * x_scale);
  114.   y = y_center + (int)((double) zimag * y_scale);
  115.  
  116.   if (x >= LEFTMARG && x <= rightedge &&
  117.       y >= TOPMARG  && y <= botedge   &&
  118.       first_flag == 1                   ) {
  119.  
  120.     WritePixel( Rp, x, y );
  121.   }
  122.   first_flag = 1;
  123. }
  124.  
  125. /*
  126.  *  Orbit display for 32 bit math using 16 bit multiplies.
  127.  *  It is written for the 68000 instruction set.
  128.  */
  129. Orbit3216( Parms )
  130.  
  131.   struct IntPotParms *Parms;
  132. {
  133.   LONG Height;
  134.  
  135.   register struct IntPotParms *P = Parms;
  136.  
  137.   register LONG cura, curb, cura2, curb2;
  138.  
  139. #asm
  140. height  equ -4
  141. Bits2Shift equ  5
  142. ;
  143. ;
  144. ;  d1 - BITS2SHIFT
  145. ;  d2 - k
  146. ;  d4 - a
  147. ;  d5 - b
  148. ;  d6 - a2
  149. ;  d7 - b2
  150. ;
  151. screenr  equ 0
  152. screeni  equ 4
  153. curx     equ 8
  154. cury     equ 12
  155. maxi     equ 16
  156. ;
  157.    move.l   #Bits2Shift,d1
  158.    move.l   screenr(a2),d4
  159.    move.l   screeni(a2),d5
  160.    move.w   maxi(a2),d2
  161.    bra      Fposa2
  162. ;
  163. FKLoop
  164. ;
  165. ;  cura = cura2 - curb2 + curx;
  166.    exg      d6,d4       ; exchange cura and cura2
  167.    sub.l    d7,d4       ; subtract curb
  168.    add.l    curx(a2),d4 ; add curx
  169. ;
  170. ;  curb = cura * curb >> 12;
  171.    move.l   d6,d7      ; get copy of op1 sign bit
  172.    bpl      Fpos1       ; get absolute value of op1
  173.    neg.l    d6
  174. Fpos1
  175.    eor.l    d5,d7      ; calculate result sign
  176.    tst.l    d5         ; get absolute value of op2
  177.    bpl      Fpos2
  178.    neg.l    d5
  179. Fpos2
  180.    move.l   d6,d0      ; get a copy of op1
  181.    swap     d0         ; get high half of op1
  182.    move.w   d0,d7      ; save a copy of high half
  183.    mulu     d5,d0      ; multiply op2 low by op1 high
  184.    clr.w    d0         ;  clear least significant part
  185.    swap     d0         ;  put it in it's place
  186.    swap     d5         ; get high half of op2
  187.    mulu     d5,d6      ; multiply op2 high with op1 low
  188.    clr.w    d6         ;  clear least significant part
  189.    swap     d6         ;  put it in its place
  190.    mulu     d7,d5      ; multiply op2 high by op1 high
  191.    add.l    d0,d5      ; add partial results
  192.    add.l    d6,d5      ; add partial results
  193.    tst.l    d7         ; is the result negative?
  194.    bpl      Fpos3
  195.    neg.l    d5         ; yes, better negate it.
  196. Fpos3
  197.    asl.l    d1,d5      ; now, rescale it.
  198. ;
  199. ;  curb += curb + cury;
  200.    add.l    d5,d5      ; double it and add cury
  201.    add.l    cury(a2),d5
  202. Fposa2
  203. ;
  204. ;  cura2 = cura * cura;
  205.    move.l   d4,d0      ; get absolute value of a in d0
  206.    bpl      Fposa
  207.    neg.l    d0
  208. Fposa
  209.    move.l   d0,d6      ; copy absolute value into d6
  210.    swap     d6         ; get high part in d6
  211.    mulu     d6,d0      ; multiply high and low destroying low
  212.    clr.w    d0         ; clear the least significant part
  213.    swap     d0         ; put most sig. part in low half
  214.    mulu     d6,d6      ; multiply high and high destroing high
  215.    add.l    d0,d6      ; add in lower half twice
  216.    add.l    d0,d6
  217.    asl.l    d1,d6      ; get radix point back in correct place
  218.    bvs      Fbailout
  219. ;
  220. ;  curb2 = curb * curb;
  221.    move.l   d5,d0      ; get absolute value of a in d0
  222.    bpl      Fposb
  223.    neg.l    d0
  224. Fposb
  225.    move.l   d0,d7      ; copy absolute value into d7
  226.    swap     d7         ; get high part in d7
  227.    mulu     d7,d0      ; multiply high and low destroying low
  228.    clr.w    d0         ; clear the least significant part
  229.    swap     d0         ; put most sig. part in low half
  230.    mulu     d7,d7      ; multiply high and high destroing high
  231.    add.l    d0,d7      ; add in lower half twice
  232.    add.l    d0,d7
  233.    asl.l    d1,d7      ; get radix point back in correct place
  234.    bvs      Fbailout
  235. ;
  236.    movem.l  .saveregs,-(sp)
  237. ;
  238. #endasm
  239.    PlotIntOrbit(cura,curb);
  240. #asm
  241. ;
  242.    movem.l  (sp)+,.saveregs
  243. ;
  244.    move.l   d6,d0      ; if (cura2 + curb2 >= 4) goto bailout;
  245.    add.l    d7,d0
  246.    bvs      Fbailout
  247. ;
  248.    dbra     d2,FKLoop
  249. ;  addq     #1,d2
  250. Fbailout
  251.    move.w   maxi(a2),d0
  252.    sub.w    d2,d0
  253.    sub.w    #1,d0
  254.    ext.l    d0
  255. #endasm
  256.    ;;
  257. }
  258.  
  259. #asm
  260. .saveregs   reg     d0-d3/a2
  261. #endasm
  262.  
  263.  
  264.  
  265.