home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / a68kex_431.lzh / A68Kex / Lorenz.asm < prev    next >
Assembly Source File  |  1991-01-17  |  9KB  |  361 lines

  1. *******************************************
  2. * One of the simplest strange attractors  *
  3. * is the Lorenz attractor:                *
  4. * E. N. Lorenz, Deterministic Nonperiodic *
  5. * Flow, Journal of Atmospheric Science,   *
  6. * 20, 130, (1963)                         *
  7. *                                         *
  8. * The model consists of the differential  *
  9. * equations:                              *
  10. *                                         *
  11. * x' = -s*x + s*y                         *
  12. * y' = r*x - y - x*z                      *
  13. * z' = x*y - b*z                          *
  14. *                                         *
  15. * with:  s = 10  r = 28  b = 8/3          *
  16. *                                         *
  17. * This implementation was written by      *
  18. * E. Lenz                                 *
  19. * Johann-Fichte-Strasse 11                *
  20. * 8 Munich 40                             *
  21. * Germany                                 *
  22. *                                         *
  23. *******************************************
  24.  
  25. _AbsExecBase        equ 4
  26.  
  27. **** exec *****
  28.  
  29. _LVOForbid       equ -$84
  30. _LVOPermit       equ -$8a
  31. _LVOGetMsg       equ -$174
  32. _LVOReplyMsg     equ -$17a
  33. _LVOWaitPort     equ -$180
  34. _LVOCloseLibrary equ -$19e
  35. _LVOOpenLibrary  equ -$228
  36.  
  37. **** intuition ******
  38.  
  39. _LVOCloseScreen     equ -$42
  40. _LVOCloseWindow     equ -$48
  41. _LVOOpenScreen      equ -$c6
  42. _LVOOpenWindow      equ -$cc
  43. _LVOViewPortAddress equ -$12c
  44.  
  45. ***** graphics ******
  46.  
  47. _LVOLoadRGB4        equ -$c0
  48. _LVOMove            equ -$f0
  49. _LVODraw            equ -$f6
  50. _LVOSetAPen         equ -$156
  51.  
  52. ****** mathffp ******
  53.  
  54. _LVOSPFix           equ -$1e
  55. _LVOSPAdd           equ -$42
  56. _LVOSPSub           equ -$48
  57. _LVOSPMul           equ -$4e
  58. _LVOSPDiv           equ -$54
  59.  
  60. wd_RPort         equ $32
  61. wd_UserPort      equ $56
  62. pr_MsgPort       equ $5c
  63. pr_CLI           equ $ac
  64. ThisTask         equ $114
  65. VBlankFrequency  equ $212
  66.  
  67. dt       equ $83126f37    ;0.001
  68. one      equ $80000041    ;1
  69. three    equ $c0000042    ;3
  70. fif      equ $f0000044    ;15
  71.  
  72.        movea.l _AbsExecBase,a6   test if WB or CLI
  73.        movea.l ThisTask(a6),a0
  74.        moveq   #0,d0
  75.        tst.l   pr_CLI(a0)
  76.        bne.s   isCLI
  77.  
  78.        lea     pr_MsgPort(a0),a0     for WB get WB Message
  79.        jsr     _LVOWaitPort(a6)
  80.        jsr     _LVOGetMsg(a6)
  81.  
  82. isCLI  move.l  d0,-(a7)
  83.  
  84.        cmpi.b  #60,VBlankFrequency(a6) test if PAL or NTSC
  85.        beq.s   isNTSC
  86.        move.w  #256,ns+6        Patch the programme
  87.        move.w  #256,nw+6        for PAL at run time
  88.        move.w  #$7810,NTSC1
  89.        move.w  #120,NTSC2+2
  90.  
  91. isNTSC lea     GfxName(pc),a1   Open graphics.library
  92.        moveq   #0,d0
  93.        jsr     _LVOOpenLibrary(a6)
  94.        movea.l d0,a4
  95.        tst.l   d0
  96.        beq.s   Gexit
  97.  
  98.        lea     IntName(pc),a1         open intuition library
  99.        moveq   #0,d0
  100.        jsr     _LVOOpenLibrary(a6)
  101.        movea.l d0,a2
  102.        tst.l   d0
  103.        beq.s   Gexit
  104.  
  105.        lea     FfpName(pc),a1         open mathffp library
  106.        moveq   #0,d0
  107.        jsr     _LVOOpenLibrary(a6)
  108.        movea.l d0,a3
  109.        tst.l   d0
  110.        beq.s   Gexit
  111.  
  112.        lea     ns(pc),a0              open screen
  113.        movea.l a2,a6
  114.        jsr     _LVOOpenScreen(a6)
  115.        move.l  d0,nws
  116.        beq.s   Gexit
  117.  
  118.        lea     nw(pc),a0              open window
  119.        jsr     _LVOOpenWindow(a6)
  120.        move.l  d0,window
  121. Gexit  beq     exit
  122.  
  123.        movea.l d0,a0
  124.        movea.l wd_RPort(a0),a5
  125.        jsr     _LVOViewPortAddress(a6)
  126.  
  127.        movea.l d0,a0
  128.        lea     ColourTable(pc),a1
  129.        moveq   #16,d0
  130.        movea.l a4,a6
  131.        jsr     _LVOLoadRGB4(a6)
  132.  
  133.        move.l  #300,d0         draw axis
  134.        moveq   #0,d1
  135.        movea.l a5,a1
  136.        jsr     _LVOMove(a6)
  137.  
  138.        moveq   #15,d6
  139. NTSC1  moveq   #12,d4
  140.        move.l  d4,d5
  141. colour move.l  d6,d0
  142.        movea.l a5,a1
  143.        jsr     _LVOSetAPen(a6)
  144.        move.l  #300,d0
  145.        move.l  d5,d1
  146.        movea.l a5,a1
  147.        jsr     _LVODraw(a6)
  148.        add.l   d4,d5
  149.        dbra    d6,colour
  150.  
  151.        moveq   #20,d3
  152.  
  153. loop   movea.l _AbsExecBase,a6
  154.  
  155.        movea.l window(pc),a0
  156.        movea.l wd_UserPort(a0),a0
  157.        jsr     _LVOGetMsg(a6)
  158.        tst.l   d0
  159.        beq.s   Main           ;No message
  160.  
  161.        movea.l d0,a1
  162.        move.l  $14(a1),d7       Message in a7
  163.        jsr     _LVOReplyMsg(a6) Always reply
  164.        movea.l a2,a6
  165.  
  166.        cmpi.l  #$200,d7     Close window
  167.        beq     exit
  168.  
  169.  
  170. Main   movea.l a3,a6       Calculate next point
  171.  
  172.        move.l  y(pc),d0
  173.        move.l  x(pc),d1
  174.        jsr     _LVOSPSub(a6)
  175.        move.l  #dt,d1
  176.        jsr     _LVOSPMul(a6)
  177.        move.l  s(pc),d1
  178.        jsr     _LVOSPMul(a6)
  179.        move.l  x(pc),d1
  180.        jsr     _LVOSPAdd(a6)
  181.        move.l  d0,x1           ;x1 = x + s*dt*(y-x)
  182.  
  183.        move.l  #one,d0
  184.        move.l  #dt,d1
  185.        jsr     _LVOSPSub(a6)
  186.        move.l  y(pc),d1
  187.        jsr     _LVOSPMul(a6)
  188.        move.l  d0,d7
  189.        move.l  r(pc),d0
  190.        move.l  z(pc),d1
  191.        jsr     _LVOSPSub(a6)
  192.        move.l  x(pc),d1
  193.        jsr     _LVOSPMul(a6)
  194.        move.l  #dt,d1
  195.        jsr     _LVOSPMul(a6)
  196.        move.l  d7,d1
  197.        jsr     _LVOSPAdd(a6)
  198.        move.l  d0,y1          ;y1 = (1 - dt)*y + dt*x*(r - z)
  199.  
  200.        move.l  b(pc),d0
  201.        move.l  #dt,d1
  202.        jsr     _LVOSPMul(a6)
  203.        move.l  d0,d1
  204.        move.l  #one,d0
  205.        jsr     _LVOSPSub(a6)
  206.        move.l  z(pc),d1
  207.        jsr     _LVOSPMul(a6)
  208.        move.l  d0,d7
  209.        move.l  #dt,d0
  210.        move.l  x(pc),d1
  211.        jsr     _LVOSPMul(a6)
  212.        move.l  y(pc),d1
  213.        jsr     _LVOSPMul(a6)
  214.        move.l  d7,d1
  215.        jsr     _LVOSPAdd(a6)  ;z1 = (1 - b*dt)*z + dt*x*y
  216.  
  217.        move.l  d0,z           ;z = z1
  218.        jsr     _LVOSPFix(a6)
  219.        move.l  d0,zi
  220.        lsr     #1,d0
  221.        move.l  d0,d4
  222.        and.l   #$f,d4
  223.        cmp.l   #1,d4
  224.        bgt.s   cont
  225.        add.l   #14,d4
  226.  
  227. cont   move.l  y1(pc),d0
  228.        move.l  d0,y            ;y = y1
  229.        move.l  #three,d1
  230.        jsr     _LVOSPMul(a6)
  231.        jsr     _LVOSPFix(a6)
  232. NTSC2  add.w   #100,d0
  233.        move.l  d0,yi
  234.  
  235.        move.l  x1(pc),d0
  236.        move.l  d0,x            ;x = x1
  237.        move.l  #fif,d1
  238.        jsr     _LVOSPMul(a6)
  239.        jsr     _LVOSPFix(a6)
  240.        add.w   #300,d0
  241.        move.l  d0,xi
  242.  
  243.        movea.l a4,a6
  244.        movea.l a5,a1
  245.        move.l  d4,d0
  246.        jsr     _LVOSetAPen(a6)
  247.  
  248.        move.l  xi(pc),d0
  249.        move.l  yi(pc),d1
  250.        movea.l a5,a1
  251.        jsr     _LVOMove(a6)
  252.  
  253.        move.l  xi(pc),d0
  254.        move.l  yi(pc),d1
  255.        movea.l a5,a1
  256.        jsr     _LVODraw(a6)
  257.  
  258.        bra     loop
  259.  
  260. exit   movea.l a2,a6           close window
  261.        move.l  window(pc),d0
  262.        beq.s   noWin
  263.        movea.l d0,a0
  264.        jsr     _LVOCloseWindow(a6)
  265.  
  266. noWin  move.l  nws(pc),d0         close screen
  267.        beq.s   noScr
  268.        movea.l d0,a0
  269.        jsr     _LVOCloseScreen(a6)
  270.  
  271. noScr  movea.l _AbsExecBase,a6
  272.        move.l  (a7)+,d0
  273.        beq.s   NoBenh
  274.        jsr     _LVOForbid(a6)       reply to WB
  275.        movea.l d0,a1
  276.        jsr     _LVOReplyMsg(a6)
  277.        jsr     _LVOPermit(a6)
  278.  
  279. NoBenh move.l  a3,d1           close mathffp library
  280.        beq.s   noFfp
  281.        movea.l d1,a1
  282.        jsr     _LVOCloseLibrary(a6)
  283.  
  284. noFfp  move.l  a2,d1           close intuition library
  285.        beq.s   noInt
  286.        movea.l d1,a1
  287.        jsr     _LVOCloseLibrary(a6)
  288.  
  289. noInt  move.l  a4,d1               close graphics library
  290.        beq.s   noGfx
  291.        movea.l d1,a1
  292.        jsr     _LVOCloseLibrary(a6)
  293.  
  294. noGfx  moveq   #0,d0                no error
  295.        rts
  296.  
  297. ;                white  blue
  298. ColourTable dc.w $0000,$000f,$002d,$004b
  299.             dc.w $0069,$0087,$00a5,$00c3
  300. ;                 green
  301.             dc.w $00f0,$02d0,$04b0,$0690
  302.             dc.w $0870,$0a50,$0c30,$0f00
  303. ;                                   red
  304.  
  305. x           dc.l $80000044    ;10
  306. y           dc.l $c0000043    ;28
  307. z           dc.l $d0000045    ;8/3
  308. s           dc.l $a0000044    ;8
  309. r           dc.l $e0000045    ;6
  310. b           dc.l $aaaaab42    ;26
  311.  
  312. x1          dc.l 0
  313. y1          dc.l 0
  314. xi          dc.l 0
  315. yi          dc.l 0
  316. zi          dc.l 0
  317.  
  318. FfpName     dc.b 'mathffp.library',0
  319. GfxName     dc.b 'graphics.library',0
  320. IntName     dc.b 'intuition.library',0
  321.             even
  322.  
  323. window      dc.l 0
  324.  
  325. title1      dc.b 'Screen',0
  326.             cnop 0,2
  327.  
  328. **** screen definition ****
  329.  
  330. ns          dc.w  0,0
  331.             dc.w  640,199,4
  332.             dc.b  0,1
  333.             dc.w  $8000
  334.             dc.w  $f
  335.             dc.l  0
  336.             dc.l  title1
  337.             dc.l  0
  338.             dc.l  0
  339.  
  340. title2      dc.b  'The Lorenz attractor',0,0
  341.  
  342. ***** Window definition *****
  343.  
  344. nw          dc.w 0,0           ;Position left,top
  345.             dc.w 640,199       ;Size width,height
  346.             dc.b 0,1           ;Colors detail-,block pen
  347.             dc.l $344          ;IDCMP-Flags
  348.             dc.l $144f         ;Window flags
  349.             dc.l 0             ;^Gadget
  350.             dc.l 0             ;^Menu check
  351.             dc.l title2        ;^Window name
  352. nws         dc.l 0             ;^Screen structure,
  353.             dc.l 0             ;^BitMap
  354.             dc.w 10            ;MinWidth
  355.             dc.w 10            ;MinHeight
  356.             dc.w -1            ;MaxWidth
  357.             dc.w -1,$f         ;MaxHeight,Screen type
  358.  
  359.             end
  360.  
  361.