home *** CD-ROM | disk | FTP | other *** search
- /* ******************************************************************
- LINE.C
- Copyright (C) 1984 by Dan Rollins
- Uses incremental algorithm and fast ASM plotdot
- Permission is granted to use this for any purpose whatsoever.
- ******************************************************************* */
-
- _main(arglin) /* this just skips the 'main' function altogether */
- char *arglin; /* points to the DOS command line */
- {
- int x,y;
-
- dmode(1); /* enter text mode first (so screen will clear) */
- dmode(4); /* mid-res color graphics mode */
-
- /* test the line algorithm by drawing in all directions, colors */
-
- for (x=0; x<320; x+=4) plotline(160,100, x, 0, 3);
- for (y=0; y<200; y+=4) plotline(160,100,319, y, 2);
- for (x=319; x>=0; x-=4) plotline(160,100, x,199, 1);
- for (y=199; y>=0; y-=4) plotline(160,100, 0, y, 2);
-
- getch(); /* pause till key is pressed */
- dmode(2); /* re-enter text mode */
- }
-
- /* ******************************************************************
- PLOTLINE(x1,y1,x2,y2,color)
- draws a line from (x1,y1) to (x2,y2) in specified color (0 to 3)
- calls 'plotdot' (a fast, mid-resolution pixel-plotting routine)
- ******************************************************************* */
- plotline(x1,y1,x2,y2,color)
- int x1,y1; /* starting point */
- int x2,y2; /* ending point */
- int color;
- {
- /* use static variables for fastest access */
- static int lg_delta, sh_delta; /* distance of long, short axis */
- static int lg_step, sh_step; /* 0, 1 or -1 */
- static int cycle; /* decision variable */
- static int temp; /* swapping variable */
-
- lg_delta = x2-x1; /* get travel along X axis */
- if (lg_delta >= 0)
- lg_step = 1;
- else {
- lg_delta = -lg_delta; /* get absolute value */
- lg_step = -1; /* reverse direction */
- }
-
- sh_delta = y2-y1; /* get travel along Y axis */
- if (sh_delta >= 0)
- sh_step = 1;
- else {
- sh_delta = -sh_delta; /* get absolute value */
- sh_step = -1; /* reverse direction */
- }
-
- if (sh_delta > lg_delta) { /* if Y axis is longer, swap axes */
- cycle = sh_delta >> 1;
- temp = lg_delta; lg_delta = sh_delta; sh_delta = temp;
- temp = lg_step; lg_step = sh_step; sh_step = temp;
-
- while (y1 != y2) { /* loop for "vertical" line */
- plotpix(x1,y1,color);
- y1 += lg_step; /* always bump line pointer */
- cycle += sh_delta; /* bump decision variable */
- if (cycle >= lg_delta) { /* past decision threshold? */
- cycle -= lg_delta; /* reset for next decison cycle */
- x1 += sh_step; /* bump column pointer */
- }
- }
- }
- else { /* X axis is longer, so don't swap */
- cycle = lg_delta >> 1;
- while (x1 != x2) { /* loop for "horizontal" line */
- plotpix(x1,y1,color);
- x1 += lg_step;
- cycle += sh_delta;
- if (cycle >= lg_delta) {
- cycle -= lg_delta;
- y1 += sh_step;
- }
- } /* end of while */
- } /* end of else (for axis swap) */
- } /* end of plotline */
-
-
- /* ******************************************************************
- DMODE(mode)
- sets the display mode
- mode is: 0 = bw 40x25 text 4 = color 320x200 graphics
- 1 = color 40x25 text 5 = bw 320x200 graphics
- 2 = bw 80x25 text 6 = bw 640x200 graphics
- 3 = color 80x25 text
- ******************************************************************* */
- dmode(m)
- int m;
- {
- struct XREGS{ int ax,bx,cx,dx; } regbuf;
- regbuf.ax = m; /* AH = 0, AL = mode */
- int86(0x10,®buf,®buf);
- }
-
- /* AH = 0, AL = mode */
- int86(0x10,®buf,®buf);
- }
-