Motorola DSP96002 User Manual
Page 598
MOTOROLA
DSP96002 USER’S MANUAL
B-79
B.1.43.2 Integer Incremental Line Drawing Algorithm
This implementation of line drawing uses Bresenham’s algorithm. This algorithm uses only integer opera-
tions to generate the points.
; Bresenham Line Drawing Implementation
;
; When entering subroutine, the registers must
; be set as follows:
;
; d0 = d4 =
; d1 = d5 =
; d2 = x1 d6 = x0
; d3 = y1 d7 = y0
;
; When entering a line drawing loop, the registers
; are set as follows:
;
; d6 = x0
; d7 = y0
; d4 = dmajor
; d5 = n0 = dminor
; r0 = dmajor/2
; m0 = dmajor - 1
org p:$50
; Calculate dx and dy
_line
sub d6,d2 d2.l,d4.l
sub d7,d3 d3.l,d5.l
; Determine whether to increment x or y
tst d2 d2.l,d0.l
neg d2 iflt
tst d3 d3.l,d1.l
neg d3 iflt
cmp d3,d2
jge _inc_x
; Increment y case
; If dy is negative, switch endpoints and sign of dx and dy
_inc_y
tst d1
tfr d4,d6 iflt
tfr d5,d7 iflt