I can't remember where I got this code but it was supposed to be very very fast. I wonder if it could be adapted in oric asm, with all the screen optimizations you can usually do (you know the tables), pecause the curset function is soooo slow.

Code: Select all

```
#include <lib.h>
#define setpix(x,y) curset(x,y,2)
void lineTwoStep(int x0, int y0, int x1, int y1)
{
int i,dx,dy,stepx, stepy,length,extras,incr1,incr2,c,d;
dy = y1 - y0;
dx = x1 - x0;
if (dy < 0) { dy = -dy; stepy = -1; } else { stepy = 1; }
if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; }
setpix(x0,y0);
setpix(x1,y1);
if (dx > dy) {
length = (dx - 1) >> 2;
extras = (dx - 1) & 3;
incr2 = (dy << 2) - (dx << 1);
if (incr2 < 0) {
c = dy << 1;
incr1 = c << 1;
d = incr1 - dx;
for (i = 0; i < length; i++) {
x0 += stepx;
x1 -= stepx;
if (d < 0) { // Pattern:
setpix(x0,y0); //
x0+=stepx; //
setpix(x0,y0); // x o o
setpix(x1,y1); //
setpix(x1,y1);
x1 -= stepx;
d += incr1;
} else {
if (d < c) { // Pattern:
setpix(x0,y0); //
x0+= stepx; //
y0 += stepy; // o
setpix(x0,y0); // x o
setpix(x1,y1); //
x1-=stepx;
y1 -= stepy;
setpix(x1,y1);
} else {
y0+=stepy;
setpix(x0,y0); // Pattern:
x0 += stepx; //
setpix(x0,y0); // o o
y1 -= stepy; // x
setpix(x1,y1);
x1-=stepx;
setpix(x1,y1);
}
d+=incr2;
}
}
if (extras > 0) {
if (d < 0) {
x0+=stepx;
setpix(x0,y0);
if (extras > 1) {x0+=stepx; setpix(x0,y0);}
if (extras > 2) {x1-=stepx; setpix(x1,y1);}
} else
if (d < c) {
x0+=stepx;
setpix(x0,y0);
if (extras > 1) {x0+=stepx; y0+=stepy; setpix(x0,y0);}
if (extras > 2) {x1-=stepx; setpix(x1,y1);}
} else {
x0+=stepx;
y0+=stepy;
setpix(x0,y0);
if (extras > 1) {x0+=stepx;setpix(x0,y0);}
if (extras > 2) {x1-=stepx; y1-=stepy; setpix(x1,y1);}
}
}
} else {
c = (dy - dx) << 1;
incr1 = c << 1;
d = incr1 + dx;
for (i = 0; i < length; i++) {
x0 += stepx;
x1 -= stepx;
if (d > 0) {
y0 += stepy;
setpix(x0,y0);
x0+=stepx; // Pattern:
y0+=stepy; //
setpix(x0,y0); // o
y1 -= stepy; // o
setpix(x1,y1); // x
x1-= stepx;
y1 -= stepy;
setpix(x1,y1);
d += incr1;
} else {
if (d < c) {
setpix(x0,y0);
x0 += stepx; // Pattern:
y0 += stepy; //
setpix(x0,y0); // o
setpix(x1, y1); // x o
x1 -= stepx;
y1 -= stepy;
setpix(x1,y1);
} else {
y0 += stepy;
setpix(x0,y0); // Pattern:
x0 += stepx;
setpix(x0,y0); // o o
y1 -= stepy; // x
setpix(x1,y1);
x1 -= stepx;
setpix(x1,y1);
}
d += incr2;
}
}
if (extras > 0) {
if (d > 0) {
x0 += stepx;
y0 += stepy;
setpix(x0,y0);
if (extras > 1) {x0+=stepx; y0+=stepy; setpix(x0,y0);}
if (extras > 2) {x1-=stepx; y1-=stepy; setpix(x1,y1);}
} else
if (d < c) {
x0 += stepx;
setpix(x0,y0);
if (extras > 1) {x0+=stepx; y0+=stepy; setpix(x0,y0);}
if (extras > 2) {x1-=stepx; setpix(x1,y1);}
} else {
x0 += stepx;
y0 += stepy;
setpix(x0,y0);
if (extras > 1) {x0+=stepx; setpix(x0,y0);}
if (extras > 2) {
if (d > c)
{x1-=stepx; y1-=stepy; setpix(x1,y1);}
else
{x1-=stepx; setpix(x1,y1);}
}
}
}
}
} else {
length = (dy - 1) >> 2;
extras = (dy - 1) & 3;
incr2 = (dx << 2) - (dy << 1);
if (incr2 < 0) {
c = dx << 1;
incr1 = c << 1;
d = incr1 - dy;
for (i = 0; i < length; i++) {
y0 += stepy;
y1 -= stepy;
if (d < 0) {
setpix(x0,y0);
y0 += stepy;
setpix(x0,y0);
setpix(x1,y1);
y1 -= stepy;
setpix(x1,y1);
d += incr1;
} else {
if (d < c) {
setpix(x0, y0);
x0 += stepx;
y0 += stepy;
setpix(x0,y0);
setpix(x1,y1);
x1 -= stepx;
y1 -= stepy;
setpix(x1,y1);
} else {
x0 += stepx;
setpix(x0,y0);
y0 += stepy;
setpix(x0,y0);
x1 -= stepx; setpix(x1,y1);
y1 -= stepy; setpix(x1,y1);
}
d+=incr2;
}
}
if (extras > 0) {
if (d < 0) {
y0+=stepy; setpix( x0, y0);
if (extras > 1) {y0+=stepy; setpix(x0,y0);}
if (extras > 2) {y1-=stepy; setpix(x1,y1);}
} else
if (d < c) {
y0+=stepy; setpix(x0,y0);
if (extras > 1) {x0+=stepx; y0+=stepy; setpix(x0,y0);}
if (extras > 2) {y1-=stepy;setpix(x1,y1);}
} else {
x0+=stepx; y0+=stepy; setpix(x0,y0);
if (extras > 1) {y0 += stepy;setpix(x0,y0);}
if (extras > 2) {x1-=stepx; y1-=stepy; setpix(x1,y1);}
}
}
} else {
c = (dx - dy) << 1;
incr1 = c << 1;
d = incr1 + dy;
for (i = 0; i < length; i++) {
y0 += stepy;
y1 -= stepy;
if (d > 0) {
x0+=stepx; setpix(x0,y0);
x0+=stepx; y0+=stepy; setpix(x0,y0);
x1-=stepy; setpix(x1,y1);
x1-=stepx; y1-=stepy; setpix(x1,y1);
d+=incr1;
} else {
if (d < c) {
setpix(x0,y0);
x0+=stepx; y0+=stepy; setpix(x0,y0);
setpix(x1,y1);
x1-=stepx, y1-=stepy; setpix(x1,y1);
} else {
x0+=stepx; setpix(x0,y0);
y0+=stepy; setpix(x0,y0);
x1-=stepy; setpix(x1,y1);
y1-=stepy; setpix(x1,y1);
}
d += incr2;
}
}
if (extras > 0) {
if (d > 0) {
x0+=stepx; y0+=stepy; setpix(x0,y0);
if (extras > 1) {x0+=stepx; y0+=stepy; setpix(x0,y0);}
if (extras > 2) {x1-=stepx, y1-=stepy; setpix(x1,y1);}
} else
if (d < c) {
y0+=stepy; setpix(x0,y0);
if (extras > 1) {x0+=stepx; y0+=stepy; setpix(x0,y0);}
if (extras > 2) {y1-=stepy; setpix(x1,y1);}
} else {
x0+=stepx; y0+=stepy; setpix(x0,y0);
if (extras > 1) {y0+=stepy; setpix(x0,y0);}
if (extras > 2) {
if (d > c)
{x1-=stepx, y1-=stepy; setpix(x1,y1);}
else
{y1-=stepy; setpix(x1,y1);}
}
}
}
}
}
}
```

That's something I have adapted from a code found on internet.

You can give it a try, it is way faster than Bresnham algorithm.