Quote:
Originally Posted by meynaf
I can do this for you. It doesn't work
More precisely, if you examine the C code you will notice it can draw a line only if dx,dy are positive values (IOW x,y positions can only increase).
But my routine has to draw lines with just about any direction...
|
OK, try this one (same level of checking as my previous effort
Code:
extern void
putpixel(register int x0 asm("d1"),
register int y0 asm("d2"),
register int c asm("d3"));
void drawline(register int x0 asm("d1"),
register int y0 asm("d2"),
register int c asm("d3"),
register int dx asm("d4"),
register int dy asm("d5"))
{
int x1 = x0 + dx;
int y1 = y0 + dy;
int sx = x0 < x1 ? 1 : -1;
int sy = y0 < y1 ? 1 : -1;
int err = dx + dy, e2; /* error value e_xy */
for (;;){ /* loop */
putpixel(x0,y0,c);
if (x0 == x1 && y0 == y1) break;
e2 = 2 * err;
if (e2 >= dy) { err += dy; x0 += sx; } /* e_xy+e_x > 0 */
if (e2 <= dx) { err += dx; y0 += sy; } /* e_xy+e_y < 0 */
}
}
Code:
_drawline:
subq.l #4,sp
movem.l a6/a5/a4/a3/a2/d7/d6/d5/d4/d3/d2,-(sp)
move.l d1,a3
move.l d2,a2
move.l d3,44(sp)
lea (a3,d4.l),a5
lea (a2,d5.l),a6
cmp.l d1,a5
sle d7
ext.w d7
ext.l d7
moveq #1,d0
or.l d0,d7
cmp.l d2,a6
sle d6
ext.w d6
ext.l d6
or.l d0,d6
move.l d4,a4
add.l d5,a4
_.L4:
move.l 44(sp),d3
move.l a2,d2
move.l a3,d1
jsr _putpixel
cmp.l a3,a5
jne _.L5
cmp.l a2,a6
jeq _.L1
_.L5:
move.l a4,d0
add.l a4,d0
cmp.l d5,d0
jlt _.L7
add.l d5,a4
add.l d7,a3
_.L7:
cmp.l d4,d0
jgt _.L4
add.l d4,a4
add.l d6,a2
jra _.L4
_.L1:
movem.l (sp)+,d2/d3/d4/d5/d6/d7/a2/a3/a4/a5/a6
addq.l #4,sp
rts