DG> Anyone know how to put a pixel in EGA (mode 10h) video?
dg>.....
/*_|_| HAPYTRLZ.C PUBLIC DOMAIN By Kurt Kuzba. (4/20/97)
_|_|_| EGA screen functions in C, with some ASM. ( 2 of 2)
_|_|*/
/* draws a line from (x, y) to (x2, y2) in color c */
void bresenham_line(int x, int y, int x2, int y2, int c)
{
int i, steep = 0, sx, sy, dx, dy, e, ex, ey;
dx = ((x2 - x) > 0) ? x2 - x : -(x2 - x);
sx = ((x2 - x) > 0) ? 1 : -1;
dy = ((y2 - y) > 0) ? y2 - y : -(y2 - y);
sy = ((y2 - y) > 0) ? 1 : -1;
if(dy > dx)
{
steep = x; x = y; y = steep; /* swap x and y */
steep = dx; dx = dy; dy = steep; /* swap dx and dy */
steep = sx; sx = sy; sy = steep; /* swap sx and sy */
steep = 1;
}
ex = dx << 1; ey = dy << 1; e = ey - dx;
for(i = 0; i < dx; i++)
{
if(steep) putpixel(y, x, c); else putpixel(x, y, c);
while(e >= 0) { y += sy;e -= ex; } x += sx; e += ey;
}
putpixel(x2, y2, c);
}
void test(void)
{
LineEnd xy[20] =
{ 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 };
int loop, c, xd[2], yd[2], change, hi = SCREEN_HEIGHT - 2;
xd[0] = rnd(2, 4); xd[1] = rnd(2, 4);
yd[0] = rnd(2, 4); xd[1] = rnd(2, 4);
change = c = 0;
while(*((char far*)0x0041000aL) == *((char far*)0x0041000cL))
{
if((change = ((change + 1) & 255)) == 0) c = rnd(0, 15);
for(loop = 0; loop < 2; loop++)
{
xy[loop + 18] = xy[loop + 16];
xy[loop + 16] = xy[loop + 14];
xy[loop + 14] = xy[loop + 12];
xy[loop + 12] = xy[loop + 10];
xy[loop + 10] = xy[loop + 8];
xy[loop + 8] = xy[loop + 6];
xy[loop + 6] = xy[loop + 4];
xy[loop + 4] = xy[loop + 2];
xy[loop + 2] = xy[loop];
if(xy[loop].x < 1 ) xd[loop] = rnd(3, 7);
if(xy[loop].x > hi ) xd[loop] = -rnd(3, 7);
if(xy[loop].y < 1 ) yd[loop] = rnd(3, 7);
if(xy[loop].y > 638 ) yd[loop] = -rnd(3, 7);
xy[loop].x += xd[loop];
xy[loop].y += yd[loop];
}
bresenham_line(xy[18].y, xy[18].x, xy[19].y, xy[19].x, c);
bresenham_line(xy[16].y, xy[16].x, xy[17].y, xy[17].x, 1);
bresenham_line(xy[14].y, xy[14].x, xy[15].y, xy[15].x, 1);
bresenham_line(xy[12].y, xy[12].x, xy[13].y, xy[13].x, 9);
bresenham_line(xy[10].y, xy[10].x, xy[11].y, xy[11].x, 9);
bresenham_line(xy[8].y, xy[8].x, xy[9].y, xy[9].x, 3);
bresenham_line(xy[6].y, xy[6].x, xy[7].y, xy[7].x, 3);
bresenham_line(xy[4].y, xy[4].x, xy[5].y, xy[5].x, 11);
bresenham_line(xy[2].y, xy[2].x, xy[3].y, xy[3].x, 11);
bresenham_line(xy[0].y, xy[0].x, xy[1].y, xy[1].x, 15);
}
}
int main(void)
{
vidmode(0x10);
srand((unsigned)time(NULL));
test();
getch();
vidmode(0x03);
return 0;
}
/*_|_| end HAPYTRLZ.C PUBLIC DOMAIN ( 2 of 2 )*/
> ] Love is not blind, but sometimes it looks the other way.....
---
---------------
* Origin: *YOPS ]I[* 3.1 GIG * RA/FD/FE RADist * Milwaukee, WI (1:154/750)
|