home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 514b.lha / line+fill / linedrawer2 < prev    next >
Text File  |  1991-06-08  |  2KB  |  104 lines

  1.     Lately there has been a few requests for a mythical very fast line
  2. drawing routine, posted to a comp.sys.amiga.* news group some time in
  3. the past, this is not it.
  4.     This is, however, a good line drawing routine written by me, and
  5. using Bresenham's line drawing algorithm taken from,
  6. Computer Graphics,    Donald Hearn, M. Pauline Baker
  7. published by Prentice-Hall International.
  8.     It also produces lines identicle to lines drawn by the blitter.
  9.  
  10.     Stuart Twyford
  11.     Internet: int131d@monu3.cc.monash.edu.au
  12.  
  13. Bresenham_line:
  14. INPUT:
  15.     d0<31-16>    Y cordinate of start point
  16.     d0<15-0>    X cordinate of start point
  17.     d1<31-16>    Y cordinate of end point
  18.     d1<15-0>    X cordinate of end point
  19.     a0        pointer to bit plane
  20.  
  21. USES:
  22.     d0-d7
  23.     a0-a1
  24.  
  25. Bresenham_line:
  26.     move.w    #1,d6
  27.     sub.w    d0,d1
  28.     bge.s    .got_deltaX
  29.     neg.w    d1
  30.     neg.w    d6
  31. .got_deltaX:
  32.     swap    d0
  33.     move.w    d1,d2
  34.     swap    d1
  35.     move.w    #Width_in_bytes,d7
  36.     sub.w    d0,d1
  37.     bge.s    .got_deltaY
  38.     neg.w    d1
  39.     neg.w    d7
  40. .got_deltaY:
  41.     clr.w    d5
  42.     cmp.w    d1,d2
  43.     bge.s    .got_L_and_Sdelta
  44.     swap    d1
  45.     not.w    d5
  46. .got_L_and_Sdelta:
  47.     move.w    d0,d2
  48.     mulu    #Width_in_bytes,d2
  49.     adda.w    d2,a0
  50.     swap    d0
  51.     movea.w    d7,a1
  52.     move.w    d1,d2
  53.     swap    d1
  54.     add.w    d2,d2
  55.     move.w    d2,d3
  56.     sub.w    d1,d3
  57.     move.w    d3,d4
  58.     sub.w    d1,d4
  59.     tst.w    d5
  60.     bne.s    .deltaY_greater
  61. .next_X:
  62.     move.w    d0,d7
  63.     not.w    d7
  64.     move.w    d0,d5
  65.     asr.w    #3,d5
  66.     bset    d7,(a0,d5.w)
  67.     tst.w    d1
  68.     beq.s    .line_done
  69.     subq.w    #1,d1
  70.     add.w    d6,d0
  71.     tst.w    d3
  72.     bge.s    .add_d4_to_Y
  73.     add.w    d2,d3
  74.     bra.s    .next_X
  75. .add_d4_to_Y:
  76.     adda.w    a1,a0
  77.     add.w    d4,d3
  78.     bra.s    .next_X
  79. .deltaY_greater:
  80. .next_Y:
  81.     move.w    d0,d7
  82.     not.w    d7
  83.     move.w    d0,d5
  84.     asr.w    #3,d5
  85.     bset    d7,(a0,d5.w)
  86.     tst.w    d1
  87.     beq.s    .line_done
  88.     subq.w    #1,d1
  89.     adda.w    a1,a0
  90.     tst.w    d3
  91.     bge.s    .add_d4_to_X
  92.     add.w    d2,d3
  93.     bra.s    .next_Y
  94. .add_d4_to_X:
  95.     add.w    d6,d0
  96.     add.w    d4,d3
  97.     bra.s    .next_Y
  98. .line_done:
  99.     rts
  100.  
  101.  
  102.  
  103.  
  104.