Category : C Source Code
Archive   : RXGRAPH.ZIP
Filename : DRAWLINE.C

 
Output of file : DRAWLINE.C contained in archive : RXGRAPH.ZIP
#if 0
Draw a line on a color monitor (CGA only) by specifying
bit coordinates of the ends and the color. The programmer
of the calling routine should insure that:
1: The video mode is set to a CGA graphics mode (4, 5, or 6)
2: The co-ordinates and color are within the range valid for
the graphics mode in use.

Preprocessor symbol PASS, PUT_DOT and PROC_NAME are reserved.

IF BIOS is not defined on the MSC command line, this generates
two functions:
draw_line_320() /* uses put_dot_320 */
draw_line_640() /* uses put_dot_640 */
This is done in a rather unique way, by having the preprocessor
#include the source file recursively after changing the symbols
for the name of the function to generate (PROC_NAME) and the
routine for putting dots (PUT_DOT) and the symbol PASS itself.

Compile option '/DBIOS' specifies that BIOS calls are used for
dot output, in which case only one function is generated, and it
will work in either mode.
#endif

#ifdef BIOS
#include "bitmap.h"
#define PUT_DOT put_dot
#define PROC_NAME draw_line
#endif

#ifndef PROC_NAME
/* This is pass one using direct memory writes - the default */
#include "bitmap.h"
#define PASS 1
#define PUT_DOT put_dot_320
#define PROC_NAME draw_line_320
#endif

void PROC_NAME(x1,y1,x2,y2,color)
int x1, y1, x2, y2;
unsigned char color;
{
int x;
if (y1==y2)
{
if (x1 else {x=x2; x2=x1;}
while (x<=x2)
PUT_DOT(y1,x++,color);
}
else
{
int y, old_x;
if (y2>y1)
y=y1;
else
{
y=y2; y2=y1; y1=y;
x=x2; x2=x1; x1=x;
}
old_x=x1;
while (y<=y2)
{
x=x1 + (long)(x2-x1)*(y-y1) / (y2-y1);
if (old_x-x > 1)
{
while (old_x-- > x)
PUT_DOT(y, old_x, color);
}
else if (old_x-x < -1)
{
while (old_x++ < x)
PUT_DOT(y, old_x, color);
}
PUT_DOT(y,x,color);
old_x=x;
++y;
}
}
}

/* If this was pass one for the direct version compile again. */
#if PASS==1
#undef PASS
#undef PUT_DOT
#undef PROC_NAME
#define PUT_DOT put_dot_640
#define PROC_NAME draw_line_640
#include "drawline.c"
#endif


  3 Responses to “Category : C Source Code
Archive   : RXGRAPH.ZIP
Filename : DRAWLINE.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/