home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 466.lha / A68kExamples / Lissajous.asm < prev    next >
Assembly Source File  |  1991-02-03  |  13KB  |  485 lines

  1. ************************************************************************
  2. *                                                                      *
  3. * These are simply Lissajous figures which you can create using an     *
  4. * oscilloscope and two frequency generators.                           *
  5. * The definition is:                                                   *
  6. *                     x(t)=sin(u*t)                                    *
  7. *                     y(t)=sin(v*t+p)                                  *
  8. *                                                                      *
  9. * u is the angular frequency in the x direction                        *
  10. * v is the angular frequency in the y direction                        *
  11. * p is the phase difference between x and y                            *
  12. *                                                                      *
  13. * This implementation was written by:                                  *
  14. * E. Lenz                                                              *
  15. * Johann-Fichte-Strasse 11                                             *
  16. * 8 Munich 40                                                          *
  17. * Germany                                                              *
  18. *                                                                      *
  19. ************************************************************************
  20.  
  21.       XREF GetReal,RealOut,request
  22.  
  23. _AbsExecBase        equ 4
  24.  
  25. **** exec *****
  26.  
  27. _LVOForbid       equ -$84
  28. _LVOPermit       equ -$8a
  29. _LVOGetMsg       equ -$174
  30. _LVOReplyMsg     equ -$17a
  31. _LVOWaitPort     equ -$180
  32. _LVOCloseLibrary equ -$19e
  33. _LVOOpenLibrary  equ -$228
  34.  
  35. **** intuition ******
  36.  
  37. _LVOCloseWindow    equ -$48
  38. _LVOOpenWindow     equ -$cc
  39. _LVOSetMenuStrip   equ -$108
  40.  
  41. ***** graphics ******
  42.  
  43. _LVOMove            equ -$f0
  44. _LVODraw            equ -$f6
  45. _LVORectFill        equ -$132
  46. _LVOSetAPen         equ -$156
  47.  
  48. *** mathffp ***
  49.  
  50. _LVOSPFix  equ -$1e
  51. _LVOSPAdd  equ -$42
  52. _LVOSPMul  equ -$4e
  53.  
  54. *** mathtrans ***
  55.  
  56. _LVOSPSin equ -$24
  57.  
  58. wd_RPort         equ $32
  59. wd_UserPort      equ $56
  60. pr_MsgPort       equ $5c
  61. pr_CLI           equ $ac
  62. ThisTask         equ $114
  63. VBlankFrequency  equ $212
  64.  
  65. hund3  equ $96000049  300
  66. hund   equ $b4000047  90
  67. hund1  equ $f0000047  120
  68. dt     equ $a3d70b3a  0.01
  69.  
  70.        movea.l _AbsExecBase,a6   test if WB or CLI
  71.        movea.l ThisTask(a6),a0
  72.        tst.l   pr_CLI(a0)
  73.        bne.s   isCLI
  74.  
  75.        lea     pr_MsgPort(a0),a0 for WB get WB Message
  76.        jsr     _LVOWaitPort(a6)
  77.        jsr     _LVOGetMsg(a6)
  78.        move.l  d0,WBenchMsg
  79.  
  80. isCLI  cmpi.b  #60,VBlankFrequency(a6) test if PAL or NTSC
  81.        beq.s   isNTSC
  82.        move.w  #256,nw+6
  83.        move.l  #hund1,NTSC+2
  84.  
  85. isNTSC lea     GfxName(pc),a1        open graphics library
  86.        moveq   #0,d0
  87.        jsr     _LVOOpenLibrary(a6)
  88.        move.l  d0,GfxBase
  89.        beq.s   Gexit
  90.  
  91.        lea     IntName(pc),a1        open intuition library
  92.        moveq   #0,d0
  93.        jsr     _LVOOpenLibrary(a6)
  94.        move.l  d0,IntBase
  95.        beq.s   Gexit
  96.  
  97.        lea     MathName(pc),a1       open mathffp library
  98.        moveq   #0,d0
  99.        jsr     _LVOOpenLibrary(a6)
  100.        move.l  d0,MathBase
  101.        beq.s   Gexit
  102.  
  103.        lea     MtransName(pc),a1     open mathtrans library
  104.        moveq   #0,d0
  105.        jsr     _LVOOpenLibrary(a6)
  106.        move.l  d0,MtransBase
  107.        bne.s   Trok
  108.        lea     MtransName(pc),a0   first line
  109.        movem.l a4-a5,-(a7)
  110.        lea     notfnd(pc),a1     second line
  111.        suba.l  a2,a2             no third line
  112.        lea     hdtxt(pc),a3      header
  113.        lea     OkTxt(pc),a4      gadget text
  114.        suba.l  a5,a5             no 2nd gadget
  115.        moveq   #0,d0
  116.        moveq   #1,d1
  117.        jsr     request
  118.        movem.l (a7)+,a4-a5
  119. Gexit  bra     exit
  120.  
  121. Trok   lea     nw(pc),a0             open window
  122.        movea.l IntBase(pc),a6
  123.        jsr     _LVOOpenWindow(a6)
  124.        move.l  d0,window
  125.        beq.s   Gexit
  126.  
  127.  
  128. ; Set menu
  129.  
  130.        movea.l d0,a0           which window
  131.        lea     Menu1(pc),a1    which menu
  132.        jsr     _LVOSetMenuStrip(a6)
  133.  
  134.        movea.l window(pc),a0
  135.        movea.l wd_RPort(a0),a5
  136.  
  137. redraw movea.l GfxBase(pc),a6  clear screen
  138.        moveq   #0,d0
  139.        movea.l a5,a1
  140.        jsr     _LVOSetAPen(a6)
  141.  
  142.        movea.l a5,a1
  143.        moveq   #0,d0
  144.        moveq   #0,d1
  145.        move.l  #640,d2
  146.        move.l  #250,d3
  147.        jsr     _LVORectFill(a6)
  148.  
  149.        movea.l a5,a1
  150.        moveq   #3,d0
  151.        jsr     _LVOSetAPen(a6)
  152.  
  153.        clr.l   t
  154.  
  155. draw   bsr     print
  156.  
  157. wait   bsr     trycls
  158.        beq.s   draw
  159.        cmpi.l  #$200,d7
  160.        beq.s   exit
  161.  
  162.        cmpi.l  #$100,d7
  163.        bne.s   wait
  164.  
  165. ; Choice from menu
  166.  
  167.        movea.l window(pc),a0
  168.        movea.l $5e(a0),a0   Load Window.MessageKey
  169.        move.w  $18(a0),d0   Load message code
  170.        move.w  d0,d1
  171.        andi.w  #$f,d1
  172.        bne.s   draw
  173.  
  174.        andi.w  #$f0,d0      Menu 1
  175.        bne.s   menu12       Submenu 1
  176.        bsr     xfreq
  177. sedraw bra.s   redraw
  178.  
  179. menu12 cmpi.w  #$20,d0      Submenu 2
  180.        bne.s   menu13
  181.        bsr     yfreq
  182.        bra.s   redraw
  183.  
  184. menu13 cmpi.w  #$40,d0      Submenu 3
  185.        bne.s   draw
  186.        bsr     phase
  187.        bra.s   sedraw
  188.  
  189. exit   movea.l IntBase(pc),a6
  190.        move.l  window(pc),d0
  191.        beq.s   noWin
  192.        movea.l d0,a0
  193.        jsr     _LVOCloseWindow(a6)    close window
  194.  
  195. noWin  movea.l _AbsExecBase,a6
  196.        tst.l   WBenchMsg
  197.        beq.s   NoBenh
  198.        jsr     _LVOForbid(a6)       reply to WB
  199.        movea.l WBenchMsg(pc),a1
  200.        jsr     _LVOReplyMsg(a6)
  201.        jsr     _LVOPermit(a6)
  202.  
  203. NoBenh move.l  MtransBase(pc),d1     close mathtrans library
  204.        beq.s   noMtr
  205.        movea.l d1,a1
  206.        jsr     _LVOCloseLibrary(a6)
  207.  
  208. noMtr  move.l  MathBase(pc),d1      close mathffp library
  209.        beq.s   noMath
  210.        movea.l d1,a1
  211.        jsr     _LVOCloseLibrary(a6)
  212.  
  213. noMath move.l  IntBase(pc),d1       close intuition library
  214.        beq.s   noInt
  215.        movea.l d1,a1
  216.        jsr     _LVOCloseLibrary(a6)
  217.  
  218. noInt  move.l  GfxBase(pc),d1       close graphics library
  219.        beq.s   noGfx
  220.        movea.l d1,a1
  221.        jsr     _LVOCloseLibrary(a6)
  222.  
  223. noGfx  moveq   #0,d0                no error
  224.        rts
  225.  
  226. trycls movem.l d0-d6/a0-a6,-(a7)
  227.        movea.l _AbsExecBase,a6
  228.        moveq   #0,d7
  229.        movea.l window(pc),a0
  230.        movea.l wd_UserPort(a0),a0  load Window.UserPort
  231.        jsr     _LVOGetMsg(a6)
  232.        tst.l   d0
  233.        beq.s   noMsg1         No message
  234.  
  235.        movea.l d0,a1
  236.        move.l  $14(a1),d7       Message in d7
  237.  
  238. noMsg1 movem.l (a7)+,d0-d6/a0-a6
  239. noMsg  tst.l   d7
  240.        rts
  241.  
  242. print  movea.l MathBase(pc),a6
  243.        movea.l MtransBase(pc),a4
  244.        move.l  t(pc),d0
  245.        move.l  #dt,d1
  246.        jsr     _LVOSPAdd(a6)
  247.        move.l  d0,t
  248.  
  249.        move.l  d0,d1
  250.        move.l  u(pc),d0
  251.        jsr     _LVOSPMul(a6)
  252.  
  253.        exg     a4,a6
  254.        jsr     _LVOSPSin(a6)
  255.  
  256.        exg     a4,a6
  257.        move.l  #hund3,d1
  258.        jsr     _LVOSPMul(a6)
  259.        move.l  #hund3,d1
  260.        jsr     _LVOSPAdd(a6)
  261.        jsr     _LVOSPFix(a6)
  262.        move.l  d0,d7
  263.  
  264.        move.l  v(pc),d0
  265.        move.l  t(pc),d1
  266.        jsr     _LVOSPMul(a6)
  267.        move.l  p(pc),d1
  268.        jsr     _LVOSPAdd(a6)
  269.  
  270.        exg     a4,a6
  271.        jsr     _LVOSPSin(a6)
  272.  
  273.        exg     a4,a6
  274. NTSC   move.l  #hund,d5
  275.        move.l  d5,d1
  276.        jsr     _LVOSPMul(a6)
  277.        move.l  d5,d1
  278.        jsr     _LVOSPAdd(a6)
  279.        jsr     _LVOSPFix(a6)
  280.        move.l  d0,d6
  281.  
  282.        move.l  d0,d1
  283.        move.l  d7,d0
  284.        movea.l GfxBase(pc),a6
  285.        movea.l a5,a1
  286.        jsr     _LVOMove(a6)
  287.  
  288.        move.l  d6,d1
  289.        move.l  d7,d0
  290.        movea.l a5,a1
  291.        jsr     _LVODraw(a6)
  292.        rts
  293.  
  294.  
  295. xfreq  bsr.s   uout
  296.        lea     item11txt(pc),a0
  297.        lea     tu(pc),a1
  298.        lea     uval(pc),a2
  299.        jsr     GetReal
  300.        tst.l   d1
  301.        bne.s   nogo
  302.        move.l  d0,u
  303.        rts
  304.  
  305. yfreq  bsr.s   vout
  306.        lea     item12txt(pc),a0
  307.        lea     tv(pc),a1
  308.        lea     vval(pc),a2
  309.        jsr     GetReal
  310.        tst.l   d1
  311.        bne.s   nogo
  312.        move.l  d0,v
  313. nogo   rts
  314.  
  315. phase  bsr.s   pout
  316.        lea     item13txt(pc),a0
  317.        lea     tp(pc),a1
  318.        lea     pval(pc),a2
  319.        jsr     GetReal
  320.        tst.l   d1
  321.        bne.s   nogo
  322.        move.l  d0,p
  323.        rts
  324.  
  325. uout   lea     uval(pc),a0
  326.        move.l  u(pc),d0
  327.        bra.s   outout
  328.  
  329. vout   lea     vval(pc),a0
  330.        move.l  v(pc),d0
  331.        bra.s   outout
  332.  
  333. pout   lea     pval(pc),a0
  334.        move.l  p(pc),d0
  335. outout moveq   #2,d1
  336.        moveq   #9,d2
  337.        movea.l a0,a1
  338. remove move.b  #' ',(a1)+
  339.        dbra    d2,remove
  340.        jsr     RealOut
  341.        moveq   #0,d0
  342.        moveq   #1,d1
  343.        rts
  344.  
  345. tu     dc.b  'X freq ='
  346. uval   dc.b  '           ',$a
  347. tv     dc.b  'Y freq ='
  348. vval   dc.b  '           ',$a
  349. tp     dc.b  'P phase='
  350. pval   dc.b  '           ',$a
  351.  
  352. u      dc.l $80000041     1
  353. v      dc.l $86666642     2.1
  354. t      dc.l 0
  355. p      dc.l 0
  356.  
  357. WBenchMsg   dc.l 0
  358. MtransBase  dc.l 0
  359. MathBase    dc.l 0
  360. GfxBase     dc.l 0
  361. IntBase     dc.l 0
  362.  
  363. window      dc.l 0
  364.  
  365. ; requester texts
  366.  
  367. notfnd      dc.b ' not found',0
  368. hdtxt       dc.b ' Lissajous Request',0
  369. OkTxt       dc.b ' OK',0
  370.             even
  371.  
  372. MtransName  dc.b 'mathtrans.library',0
  373. MathName    dc.b 'mathffp.library',0
  374. GfxName     dc.b 'graphics.library',0
  375. IntName     dc.b 'intuition.library',0
  376.             even
  377.  
  378. title       dc.b  'Lissajous figures',0
  379.             even
  380.  
  381. ***** Window definition *****
  382.  
  383. nw          dc.w 0,0         Position left,top
  384.             dc.w 640,199     Size width,height
  385.             dc.b 0,1         Colors detail-,block pen
  386.             dc.l $340        IDCMP-Flags
  387.             dc.l $140f       Window flags
  388.             dc.l 0           ^Gadget
  389.             dc.l 0           ^Menu check
  390.             dc.l title       ^Window name
  391. nws         dc.l 0           ^Screen structure,
  392.             dc.l 0           ^BitMap
  393.             dc.w 100         MinWidth
  394.             dc.w 40          MinHeight
  395.             dc.w -1          MaxWidth
  396.             dc.w -1,1        MaxHeight,Screen type
  397.  
  398. **** menu definition ****
  399.  
  400. Menu1       dc.l 0           Next menu
  401.             dc.w 50,0        Position left edge,top edge
  402.             dc.w 100,20      Dimensions width,height
  403.             dc.w 1           Menu enabled
  404.             dc.l mtext1      Text for menu header
  405.             dc.l item11      ^First in chain
  406.             dc.l 0,0         Internal
  407.  
  408. mtext1      dc.b 'parameters',0
  409.             even
  410.  
  411. item11      dc.l item12      next in chained list
  412.             dc.w 0,0         Position left edge,top edge
  413.             dc.w 170,10      Dimensions width,height
  414.             dc.w $52         itemtext+highcomp+itemenabled
  415.             dc.l 0           Mutual exclude
  416.             dc.l I11txt      Pointer to intuition text
  417.             dc.l 0
  418.             dc.b 0,0
  419.             dc.l 0
  420.             dc.w 0
  421.  
  422.  
  423. I11txt      dc.b 0           Front pen  (blue)
  424.             dc.b 1           Back pen   (white)
  425.             dc.b 0,0         Draw mode
  426.             dc.w 0           Left edge
  427.             dc.w 0           Top edge
  428.             dc.l 0           Text font
  429.             dc.l item11txt   Pointer to text
  430.             dc.l 0           Next text
  431.  
  432. item11txt   dc.b 'u angular frequency x',0
  433.             even
  434.  
  435. item12      dc.l item13      next in chained list
  436.             dc.w 0,10        Position left edge,top edge
  437.             dc.w 170,10      Dimensions width,height
  438.             dc.w $52         itemtext+highcomp+itemenabled
  439.             dc.l 0           Mutual exclude
  440.             dc.l I12txt      Pointer to intuition text
  441.             dc.l 0
  442.             dc.b 0,0
  443.             dc.l 0
  444.             dc.w 0
  445.  
  446.  
  447. I12txt      dc.b 0           Front pen  (blue)
  448.             dc.b 1           Back pen   (white)
  449.             dc.b 0,0         Draw mode
  450.             dc.w 0           Left edge
  451.             dc.w 0           Top edge
  452.             dc.l 0           Text font
  453.             dc.l item12txt   Pointer to text
  454.             dc.l 0           Next text
  455.  
  456. item12txt   dc.b 'v angular frequency y',0
  457.             even
  458.  
  459. item13      dc.l 0           next in chained list
  460.             dc.w 0,20        Position left edge,top edge
  461.             dc.w 170,10      Dimensions width,height
  462.             dc.w $52         itemtext+highcomp+itemenabled
  463.             dc.l 0           Mutual exclude
  464.             dc.l I13txt      Pointer to intuition text
  465.             dc.l 0
  466.             dc.b 0,0
  467.             dc.l 0
  468.             dc.w 0
  469.  
  470.  
  471. I13txt      dc.b 0           Front pen  (blue)
  472.             dc.b 1           Back pen   (white)
  473.             dc.b 0,0         Draw mode
  474.             dc.w 0           Left edge
  475.             dc.w 0           Top edge
  476.             dc.l 0           Text font
  477.             dc.l item13txt   Pointer to text
  478.             dc.l 0           Next text
  479.  
  480. item13txt   dc.b 'p phase difference',0
  481.             even
  482.  
  483.             end
  484.  
  485.