/* ------------------------------------------------------------------------
System       : Manx Aztec C65 Version 3.2b
               MS-DOS cross-development environment
Platform     : Apple IIe 128K PRODOS 8
Program      : dhrline.c
Description  : G2 Library Routine
               Double Hi-Res 140 x 192 x 16 color
               Bresenham Algorithm line drawing routine
Written by   : Bill Buckels
Date Written : January 2013
Revision     : 1.0 First Release
Licence      : You may use this code for whatever you wish as long
               as you agree that Bill Buckels has no warranty or
               liability obligations whatsoever from said use.
------------------------------------------------------------------------ */
dhrline(x1, y1, x2, y2, drawcolor)
int x1, y1, x2, y2, drawcolor;
{

	int dx, dy, sx, sy, err, err2;

	if(x1 < x2) {
		dx = x2 - x1;
		sx = 1;
	}
	else {
		sx = -1;
		dx = x1 - x2;
	}

	if(y1 < y2) {
		sy = 1;
		dy = y2 - y1;
	}
	else {
		sy = -1;
		dy = y1 - y2;
	}

	err = dx-dy;

	for (;;) {
		dhrplot(x1,y1,drawcolor);

		if(x1 == x2 && y1 == y2)break;

		err2 = err*2;

		if(err2 > (0-dy)) {
			 err = err - dy;
			 x1 = x1 + sx;
		}

		if(err2 <  dx) {
			 err = err + dx;
			 y1 = y1 + sy;
		}
	}
	return;
}
