home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / asm / PJGRAPH.ZIP / CHAP12.2 < prev    next >
Encoding:
Text File  |  1989-09-26  |  2.6 KB  |  86 lines

  1. /* Sample program to illustrate EGA/VGA line-drawing routines.
  2.  *
  3.  * Must be linked with Listing 12.1 with a command line like:
  4.  *
  5.  *    tcc lst12-2 lst12-1.asm
  6.  *
  7.  * Compiled with Turbo C 2.0.
  8.  *
  9.  * By Michael Abrash.  2/4/89.
  10.  * Updated 6/30/89.
  11.  */
  12. #include <dos.h>     /* contains geninterrupt */
  13.  
  14. #define GRAPHICS_MODE   0x10
  15. #define TEXT_MODE       0x03
  16. #define BIOS_VIDEO_INT  0x10
  17. #define X_MAX           640      /* working screen width */
  18. #define Y_MAX           348      /* working screen height */
  19.  
  20. extern void EVGALine();
  21.  
  22. /*
  23.  * Subroutine to draw a rectangle full of vectors, of the specified
  24.  * length and color, around the specified rectangle center.
  25.  */
  26. void VectorsUp(XCenter, YCenter, XLength, YLength, Color)
  27. int XCenter, YCenter;   /* center of rectangle to fill */
  28. int XLength, YLength;   /* distance from center to edge
  29.                            of rectangle */
  30. int Color;              /* color to draw lines in */
  31. {
  32.    int WorkingX, WorkingY;
  33.  
  34.    /* Lines from center to top of rectangle */
  35.    WorkingX = XCenter - XLength;
  36.    WorkingY = YCenter - YLength;
  37.    for ( ; WorkingX < ( XCenter + XLength ); WorkingX++ )
  38.       EVGALine(XCenter, YCenter, WorkingX, WorkingY, Color);
  39.  
  40.    /* Lines from center to right of rectangle */
  41.    WorkingX = XCenter + XLength - 1;
  42.    WorkingY = YCenter - YLength;
  43.    for ( ; WorkingY < ( YCenter + YLength ); WorkingY++ )
  44.       EVGALine(XCenter, YCenter, WorkingX, WorkingY, Color);
  45.  
  46.    /* Lines from center to bottom of rectangle */
  47.    WorkingX = XCenter + XLength - 1;
  48.    WorkingY = YCenter + YLength - 1;
  49.    for ( ; WorkingX >= ( XCenter - XLength ); WorkingX-- )
  50.       EVGALine(XCenter, YCenter, WorkingX, WorkingY, Color);
  51.  
  52.    /* Lines from center to left of rectangle */
  53.    WorkingX = XCenter - XLength;
  54.    WorkingY = YCenter + YLength - 1;
  55.    for ( ; WorkingY >= ( YCenter - YLength ); WorkingY-- )
  56.       EVGALine(XCenter, YCenter, WorkingX, WorkingY, Color );
  57. }
  58.  
  59. /*
  60.  * Sample program to draw four rectangles full of lines.
  61.  */
  62. int main()
  63. {
  64.    char temp;
  65.  
  66.    /* Set graphics mode */
  67.    _AX = GRAPHICS_MODE;
  68.    geninterrupt(BIOS_VIDEO_INT);
  69.  
  70.    /* Draw each of four rectangles full of vectors */
  71.    VectorsUp(X_MAX / 4, Y_MAX / 4, X_MAX / 4,
  72.       Y_MAX / 4, 1);
  73.    VectorsUp(X_MAX * 3 / 4, Y_MAX / 4, X_MAX / 4,
  74.       Y_MAX / 4, 2);
  75.    VectorsUp(X_MAX / 4, Y_MAX * 3 / 4, X_MAX / 4,
  76.       Y_MAX / 4, 3);
  77.    VectorsUp(X_MAX * 3 / 4, Y_MAX * 3 / 4, X_MAX / 4,
  78.       Y_MAX / 4, 4);
  79.  
  80.    /* Wait for the enter key to be pressed */
  81.    scanf("%c", &temp);
  82.  
  83.    /* Back to text mode */
  84.    _AX = TEXT_MODE;
  85.    geninterrupt(BIOS_VIDEO_INT);
  86. }