home *** CD-ROM | disk | FTP | other *** search
-
- xdef _main
- xdef _comment
- include "flib.h" ;Well needed to clear screen
- include "tios.h" ;Needed to locate LCD memory
-
- ;************** Start of Fargo program **************
-
- _main:
-
- jsr flib::clr_scr ;clear screen
-
- ;registers d0-d4/a0 are destroyed by this function (could be pushed/poped ?)
-
- move.w #0,d0 ;d0=X1
- move.w #0,d1 ;d1=Y1
- move.w #200,d2 ;d2=X2
- move.w #128,d3 ;d3=Y2
-
- move.l #LCD_MEM,a0 ;LCD memory address
- move.w d1,d4 ;d4 contains coordinates of pixel, that is
- mulu #240,d4 ;x + 240*y (240 is screen width)
- add.w d0,d4
-
- movem.w d2-d3,-(sp) ;Push both regs
- sub.w d0,d2 ;DeltaX
- sub.w d1,d3 ;DeltaY
- cmp d2,d3 ;Well we should increment the "longest way" by one
- movem.w (sp)+,d2-d3 ; and apply the "error accumulation" to the other
- ble @@ok ; or go through X or Y axis
-
- exg.w d2,d3 ;Exchange regs so that "X" is always the longest way
- exg.w d1,d0
- move.w #240,xincr ;Value added each time, as he believes to increment X,
- move.w #1,yincr ; we must swap both values so that it works properly again
-
-
- @@ok:
- sub.w d1,d3 ;deltay = delaty
- lsl.w #1,d3 ;deltay2 = 2*delaty
- move.w d3,deltay2
-
- sub.w d0,d2 ;DeltaX->d2
- move.w d2,d1 ;DeltaX->d1 = how long is the longest way?
- lsl.w #1,d2
- sub.w d3,d2
- neg.w d2
- move.w d2,deltay_x2 ;Deltay_x2 = 2 * (DeltaY - DeltaX)
-
- sub.w d1,d3 ;d3 = variable and tells us when the error reaches 1
-
- @@line:
- move.w d4,d0 ;Here we go
- move.w d4,d2 ; pixel plotting mechanism I could explain if anyone wants
- neg d0 ; to ...
- and.w #7,d0 ;
- sub.w #1,d2 ;
- lsr.w #3,d2 ;
- bset.b d0,0(a0,d2) ; plotting pixel
- add.w xincr,d4 ;So always increment the longest axis
- or.w d3,d3 ;Test d3's sign
- bpl @@inc_Y ;Jump if Neg-FLAG set
- add.w deltay2,d3 ;Modify the "error-counter"
- dbra d1,@@line ;OK next pixel
- bra @@lf ;Well to quit after d1 reaches 0
- @@inc_Y:
- add.w deltay_x2,d3 ;We have to increment the small axis !
- add.w yincr,d4
- dbra d1,@@line ;Next pixel
- @@lf:
-
- jsr flib::idle_loop ;Wait until a key is pressed
-
- rts
-
- ;*****************************************************
-
- ;*****************************************************
-
- xincr dc.w 1 ;Var for the long-way incrementation
- yincr dc.w 240 ;Var for the short-way incrementation
- deltay2 dc.w 0 ;2 * DeltaY
- deltay_x2 dc.w 0 ;2 * (DeltaX - DeltaY)
-
- ;****************************************************
- _comment:
- dc.b "Jerbom's Bresenham line",0
- ;************** End of Fargo program ****************
-
-
- end