I now have an optimized line routine, but it is slightly buggy. It would be hard to describe, so I have attached 2 pictures - "drawline" is working normally, and "drawline2_bug" is drawn using the optimized routine (below). Any ideas what is causing this? (other than my dodgy code
)
Code:
drawline2: ;INPUT: d0=x1, d1=y1, d2=x2, d3=y2
; d4=width, a0=aptr
.deltax_and_sx
moveq #1,d6 ;sx = 1
move.w d2,d4 ;d4 = x2
sub.w d0,d4 ;delta_x = x2 - x1
bgt.b .deltay_and_sy
neg.w d4 ;-delta_x -> delta_x
moveq #-1,d6 ;sx = -1
.deltay_and_sy
moveq #1,d7 ;sy = 1
move.w d3,d5 ;d5 = y2
sub.w d1,d5 ;delta_y = y2 - y1
bgt.b .get_ERR
neg.w d5 ;-delta_y -> delta_y
moveq #-1,d7 ;sy = -1
.get_ERR
move.w d4,a1 ;a1 = delta_x
sub.w d5,a1 ;a1 = delta_x - delta_y
;a1=ERR
.mainloop
movem.l d0-d2/a1,-(sp)
jsr plot ;plot a pixel
movem.l (sp)+,d0-d2/a1
cmp.w d2,d0 ;does x1 equal x2?
beq .exit1
.no_exit
move.w a1,a2 ;\ a2 = ERR * 2
add.w a1,a2 ;/
neg.w d5 ;delta_y -> -delta_y
cmp.w d5,a2 ;E2 > -delta_Y ?
bgt.b .dec_ERR
.dec_ERR_return
cmp.w d4,a2
blt.b .add_ERR ;E2 < delta_x ?
bra.s .mainloop
.dec_ERR
neg.w d5 ;-delta_y -> delta_y
sub.w d5,a1 ;ERR=ERR-delta_Y
add.w d6,d0 ;X1=X1+shift_X
bra.s .dec_ERR_return
.add_ERR
add.w d4,a1 ;ERR=ERR+delta_X
add.w d7,d1 ;Y1=Y1+SY
bra .mainloop
.exit1
cmp.w d1,d3 ;exit if y1 equals y2
bne .no_exit
.exit
rts
Regards,
Lonewolf10