home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 92 / asm / source / fargo / bline.asm next >
Encoding:
Assembly Source File  |  2001-07-01  |  2.6 KB  |  91 lines

  1.  
  2.         xdef            _main
  3.     xdef        _comment
  4.     include        "flib.h"    ;Well needed to clear screen
  5.     include        "tios.h"    ;Needed to locate LCD memory
  6.  
  7. ;************** Start of Fargo program **************
  8.  
  9. _main:
  10.  
  11.     jsr        flib::clr_scr    ;clear screen
  12.  
  13. ;registers d0-d4/a0 are destroyed by this function (could be pushed/poped ?)
  14.         
  15.     move.w        #0,d0        ;d0=X1
  16.     move.w        #0,d1        ;d1=Y1
  17.     move.w        #200,d2        ;d2=X2
  18.     move.w        #128,d3        ;d3=Y2
  19.  
  20.     move.l        #LCD_MEM,a0    ;LCD memory address
  21.     move.w        d1,d4        ;d4 contains coordinates of pixel, that is
  22.     mulu        #240,d4        ;x + 240*y (240 is screen width)
  23.     add.w        d0,d4
  24.  
  25.     movem.w        d2-d3,-(sp)    ;Push both regs
  26.     sub.w        d0,d2        ;DeltaX
  27.     sub.w        d1,d3        ;DeltaY
  28.     cmp        d2,d3        ;Well we should increment the "longest way" by one
  29.     movem.w        (sp)+,d2-d3    ; and apply the "error accumulation" to the other
  30.     ble        @@ok        ; or go through X or Y axis
  31.     
  32.     exg.w        d2,d3        ;Exchange regs so that "X" is always the longest way
  33.     exg.w        d1,d0
  34.     move.w        #240,xincr    ;Value added each time, as he believes to increment X,
  35.     move.w        #1,yincr    ; we must swap both values so that it works properly again
  36.  
  37.  
  38. @@ok:
  39.     sub.w        d1,d3        ;deltay = delaty
  40.     lsl.w        #1,d3        ;deltay2 = 2*delaty
  41.     move.w        d3,deltay2
  42.  
  43.     sub.w        d0,d2        ;DeltaX->d2
  44.     move.w        d2,d1        ;DeltaX->d1 = how long is the longest way?
  45.     lsl.w        #1,d2
  46.     sub.w        d3,d2
  47.     neg.w        d2
  48.     move.w        d2,deltay_x2    ;Deltay_x2 = 2 * (DeltaY - DeltaX)
  49.  
  50.     sub.w        d1,d3        ;d3 = variable and tells us when the error reaches 1
  51.  
  52. @@line:
  53.     move.w        d4,d0        ;Here we go
  54.     move.w        d4,d2        ; pixel plotting mechanism I could explain if anyone wants
  55.     neg        d0        ; to ...
  56.     and.w        #7,d0        ;
  57.     sub.w        #1,d2        ;
  58.     lsr.w        #3,d2        ;
  59.     bset.b        d0,0(a0,d2)    ; plotting pixel
  60.     add.w        xincr,d4    ;So always increment the longest axis
  61.     or.w        d3,d3        ;Test d3's sign
  62.     bpl        @@inc_Y        ;Jump if Neg-FLAG set
  63.     add.w        deltay2,d3    ;Modify the "error-counter"
  64.     dbra        d1,@@line    ;OK next pixel
  65.     bra        @@lf        ;Well to quit after d1 reaches 0
  66. @@inc_Y:
  67.     add.w        deltay_x2,d3    ;We have to increment the small axis !
  68.     add.w        yincr,d4
  69.     dbra        d1,@@line    ;Next pixel
  70. @@lf:
  71.  
  72.     jsr        flib::idle_loop    ;Wait until a key is pressed
  73.  
  74.     rts
  75.  
  76. ;*****************************************************
  77.  
  78. ;*****************************************************
  79.  
  80. xincr        dc.w 1            ;Var for the long-way incrementation
  81. yincr        dc.w 240        ;Var for the short-way incrementation
  82. deltay2        dc.w 0            ;2 * DeltaY
  83. deltay_x2    dc.w 0            ;2 * (DeltaX - DeltaY)
  84.  
  85. ;****************************************************
  86. _comment:
  87.         dc.b    "Jerbom's Bresenham line",0
  88. ;************** End of Fargo program ****************
  89.  
  90.  
  91.         end