home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pctech / hlsrc / hlgrsubs.c < prev    next >
C/C++ Source or Header  |  1988-09-09  |  4KB  |  143 lines

  1. /*+
  2.     Name:       HLGRSUBS.C
  3.     Author:     Kent J. Quirk
  4.             (c) Copyright 1988 Ziff Communications Co.
  5.     Date:       April 1988
  6.     Abstract:   A set of graphic subroutines which allow the
  7.             benchmarks to have code which is independent of the
  8.             video mode. This also sets a set of useful colors. 
  9.             Color 0 is always black, and color 15 is always white. 
  10.             The colors in the middle are designed to be relatively
  11.             pleasing in sequential combinations from beginning to
  12.             the end.  The global variable colorlist always points
  13.             to an array of 16 integer colors.
  14.     History:    09-Sep-88    kjq    Version 1.00
  15. -*/
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <dos.h>
  20. #include <graph.h>
  21. #include <string.h>
  22. #include <malloc.h>
  23.  
  24. static int egacolorlist[]     = { 0,1,2,4, 5,3,6,7, 8,9,10,12, 13,11,14,15 };
  25. static int cgacolorlist[]     = { 0,1,2,3, 1,2,3,3, 0,1,2,3,   1,2,3,3 };
  26. static int monocolorlist[]    = { 0,1,1,1, 1,1,1,1, 1,1,1,1,   1,1,1,1 };
  27. static int vgamonocolorlist[] = { 0,3,1,3, 1,3,1,3, 1,3,1,3,   1,3,1,3 };
  28. int *colorlist;
  29.  
  30. /**** c h e c k _ v g a _ m o n o ****
  31.     Abstract:    Check to see if the VGA monochrome screen is present
  32.     Parameters: none
  33.     Returns:    1 if it is, 0 if it's color
  34. ****************************/
  35. int check_vga_mono()
  36. {
  37.     union REGS regs;
  38.  
  39.     regs.x.ax = 0x1A00;         /* get display combination mode */
  40.     int86(0x10, ®s, ®s);  /* video BIOS interrupt */
  41.     if (regs.h.al == 0x1A)      /* is this function supported? */
  42.     {
  43.     if ((regs.h.bl == 0x07) || (regs.h.bl == 0x0B))
  44.         return(1);          /* monochrome present */
  45.     else
  46.         return(0);          /* not mono */
  47.     }
  48.     return(0);                  /* just don't know */
  49. }
  50.  
  51. /**** i n i t _ v i d e o ****
  52.     Abstract:    Initialize the video display to the highest-resolution 
  53.         graphics mode available.
  54.     Parameters: configp -- A pointer to an area to put the video configuration
  55.                 info.
  56.     Returns:    1 if successful, 0 if not
  57.     Comments:    If the environment variable HLGRAPH is present, uses it
  58.         to obtain the video mode information.
  59. ****************************/
  60. int init_video(configp)
  61. struct videoconfig far *configp;
  62. {    
  63.     char *buf;
  64.     
  65.     if ((buf = getenv("HLGRAPH")) == NULL)    /* if no extern video mode */
  66.     {     
  67.     if (_setvideomode(_VRES16COLOR))
  68.         colorlist = egacolorlist;
  69.     else if (_setvideomode(_HERCMONO))
  70.         colorlist = monocolorlist;
  71.     else if (_setvideomode(_ERESCOLOR))
  72.         colorlist = egacolorlist;
  73.     else if (_setvideomode(_HRES16COLOR))
  74.         colorlist = egacolorlist;
  75.     else if (_setvideomode(_MRES16COLOR))
  76.         colorlist = egacolorlist;
  77.     else if (_setvideomode(_MRES4COLOR))
  78.         colorlist = cgacolorlist;
  79.     else if (_setvideomode(_HRESBW))
  80.         colorlist = monocolorlist;
  81.     else
  82.         return(0);
  83.     }
  84.     else 
  85.     {
  86.     _setvideomode(atoi(buf));        /* set desired mode */
  87.     _getvideoconfig(configp);
  88.     if (configp->numcolors >= 16)
  89.         colorlist = egacolorlist;
  90.     else if (configp->numcolors >= 4)
  91.         colorlist = cgacolorlist;
  92.     else if (configp->numcolors >= 2)
  93.         colorlist = vgamonocolorlist;
  94.     else if (configp->numcolors >= 1)
  95.         colorlist = monocolorlist;
  96.     }
  97.     
  98.     if (check_vga_mono())
  99.     {
  100.         _setvideomode(_ERESNOCOLOR);
  101.         colorlist = vgamonocolorlist;
  102.     }
  103.  
  104.     _getvideoconfig(configp);
  105.     return(1);
  106. }
  107.  
  108. /**** p l o t s t r ****
  109.     Given a string, a position, and a color, this plots the string at
  110.     that position on the screen.  It does so by first drawing it using _outtext
  111.     on the top line of the screen.  Then it uses _getimage to read the image
  112.     into a buffer, then uses _putimage to place it at the desired location.
  113. ****************************/
  114. int plotstr(char *s, int x, int y, int color, int mode)
  115. {
  116.     int i, c;
  117.     int height, width;
  118.     struct xycoord ul, lr;
  119.     char far *image;
  120.     struct videoconfig config;
  121.  
  122.     _getvideoconfig(&config);
  123.  
  124.     _settextcolor(color);
  125.     _settextposition(1,1);
  126.     _outtext(s);
  127.  
  128.     width = config.numxpixels/config.numtextcols * strlen(s);
  129.     height = config.numypixels/config.numtextrows;
  130.     if ((image = _fmalloc((int)_imagesize(0, 0, width, height))) == NULL)
  131.         return(0);
  132.  
  133.     lr = _getlogcoord(width, height);
  134.     ul = _getlogcoord(0, 0);
  135.     _getimage(ul.xcoord, ul.ycoord, lr.xcoord, lr.ycoord, image);
  136.     _settextcolor(0);               /* erase string */
  137.     _settextposition(1,1);
  138.     _outtext(s);
  139.     _putimage(x, y, image, mode);
  140.     _ffree(image);
  141.     return(1);
  142. }
  143.