home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 260.lha / Bezier / bezier.asm < prev    next >
Encoding:
Assembly Source File  |  1989-07-07  |  3.8 KB  |  284 lines

  1.     addsym
  2.     exeobj
  3.     caseoff
  4.     include    "lvo.asm"
  5.     include    "strucdef.asm"
  6.     code
  7.  
  8. start:    lea    ytab,a0
  9.     clr    d0
  10.     move    #199,d1
  11. 1$:    move    d0,(a0)+
  12.     add    #40,d0
  13.     dbra    d1,1$
  14.     lea    bytenum,a0
  15.     lea    bitnum,a1
  16.     clr    d0
  17.     move    #319,d1
  18. 2$:    move    d0,d2
  19.     and    #7,d2
  20.     neg    d2
  21.     add    #7,d2
  22.     move.b    d2,(a1)+
  23.     move    d0,d2
  24.     lsr    #3,d2
  25.     move    d2,(a0)+
  26.     addq    #1,d0
  27.     dbra    d1,2$
  28.     move.l    4,a6
  29.     lea    varbase,a5
  30.     lea    gfxname(a5),a1
  31.     moveq    #0,d0
  32.     jsr    _LVOOpenLibrary(a6)
  33.     move.l    d0,gfxbase(a5)
  34.     lea    intuiname(a5),a1
  35.     moveq    #0,d0
  36.     jsr    _LVOOpenLibrary(a6)
  37.     move.l    d0,intuibase(a5)
  38.     move.l    a5,a6
  39.     bsr    setmode
  40.     bsr    get_pnts
  41.     bsr    get_deltas
  42. outer
  43.     bsr    get_deltas
  44.     bsr    random
  45.     mulu    #20,d0
  46.     swap    d0
  47.     add    #50,d0
  48.     move    d0,ctdn(a6)
  49.     addq    #1,color(a6)
  50. b_loop:    movem.l    v0(a6),d0-d3
  51.     bsr    draw_bezier
  52.     bsr    update_coords
  53.     btst    #6,$bfe001
  54.     beq.s    cleanup
  55.     subq    #1,ctdn(a6)
  56.     bne.s    b_loop
  57.     bra    outer
  58. cleanup:    move.l    myscreen(a6),a0
  59.     move.l    intuibase(a6),a6
  60.     jsr    _LVOCloseScreen(a6)
  61.     move.l    4,a6
  62.     rts
  63.  
  64. setmode:    lea    mns(a6),a0
  65.     move.l    intuibase(a6),a6
  66.     jsr    _LVOOpenScreen(a6)
  67.     move.l    d0,myscreen
  68.     move.l    d0,a0
  69.     lea    sc_RastPort(a0),a2
  70.     lea    varbase,a6
  71.     move.l    a2,the_rp(a6)
  72.     rts
  73.     
  74. ; return random word in d0
  75. random:    move.w    seed(a6),d0
  76.     mulu    #$1efd,d0
  77.     add.w    #$dff,d0
  78.     move.w    d0,seed(a6)
  79.     rts
  80.  
  81. rand_xy:
  82. ; ret rnd x/y in d1/d2
  83.     bsr    random
  84.     move    #300*32,d1
  85.     mulu    d0,d1
  86.     clr    d1
  87.     swap    d1
  88.     add    #10,d1
  89.     bsr    random
  90.     move    #179*32,d2
  91.     mulu    d0,d2
  92.     clr    d2
  93.     swap    d2
  94.     add    #10,d2
  95.     rts
  96.  
  97. get_pnts:    lea    v0(a6),a0
  98.     moveq    #3,d3
  99. 1$:    bsr    rand_xy
  100.     movem    d1/d2,(a0)
  101.     lea    4(a0),a0
  102.     dbra    d3,1$
  103.     rts
  104.  
  105.  
  106. get_deltas:    lea    dx0(a6),a0
  107.     moveq    #7,d1
  108. 1$:    bsr    random
  109.     mulu    #512,d0
  110.     swap    d0
  111.     sub    #256,d0
  112.     move    d0,(a0)+
  113.     dbra    d1,1$
  114.     bsr    random
  115.     rts
  116.  
  117. update_coords:
  118.     lea    v0(a6),a0
  119.     lea    dx0(a6),a1
  120.     moveq    #3,d0
  121. pt_loop:
  122.     clr    d3
  123. 1$:    move    (a0),d1        ; x
  124.     move    (a1)+,d2        ; dx
  125.     add.w    d2,d1
  126.     bmi.s    2$
  127.     cmp    #319*32,d1
  128.     blt.s    3$
  129. 2$:    neg    -2(a1)
  130.     moveq    #1,d3
  131. 3$:    move    d1,d4
  132. do_y:
  133. 1$:    move    2(a0),d1        ; x
  134.     move    (a1)+,d2        ; dx
  135.     add.w    d2,d1
  136.     bmi.s    2$
  137.     cmp    #199*32,d1
  138.     blt.s    3$
  139. 2$:    moveq    #1,d3
  140.     neg    -2(a1)
  141. 3$:    tst    d3
  142.     bne.s    4$
  143.     move    d4,(a0)
  144.     move    d1,2(a0)
  145. 4$:    lea    4(a0),a0
  146.     dbra    d0,pt_loop
  147.     rts
  148.  
  149.  
  150. draw_bezier    move.l    myscreen(a6),a0
  151.     lea    sc_BitMap+bm_Planes(a0),a0
  152.     lea    ytab(a6),a2
  153.     move    color(a6),a3
  154.     lea    bitnum(a6),a1
  155.     lea    bytenum(a6),a6
  156.     bsr    bez_draw
  157.     lea    varbase,a6
  158.     rts
  159.  
  160.  
  161. pstep    macro
  162.     move.l    (a4)+,a5
  163.     add    d1,a5
  164.     bclr    d2,(a5)
  165.     lsr    #1,d3
  166.     bcc.s    no_or\@
  167.     bset    d2,(a5)
  168. no_or\@:
  169.     endm
  170.  
  171. set_it:    move.l    d0,d1
  172.     swap    d0
  173.     lsr    #5,d0
  174.     lsr    #5,d1
  175. set_pixel:
  176. ; d0,d1=x,y
  177. ; a0=bm array
  178. ; a1=bit #'s
  179. ; a2=ytab
  180. ; a3=color
  181. ; a6=bytenum
  182.     add    d1,d1
  183.     move    0(a2,d1),d1
  184.     move.b    0(a1,d0),d2
  185.     add    d0,d0
  186.     add    0(a6,d0),d1
  187.     move.l    a0,a4
  188.     move    a3,d3
  189.     pstep
  190.     pstep
  191.     pstep
  192.     pstep
  193.     move.l    (a4),a5
  194.     add    d1,a5
  195.     bclr    d2,(a5)
  196.     tst    d3
  197.     beq.s    no_or
  198.     bset    d2,(a5)
  199. no_or:    rts
  200.  
  201.  
  202. bez_draw:    move    d0,d4
  203.     sub.w    d3,d4
  204.     bpl.s    1$
  205.     neg    d4
  206. 1$:    move.l    d0,d5
  207.     swap    d5
  208.     swap    d3
  209.     sub    d3,d5
  210.     bpl.s    2$
  211.     neg    d5
  212. 2$:    swap    d3
  213.     add    d4,d5
  214.     cmp    #64,d5
  215.     blt.s    set_it
  216. subdivide:    move    #$7fff,d7
  217.     move.l    d0,d4
  218.     add.l    d1,d4
  219.     lsr.l    #1,d4
  220.     and    d7,d4        ; d4=s1
  221.     move.l    d1,d5
  222.     add.l    d2,d5
  223.     lsr.l    #1,d5
  224.     and    d7,d5        ; d5=t
  225.     move.l    d4,d6
  226.     add.l    d5,d6
  227.     lsr.l    #1,d6
  228.     and    d7,d6        ; d6=s2
  229.     add.l    d3,d2
  230.     lsr.l    #1,d2
  231.     and    d7,d2        ; d2=t2
  232.     add.l    d2,d5
  233.     lsr.l    #1,d5
  234.     and    d7,d5        ; d5=t1
  235.     move.l    d6,d7
  236.     add.l    d5,d7
  237.     lsr.l    #1,d7
  238.     bclr    #15,d7        ; d7=s3,t0
  239.     movem.l    d7/d5/d2/d3,-(a7)
  240.     move.l    d4,d1
  241.     move.l    d6,d2
  242.     move.l    d7,d3
  243.     bsr    bez_draw
  244.     movem.l    (a7)+,d7/d5/d2/d3
  245.     move.l    d7,d0
  246.     move.l    d5,d1
  247.     bra    bez_draw
  248.  
  249.  
  250. pt    macro
  251.     dc.l    65536*32*\1+32*\2
  252.     endm
  253.  
  254.     section    vars,DATA
  255. varbase
  256. v0    pt    0,100
  257. v1    pt    100,50
  258. v2    pt    200,150
  259. v3    pt    300,125
  260.  
  261. dx0    dc.l    0
  262. dx1    dc.l    0
  263. dx2    dc.l    0
  264. dx3    dc.l    0
  265.  
  266. ctdn    dc.w    20000
  267. color    dc.w    1
  268. gfxbase    dc.l    0
  269. intuibase    dc.l    0
  270. myscreen    dc.l    0
  271. the_rp    dc.l    0
  272. seed    dc.w    $5232
  273. mns    dc.w    0,0,320,200,5
  274.     dc.w    -1,0,CUSTOMSCREEN
  275.     dc.l    0,0,0,0
  276.  
  277. ytab    ds.w    200
  278. bytenum    ds.w    320
  279. bitnum    ds.b    320
  280. gfxname    dc.b    'graphics.library',0
  281. intuiname    dc.b    'intuition.library',0
  282.  
  283.     end
  284.