home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 98.img / LCNOW2.ZIP / EXAMPLES / VMODES.C < prev    next >
C/C++ Source or Header  |  1988-08-03  |  4KB  |  141 lines

  1. /*
  2.  * V M O D E S
  3.  *
  4.  * Show how to run a program in the best
  5.  * mode available for the hardware configuration it
  6.  * finds when it starts execution.
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <conio.h>
  12. #include <graph.h>
  13. #include <math.h>
  14.  
  15. /*
  16.  * Function prototypes.
  17.  */
  18. int SetBestColorGraphicsMode(void);
  19.  
  20. #define K_ESC           27
  21. #define MODE_ERR        0
  22.  
  23. /*
  24.  * Table of video modes and names.
  25.  */
  26. struct mode_st {
  27.     int number;     /* internal mode number */
  28.     char *name;     /* symbolic name */
  29.     char *desc;     /* description */
  30. } Mode[] = {
  31.     0,      "_TEXTBW40",            "40x25 monochrome text",
  32.     1,      "_TEXTC40",             "40x24 color text",
  33.     2,      "_TEXTBW80",            "80x25 monochrome text",
  34.     3,      "_TEXTC80",             "80x25 color text",
  35.     4,      "_MRES4COLOR",          "320x200 4-color graphics",
  36.     5,      "_MRESNOCOLOR",         "320x200 monochrome graphics",
  37.     6,      "_HRESBW",              "640x200 monochrome",
  38.     7,      "_TEXTMONO",            "80x25 monochrome text (MDA)",
  39.     -1,     "",                     "(not supported)",
  40.     -1,     "",                     "(not supported)",
  41.     -1,     "",                     "(not supported)",
  42.     -1,     "",                     "(not supported)",
  43.     -1,     "",                     "(not supported)",
  44.     13,     "_MRES16COLOR",         "320x200 16-color graphics",
  45.     14,     "_HRES16COLOR",         "640x200 16-color graphics",
  46.     15,     "_ERESNOCOLOR",         "640x350 monochrome graphics",
  47.     16,     "_ERESCOLOR",           "640x350 color (4/16) graphics",
  48.     17,     "_VRES2COLOR",          "640x480 monochrome graphics",
  49.     18,     "_VRES16COLOR",         "640x480 16-color graphics",
  50.     19,     "_MRES256COLOR",        "320x200 256-color graphics"
  51. };
  52.  
  53. int
  54. main(void)
  55. {
  56.     struct videoconfig vidconfig;   /* video config data */
  57.  
  58.     /*
  59.      * Try to set the highest available graphics
  60.      * resolution mode with the greatest number
  61.      * of colors.
  62.      */
  63.     if (SetBestColorGraphicsMode() == MODE_ERR) {
  64.         fprintf(stderr,
  65.             "No medium resolution color support\n");
  66.         exit (1);
  67.     }
  68.  
  69.     /*
  70.      * Update video configuration members of
  71.      * vidconfig structure.
  72.      */
  73.     _getvideoconfig(&vidconfig);
  74.  
  75.     /*
  76.      * Display information about the current video configuration.
  77.      */
  78.     printf("\nVideo mode name: %s\n", Mode[vidconfig.mode].name);
  79.     printf("[%s]\n\n", Mode[vidconfig.mode].desc);
  80.     printf("Horizontal pixels = %d\n", vidconfig.numxpixels);
  81.     printf("Vertical pixels = %d\n", vidconfig.numypixels);
  82.     printf("Text rows = %d\n", vidconfig.numtextrows);
  83.     printf("Text columns = %d\n", vidconfig.numtextcols);
  84.     printf("Number of actual colors = %d\n",
  85.         vidconfig.numcolors);
  86.     printf("Bits per pixel = %d\n", vidconfig.bitsperpixel);
  87.     printf("Video pages = %d\n", vidconfig.numvideopages);
  88.     printf("Video memory size = %d KB\n", vidconfig.memory);
  89.  
  90.     /*
  91.      * Halt and wait for a keypress.
  92.      */
  93.     fprintf(stderr, "\n\tPress a key...");
  94.     if (getch() == '\0')
  95.         getch();
  96.  
  97.     /*
  98.      * Restore the original video mode and
  99.      * return control to the operating system.
  100.      */
  101.     _setvideomode(_DEFAULTMODE);
  102.     return (0);
  103. }
  104.  
  105.  
  106. /*
  107.  * SetBestColorGraphicsMode()
  108.  *
  109.  * Attempt to set the best available color graphics mode.
  110.  */
  111.  
  112. int
  113. SetBestColorGraphicsMode()
  114. {
  115.     int rc = MODE_ERR;      /* Assume the worst. */
  116.  
  117.     /*
  118.      * This routine assumes that
  119.      * resolution is more important than the number
  120.      * of actual colors.
  121.      */
  122.     if (_setvideomode(_VRES16COLOR))
  123.         rc = _VRES16COLOR;
  124.     else if (_setvideomode(_ERESCOLOR))
  125.         rc = _ERESCOLOR;
  126.     else if (_setvideomode(_HRES16COLOR))
  127.         rc = _HRES16COLOR;
  128.     else if (_setvideomode(_MRES256COLOR))
  129.         rc = _MRES256COLOR;
  130.     else if (_setvideomode(_MRES16COLOR))
  131.         rc = _MRES16COLOR;
  132.     else if (_setvideomode(_MRES4COLOR))
  133.         rc = _MRES4COLOR;
  134.  
  135.     /*
  136.      * Tell the calling function what was set.  A return
  137.      * code of MODE_ERR says we struck out -- no color.
  138.      */
  139.     return (rc);
  140. }
  141.