home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / SVGALIB / SVGALIB1.TAR / svgalib / src / vgamodesel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-17  |  1.9 KB  |  83 lines

  1. /* VGAlib version 1.2 - (c) 1993 Tommy Frandsen            */
  2. /*                                   */
  3. /* This library is free software; you can redistribute it and/or   */
  4. /* modify it without any restrictions. This library is distributed */
  5. /* in the hope that it will be useful, but without any warranty.   */
  6.  
  7. /* Multi-chipset support Copyright 1993 Harm Hanemaayer */
  8. /* partially copyrighted (C) 1993 by Hartmut Schirmer */
  9.  
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13.  
  14. #include "vga.h"
  15. #include "libvga.h"
  16.  
  17.  
  18. #define MODENAME_LENGTH 20
  19.  
  20.  
  21. /* This one won't type an error message ... */
  22. int __vga_name2number( char *m)
  23. {
  24.     int i;
  25.  
  26.     for (i = G320x200x16; i <= GLASTMODE; i++) {
  27.         if (strcasecmp(m, vga_getmodename(i)) == 0)    /* check name */
  28.             return i;
  29.     }
  30.     return -1;
  31. }
  32.  
  33. int vga_getmodenumber( char *m ) {
  34.     int i;
  35.     char s[3];
  36.  
  37.     __vga_getchipset(); /* Do initialisation first */
  38.     i = __vga_name2number(m);
  39.     if (i>0)
  40.         return i;
  41.  
  42.     for (i = G320x200x16; i <= GLASTMODE; i++) {
  43.         sprintf(s, "%d", i);
  44.         if (strcmp(m, s) == 0)            /* check number */
  45.             return i;
  46.     }
  47.     if (strcmp(m, "PROMPT") == 0)
  48.         return -1;
  49.     printf("Invalid graphics mode in environment variable.\n");
  50.     return -1;
  51. }
  52.  
  53. char *vga_getmodename( int m ) {
  54.     static char modename[MODENAME_LENGTH];
  55.     int x, y, c;
  56.  
  57.     if (m <= TEXT || m > GLASTMODE) 
  58.       return "";
  59.     x = __svgalib_infotable[m].xdim;
  60.     y = __svgalib_infotable[m].ydim;
  61.     switch (c = __svgalib_infotable[m].colors) {
  62.       case 1<<15: sprintf(modename, "G%dx%dx32K", x, y); break;
  63.       case 1<<16: sprintf(modename, "G%dx%dx64K", x, y); break;
  64.       case 1<<24: sprintf(modename, (__svgalib_infotable[m].bytesperpixel==3)?
  65.                         "G%dx%dx16M":"G%dx%dx16M32", x, y); break;
  66.       default   : sprintf(modename, "G%dx%dx%d", x, y, c); break;
  67.     }
  68.     return modename;
  69. }
  70.  
  71. int vga_getdefaultmode(void) {
  72.     char *e;
  73.     int m;
  74.     e = getenv("GSVGAMODE");
  75.     if (e != NULL && strcmp(e, "") != 0) {
  76.         m = vga_getmodenumber(e);
  77.         if (m != -1)
  78.             return m;
  79.     }
  80.     return -1;
  81. }
  82.  
  83.