home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 2 / MECOMP-CD-II.iso / amiga / grafix / flashmandel / sources / modules / mandint.s < prev    next >
Encoding:
Text File  |  1998-04-19  |  4.3 KB  |  177 lines

  1.  
  2. ********************************************************************************
  3. **
  4. **  Original code made by Tobias Ferber and Martin Giese (Mandel-92)
  5. **
  6. **  Rewritten and speeded up by Dino Papararo            01-Mar-1997
  7. **
  8. **  FUNCTION
  9. **
  10. **    MandInt -- perform Z = Z^2 + C iteration.
  11. **
  12. **  SYNOPSIS
  13. **
  14. **    WORD MandINT (WORD Iterations,LONG Cre,LONG Cim)
  15. **
  16. **
  17. **  DESCRIPTION
  18. **
  19. **    Work with fixed-point real numbers, x between -8 and 8 (aprox.)
  20. **    being represented by x*2^(28) in a long.
  21. **
  22. **
  23. **    MandInt performs an iteration given by
  24. **
  25. **                             2    2
  26. **    x = r    y = i    x   = x  - y  + r    y   = 2 x  y + i
  27. **     0        0        j+1   j    j         j+1     j  j
  28. **
  29. **
  30. **    2 x y  is calculated via
  31. **
  32. **
  33. **                   2    2    2
  34. **    2 x y = (x + y)  - x  - y
  35. **
  36. **
  37. **    as the squaring of x+y requires only three more multiplicaitons vs.
  38. **    four for a normal multiplication of longs.
  39. **
  40. **    the iterations is performed up to n times, but may stop before that
  41. **    if x^2+y^2 exceeds 2.00
  42. **
  43. **    The value returned is the number of iterations actually done.
  44. **
  45. ********************************************************************************
  46.  
  47. ***** d0:Iterations d1:zr d2:zi d3:Quad d4:zr2 d5:zi2 d6:Const d7:Const ********
  48.  
  49. ******************************** a0:Cre a1:Cim *********************************
  50.  
  51. ********************************************************************************
  52.  
  53.  
  54.         XDEF  _MandINT
  55.  
  56. _MandINT:
  57.  
  58.         movem.l d3-d7,-(sp)     ; save regs
  59.  
  60.  
  61.         move.l  d1,a0           ; a0 = Cre
  62.         move.l  d2,a1           ; a1 = Cim
  63.         moveq.l #12,d6          ; d6 = 12
  64.         moveq.l #11,d7          ; d7 = 11
  65.  
  66.  
  67. Iter:
  68.         move.l  d1,d3           ; save zr in d3 & calculate zr^2
  69.         bpl.s   Positiv_1
  70.         neg.l   d1
  71.  
  72. Positiv_1:
  73.  
  74.         move.w  d1,d4           ; d4   = Rl
  75.         mulu.w  d4,d4           ; d4   = Rl * Rl
  76.         clr.w   d4              ; d4.w = 0
  77.         swap.w  d4              ; d4   = d4 >> 16
  78.         lsr.w   d6,d4           ; d4   = d4 >> 12
  79.  
  80.         move.w  d1,d5           ; d5   = Rl
  81.         swap.w  d1              ; d1.w = Rh
  82.         mulu.w  d1,d5           ; d5   = Rh * Rl
  83.         lsr.l   d7,d5           ; d5   = d7 >> 11
  84.  
  85.         add.l   d5,d4           ; d4   = ((Rl * Rl) >> 28) + ((2 * Rl * Rh) >> 12)
  86.  
  87.         mulu.w  d1,d1           ; d1   = Rh * Rh
  88.         asl.l   #4,d1           ; d1   = d4 << 4
  89.         bvs.s   Exit            ; Check Overflow
  90.  
  91.         add.l   d1,d4           ; d4 = d4 + ((Rh * Rh) << 4)
  92.                                 ; zr * zr
  93.  
  94.  
  95.         add.l   d2,d3           ; add zi in d3 & calculate zi^2
  96.  
  97.  
  98.  
  99.         tst.l   d2
  100.         bpl.s   Positiv_2
  101.         neg.l   d2
  102.  
  103. Positiv_2:
  104.  
  105.         move.w  d2,d5
  106.         mulu.w  d5,d5
  107.         clr.w   d5
  108.         swap.w  d5
  109.         lsr.w   d6,d5
  110.  
  111.         move.w  d2,d1
  112.         swap.w  d2
  113.         mulu.w  d2,d1
  114.         lsr.l   d7,d1
  115.  
  116.         add.l   d1,d5
  117.  
  118.         mulu.w  d2,d2
  119.         asl.l   #4,d2
  120.         bvs.s   Exit
  121.  
  122.         add.l   d2,d5           ; d5 = zi * zi
  123.  
  124.  
  125.  
  126.         move.l  d4,d1
  127.         add.l   d5,d1           ; zr2 + zi2
  128.         bvs.s   Exit            ; if overflow exit
  129.         cmpi.l  #$40000000,d1   ; compare (zr2 + zi2) with (4 * 2^28)
  130.         bgt.s   Exit            ; if greater exit
  131.  
  132.  
  133.  
  134.         tst.l   d3              ; calculate (zi + zr)^2
  135.         bpl.s   Positiv_3
  136.         neg.l   d3
  137.  
  138. Positiv_3:
  139.  
  140.         move.w  d3,d2
  141.         mulu.w  d2,d2
  142.         clr.w   d2
  143.         swap.w  d2
  144.         lsr.w   d6,d2
  145.  
  146.         move.w  d3,d1
  147.         swap.w  d3
  148.         mulu.w  d3,d1
  149.         lsr.l   d7,d1
  150.  
  151.         add.l   d1,d2
  152.  
  153.         mulu.w  d3,d3
  154.         asl.l   #4,d3
  155.         bvs.s   Exit
  156.         add.l   d3,d2           ; d5 = (zi + zr)^2
  157.  
  158.  
  159.  
  160.         move.l  a0,d1           ; d1  = Cre
  161.         move.l  a1,d3           ; d3  = Cim
  162.         sub.l   d4,d2           ; d2  = (zr + zi)^2 - zr2
  163.         sub.l   d5,d1           ; d1 -= zi2
  164.         add.l   d3,d2           ; d2 += Cim
  165.         add.l   d4,d1           ; d1 += zr2
  166.         sub.l   d5,d2           ; d2 -= zi2
  167.  
  168.         dbra.w  d0,Iter         ; if Iterations != 0) go to Iter
  169.         moveq.l #0,d0           ; else Iterations = 0
  170.  
  171. Exit:
  172.         movem.l (sp)+,d3-d7     ; restore regs
  173.  
  174.         rts                     ; return Iterations
  175.  
  176.         end                     ; end.
  177.