home *** CD-ROM | disk | FTP | other *** search
/ World of Graphics / WOGRAPH.BIN / 474.MODES.C < prev    next >
C/C++ Source or Header  |  1993-03-19  |  7KB  |  237 lines

  1. /****************************************************************************
  2. *
  3. *                        MegaGraph Graphics Library
  4. *
  5. *                   Copyright (C) 1993 Kendall Bennett.
  6. *                            All rights reserved.
  7. *
  8. * Filename:        $RCSfile: modes.c $
  9. * Version:        $Revision: 1.2 $
  10. *
  11. * Language:        ANSI C
  12. * Environment:    IBM PC (MS DOS)
  13. *
  14. * Description:    Routine to determine the available video modes for a
  15. *                specified video card, given memory restrictions.
  16. *
  17. * $Id: modes.c 1.2 1993/03/07 04:04:13 kjb Exp $
  18. *
  19. * Revision History:
  20. * -----------------
  21. *
  22. * $Log: modes.c $
  23. * Revision 1.2  1993/03/07  04:04:13  kjb
  24. * Bug fixes.
  25. *
  26. * Revision 1.1  1993/03/03  10:46:00  kjb
  27. * Initial revision
  28. *
  29. ****************************************************************************/
  30.  
  31. #include "drivers.h"
  32.  
  33. /*--------------------------- Global Variables ----------------------------*/
  34.  
  35. int        __modeTable[grMAXMODE+1];    /* Internal table of video modes    */
  36.  
  37. /*------------------------- Implementation --------------------------------*/
  38.  
  39. /* Routines in 'detectgr.asm' for returning the list of possible video
  40.  * modes for this adapter and display pages.
  41.  */
  42.  
  43. char far * _getSuperVGAModes(void);
  44. int _getSuperVGAPages(int mode,int memory,long *pagesize);
  45.  
  46. PRIVATE int loadVGAModes(int i)
  47. /****************************************************************************
  48. *
  49. * Function:        loadVGAModes
  50. * Parameters:    i    - Index to start loading modes at
  51. * Returns:        Index of next available space in mode table.
  52. *
  53. * Description:    Fills in all of the standard VGA video modes in the mode
  54. *                table.
  55. *
  56. ****************************************************************************/
  57. {
  58.     __modeTable[i++] = grEGA_320x200x16;
  59.     __modeTable[i++] = grEGA_640x200x16;
  60.     __modeTable[i++] = grEGA_640x350x16;
  61.     __modeTable[i++] = grVGA_640x400x16;
  62.     __modeTable[i++] = grVGA_640x480x16;
  63.     __modeTable[i++] = grVGA_320x200x256;
  64.     __modeTable[i++] = grVGAX_320x200x256;
  65.     __modeTable[i++] = grVGAX_320x240x256;
  66.     __modeTable[i++] = grVGAX_320x400x256;
  67.     __modeTable[i++] = grVGAX_320x480x256;
  68.     __modeTable[i++] = grVGAX_360x200x256;
  69.     __modeTable[i++] = grVGAX_360x240x256;
  70.     __modeTable[i++] = grVGAX_360x400x256;
  71.     __modeTable[i++] = grVGAX_360x480x256;
  72.     return i;
  73. }
  74.  
  75. PUBLIC int * MGL_availableModes(int driver,int memory)
  76. /****************************************************************************
  77. *
  78. * Function:        MGL_availableModes
  79. * Parameters:    driver    - Graphics device driver to check.
  80. *                memory    - Amount of memory on video card
  81. *
  82. * Returns:        Returns a pointer to a list of all the video modes that are
  83. *                currently available. This routine can be called before
  84. *                MGL_init() is called to determine the video modes available.
  85. *                The list of video modes is terminated by a -1, but you
  86. *                will have to call MGL_detectGraph() to determine the
  87. *                currently installed video card.
  88. *
  89. ****************************************************************************/
  90. {
  91.     int        i;
  92.     long    pagesize;
  93.     char    far *modes;
  94.  
  95.     switch(driver) {
  96.         case grMCGA:
  97.             __modeTable[0] = grVGA_320x200x256;
  98.             __modeTable[1] = -1;        /* Terminate the table    */
  99.             memory = 64;
  100.             break;
  101.         case grEGA:
  102.             __modeTable[0] = grEGA_320x200x16;
  103.             __modeTable[1] = grEGA_640x200x16;
  104.             __modeTable[2] = grEGA_640x350x16;
  105.             __modeTable[3] = -1;        /* Terminate the table    */
  106.             memory = 256;
  107.             break;
  108.         case grVGA:
  109.             i = loadVGAModes(0);
  110.             __modeTable[i] = -1;        /* Terminate the table    */
  111.             memory = 256;
  112.             break;
  113.         default:
  114.             if (driver >= __FIRST_SVGA && driver <= __LAST_SVGA) {
  115.                 /* We have a Super VGA video card. We know that we can use
  116.                  * all of the standard VGA video modes, but we must also
  117.                  * determine what SuperVGA video modes are available. We
  118.                  * obtain this information from the DetectGraph module.
  119.                  */
  120.  
  121.                 i = loadVGAModes(0);
  122.  
  123.                 /* Install all detected SuperVGA modes, filtering
  124.                  * those not supported with the memory installed
  125.                  */
  126.  
  127.                 modes = _getSuperVGAModes();
  128.                 if (memory >= 4096)    /* Fix strange memory sizes    */
  129.                     memory = 4096;
  130.                 else if (memory >= 3072)
  131.                     memory = 3072;
  132.                 else if (memory >= 2048)
  133.                     memory = 2048;
  134.                 else if (memory >= 1024)
  135.                     memory = 1024;
  136.                 else if (memory >= 512)
  137.                     memory = 512;
  138.                 else if (memory >= 256)
  139.                     memory = 256;
  140.  
  141.                 while (*modes != -1) {
  142.                     /* Compute the size of the video page for the mode, and
  143.                      * if we have enough memory for one page then include
  144.                      * it in the mode list
  145.                      */
  146.  
  147.                     if (*modes != 0) {
  148.                         if (_getSuperVGAPages(*modes | 0x80,memory,&pagesize) > 0) {
  149.                             if ((pagesize / 1024) <= memory)
  150.                                 __modeTable[i++] = *modes;
  151.                             }
  152.                         }
  153.                     modes++;
  154.                     }
  155.                 __modeTable[i] = -1;        /* Terminate the table    */
  156.                 }
  157.             else {
  158.                 /* No video modes are supported for this adapter */
  159.  
  160.                 __modeTable[0] = -1;        /* Terminate the table    */
  161.                 }
  162.         }
  163.     return __modeTable;
  164. }
  165.  
  166. PUBLIC int MGL_availablePages(int driver,int memory,int mode)
  167. /****************************************************************************
  168. *
  169. * Function:        MGL_availablePages
  170. * Parameters:    driver    - Graphics device driver to check.
  171. *                memory    - Amount of memory on video card.
  172. *                mode    - Video mode to check
  173. * Returns:        Number of available video pages for the mode, -1 on error.
  174. *
  175. * Description:    Determines the number of available video pages for a
  176. *                specific video mode and driver. This routine assumes that
  177. *                the MGL_detectGraph() routine has already been called
  178. *                to obtain the video device driver ID.
  179. *
  180. *                If the video mode specified is invalid, a -1 is returned.
  181. *
  182. ****************************************************************************/
  183. {
  184.     int        *modes;
  185.     long    pagesize;
  186.  
  187.     /* Get list of available video modes and check that the mode specified
  188.      * is currently valid
  189.      */
  190.  
  191.     modes = MGL_availableModes(driver,memory);
  192.  
  193.     while (*modes != -1) {
  194.         if (mode == *modes)
  195.             break;
  196.         modes++;
  197.         }
  198.     if (*modes == -1)
  199.         return -1;
  200.  
  201.     switch(driver) {
  202.         case grMCGA:
  203.             return 1;
  204.         case grEGA:
  205.         case grVGA:
  206.             switch (mode) {
  207.                 case grEGA_320x200x16:
  208.                     return 8;
  209.                 case grEGA_640x200x16:
  210.                     return 4;
  211.                 case grEGA_640x350x16:
  212.                     return 2;
  213.                 case grVGA_640x400x16:
  214.                     return 2;
  215.                 case grVGA_640x480x16:
  216.                     return 1;
  217.                 case grVGA_320x200x256:
  218.                     return 1;
  219.                 }
  220.             return -1;
  221.         default:
  222.             if (driver >= __FIRST_SVGA && driver <= __LAST_SVGA) {
  223.                 /* We have a Super VGA video card. We simply call the
  224.                  * assembly language routine to compute the number
  225.                  * of video pages.
  226.                  */
  227.  
  228.                 return _getSuperVGAPages(mode,memory,&pagesize);
  229.                 }
  230.             else {
  231.                 /* No video modes are supported for this adapter */
  232.  
  233.                 return -1;
  234.                 }
  235.         }
  236. }
  237.