home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / prog-asm / talincod.lha / talincode.lha / getdisplay.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-23  |  2.2 KB  |  97 lines

  1. /*=========================================================================*
  2.  
  3.  GetModeIDByName.c - given a display name, return its mode ID of INVALID_ID
  4.  
  5.            Placed in the public domain by Sylvan Technical Arts
  6.                               Use at your own risk.
  7.  *=========================================================================*/
  8.  
  9. #include <graphics/displayinfo.h>
  10.  
  11. extern struct Library    *GfxBase;
  12.  
  13. /*    This is a list of mode names that are acceptable, although they may
  14.     not be in the display database.                                            */
  15.  
  16. struct ExtraModes {
  17.     LONG    ModeID;
  18.     char    *Name;
  19. };
  20.  
  21. struct ExtraModes extra_modes[] = {
  22.     LORES_KEY,        "Lores",
  23.     HIRES_KEY,        "Hires",
  24.     SUPER_KEY,        "SuperHires",
  25.     LORESLACE_KEY,    "Lores-Interlaced",
  26.     HIRESLACE_KEY,    "Hires-Interlaced",
  27.     SUPERLACE_KEY,    "SuperHires-Interlaced"
  28. };
  29.     
  30. /*    This is routne that does the work...                                    */
  31.  
  32. LONG GetModeIDByName(char *name)
  33. {
  34.     DisplayInfoHandle    handle;
  35.     struct NameInfo        nameinfo;
  36.     struct DisplayInfo    dispinfo;
  37.     LONG                theID = INVALID_ID;
  38.     WORD                i;
  39.  
  40.     while ( (theID = NextDisplayInfo(theID)) != INVALID_ID )
  41.     {
  42.         if (handle = FindDisplayInfo(theID))
  43.         {
  44.             if ( GetDisplayInfoData(handle, (void *)&nameinfo, sizeof nameinfo,
  45.                 DTAG_NAME, NULL) )
  46.             {
  47.                 if (!str_cmpi(nameinfo.Name,name))
  48.                 {
  49.                     if ( GetDisplayInfoData(handle,(void *)&dispinfo,
  50.                         sizeof dispinfo,DTAG_DISP, NULL) )
  51.                     {
  52.                         return (dispinfo.NotAvailable ? INVALID_ID : theID);
  53.                     }
  54.                 }
  55.             }
  56.         }
  57.     }
  58.  
  59.     for (i=0;i<sizeof extra_modes/sizeof (struct ExtraModes);i++)
  60.     {
  61.         if (!str_cmpi(extra_modes[i].Name,name))
  62.         {
  63.             if (handle = FindDisplayInfo(theID = extra_modes[i].ModeID))
  64.             {
  65.                 if ( GetDisplayInfoData(handle,(void *)&dispinfo,
  66.                     sizeof dispinfo,DTAG_DISP, NULL) )
  67.                 {
  68.                     return (dispinfo.NotAvailable ? INVALID_ID : theID);
  69.                 }
  70.             }
  71.         }
  72.     }
  73.  
  74.     return INVALID_ID;
  75. }
  76.  
  77. /*    Here a test program for the above...                                    */
  78.  
  79. #if 0
  80. void main(int argc,char *argv[])
  81. {    LONG    id;
  82.  
  83.     if ( (GfxBase = OpenLibrary("graphics.library",36L)) == NULL ) exit(0);
  84.  
  85.     if (argc > 1)
  86.     {
  87.         id = GetModeIDByName(argv[1]);
  88.         if (id == INVALID_ID) printf("The ID is invalid on this system.\n");
  89.         else printf("The ID for this mode is %08lx.\n",id);
  90.     }
  91.  
  92.     CloseLibrary(GfxBase);
  93.  
  94.     exit (0);
  95. }
  96. #endif
  97.