/* %kw # %v %n %d %t # */ /* Version # 4 METFIND.C 26-Jul-94 10:58:44 # */ /* ***************************************************************** * * METFIND.C - Procedures to find best display or mouse to use * * Copyright (c) 1994 Metagraphics Software Corporation * * ***************************************************************** * This file contains functions to help your application decide which display mode would be best considering the hardware the user has installed. This file may be #included by your app, or you can compile it and link it in separately. Functions supplied: int FindBestDisplay( int maxx, int maxy, long maxclr ) Finds the best display mode that doesn't exceed the passed parameters. int FindUserDisplay( int argc, char *argv[] ) Finds the display mode specified by the user on the command line or environment variable METAPARM if any. char* FindDisplayInfo( int num, int *xres, int *yres, long *clrs ) Returns descriptive information about a display mode. int FindBestMouse( ) Finds the best input device available. =========================================================================== */ #ifndef cMET /* If compiled separately, not "included" */ #include "metawndo.h" /* master MetaWINDOW include file */ #endif #include "string.h" #include "ctype.h" /* determine if running 32 bit compiler */ #ifdef MetawareC #define __386__ /* already defined for Watcom C 386 */ #endif /* device data type */ typedef struct _device { int num; /* InitGraphics mode number */ int hres; /* horizontal resolution */ int vres; /* vertical resolution */ long colors; /* maxium number of colors */ int id; /* id number */ char *slash; /* command line code */ } device; /* device ID codes */ #define s8514 0 #define sS3 1 #define sHerc 2 #define sCGA 3 #define sEGA 4 #define sVGA 5 #define sSVGA 6 #define sVESA 7 #define sMISC 8 /* output device table */ device o_dev[] = { /* =============== check for accelerated cards first ============== */ /* IBM 8514 */ { V8514A1024x768x8I,1024, 768, 256, s8514, "ve:53" }, /* S3 = HP Ultra VGA, Diamond Stealth, Orchid Fahrenheit, and others */ { S3I640x480X, 640, 480, 256, sS3, "s3:10" }, { S3I800x600X, 800, 600, 256, sS3, "s3:11" }, { S3I1024x768X, 1024, 768, 256, sS3, "s3:12" }, /* ATI Graphics Ultra Pro */ { ATIUP640x480X, 640, 480, 256, s8514, "ai:50" }, { ATIUP800x600X, 800, 600, 256, s8514, "ai:51" }, { ATIUP1024x768X, 1024, 768, 256, s8514, "ai:52" }, { ATIUP1280x1024X, 1280, 1024, 256, s8514, "ai:53" }, /* =============== check for standard modes ============== */ /* HERCULES */ { HER720x348, 720, 348, 2, sHerc, "h:1" }, /* CGA */ { CGA640x200, 640, 200, 2, sCGA, "i:1" }, /* EGA */ { EGA320x200, 320, 200, 16, sEGA, "i:10" }, { EGA640x200, 640, 200, 16, sEGA, "i:11" }, { EGA640x350, 640, 350, 16, sEGA, "i:12" }, { EGAMono, 640, 350, 2, sEGA, "i:13" }, { EGA640x3502, 640, 350, 2, sEGA, "f:41" }, /* VGA */ { VGA320x200, 320, 200, 16, sVGA, "i:20" }, { VGA640x200, 640, 200, 16, sVGA, "i:21" }, { VGA640x350, 640, 350, 16, sVGA, "i:22" }, { VGA640x480, 640, 480, 16, sVGA, "i:23" }, { VGA640x4802, 640, 480, 2, sVGA, "i:24" }, { VGA320x200X, 320, 200, 256, sVGA, "i:25" }, /* =============== check for VESA standard modes ============== */ /* VESA super VGA */ { VESA800x600, 800, 600, 16, sVESA, "ve:20"}, { VESA1024x768, 1024, 768, 16, sVESA, "ve:21"}, { VESA640x480X, 640, 480, 256, sVESA, "ve:31"}, { VESA800x600X, 800, 600, 256, sVESA, "ve:32"}, { VESA1024x768X, 1024, 768, 256, sVESA, "ve:33"}, { VESA1280x1024X, 1280, 1024, 256, sVESA, "ve:34"}, { VESA640x480Y, 640, 480, 32767,sVESA, "ve:40"}, { VESA640x480YY, 640, 480, 65535L,sVESA, "ve:41"}, { VESA800x600Y, 800, 600, 32767 ,sVESA, "ve:42"}, { VESA800x600YY, 800, 600, 65535L,sVESA, "ve:43"}, { VESA1024x768Y, 1024, 768, 32767 ,sVESA, "ve:44"}, { VESA1024x768YY, 1024, 768, 65535L,sVESA, "ve:45"}, { VESA1280x1024Y, 1280, 1024, 32767 ,sVESA, "ve:46"}, { VESA1280x1024YY, 1280, 1024, 65535L,sVESA, "ve:47"}, { VESA640x480Z, 640, 480, 16777216L,sVESA,"ve:71"}, { VESA800x600Z, 800, 600, 16777216L,sVESA,"ve:72"}, /* =============== check for vendor specific modes ============== */ /* ATI */ { ATI800x600, 800, 600, 16, sSVGA, "ai:20" }, /* Wonder */ { ATI1024x768, 1024, 768, 16, sSVGA, "ai:21" }, /* Wonder+ */ { ATI640x480X, 640, 480, 256, sSVGA, "ai:30" }, /* Wonder */ { ATI800x600X, 800, 600, 256, sSVGA, "ai:31" }, /* Wonder XL */ { ATI1024x768X, 1024, 768, 256, sSVGA, "ai:32" }, /* Wonder XL */ { ATI640x480Y, 640, 480, 32767,sSVGA, "ai:40" }, /* Wonder XL */ /* ATT */ { DEB640x200, 640, 200, 16, sMISC, "at:2" }, { DEB640x400, 640, 400, 16, sMISC, "at:3" }, /* COMPAQ */ { ATT640x400, 640, 400, 2, sMISC, "cp:1" }, /* Plasma */ { CPQ800x600, 800, 600, 16, sSVGA, "cp:10" }, /* Adv. VGA */ { CPQ640x480X, 640, 480, 256, sSVGA, "cp:11" }, /* Adv. VGA */ { CPQ1024x768X, 1024, 768, 256, sSVGA, "cp:12" }, /* QVision */ /* Tseng Labs 4000 */ /* Diamond Speedstar, Orchid Pro Designer II, STB VGA EM-16, and others */ { TS4800x600, 800, 600, 16, sSVGA, "ts:20" }, { TS41024x768, 1024, 768, 16, sSVGA, "ts:21" }, { TS4640x350X, 640, 350, 256, sSVGA, "ts:30" }, { TS4640x480X, 640, 480, 256, sSVGA, "ts:31" }, { TS4800x600X, 800, 600, 256, sSVGA, "ts:32" }, { TS41024x768X, 1024, 768, 256, sSVGA, "ts:34" }, { TS4640x480Y, 640, 480, 32767,sSVGA, "ts:40" }, { TS4800x600Y, 800, 600, 32767,sSVGA, "ts:41" }, /* EVEREX EVGA EV-673 */ { EVX800x600, 800, 600, 16, sSVGA, "ev:1" }, /* GENOA */ { GEN640x480, 640, 480, 16, sSVGA, "g:1"}, /* EGA 4880 */ { GEN800x600, 800, 600, 16, sSVGA, "g:2"}, /* EGA 4880 */ { GEN800x600V, 800, 600, 16, sSVGA, "g:3"}, /* VGA 5/6000 */ { GEN1024x768, 1024, 768, 16, sSVGA, "g:4"}, /* VGA 5000 */ { GEN640x350X, 640, 350, 256, sSVGA, "g:5"}, /* VGA 5000 */ { GEN640x480X, 640, 480, 256, sSVGA, "g:6"}, /* VGA 5000 */ { GEN61024x768, 1024, 768, 16, sSVGA, "g:7"}, /* VGA 6000 */ { GEN6640x480X, 640, 480, 256, sSVGA, "g:8"}, /* VGA 6000 */ /* Oak OTI-067 chipset */ { OAK800x600, 800, 600, 16, sSVGA, "ok:1" }, { OAK1024x768, 1024, 768, 16, sSVGA, "ok:2" }, { OAK640x480X, 640, 480, 256, sSVGA, "ok:3" }, /* Orchid Designer, STB Extra/EM, Quadram VGA Spectra */ { STB800x600, 800, 600, 16, sSVGA, "st:20" }, { STB1024x768, 1024, 768, 16, sSVGA, "st:21" }, { STB640x350X, 640, 350, 256, sSVGA, "st:30" }, { STB640x480X, 640, 480, 256, sSVGA, "st:31" }, /* Paradise */ { PAR640x480, 640, 480, 16, sSVGA, "p:1" }, { PAR800x600, 800, 600, 16, sSVGA, "p:2" }, { PAR1024x768, 1024, 768, 16, sSVGA, "p:3" }, { PAR640x480X, 640, 480, 256, sSVGA, "p:4" }, /* TECMAR VGA/AD */ { TEC800x600, 800, 600, 16, sSVGA, "tc:1" }, { TEC1024x768, 1024, 768, 16, sSVGA, "tc:2" }, { TEC640x350X, 640, 350, 256, sSVGA, "tc:3" }, { TEC640x480X, 640, 480, 256, sSVGA, "tc:4" }, /* Toshiba 3100 */ { TOS640x400, 640, 400, 2, sMISC, "to:1" }, /* Trident Impact */ { TRI800x600, 800, 600, 16, sSVGA, "tr:1" }, { TRI1024x768, 1024, 768, 16, sSVGA, "tr:2" }, { TRI640x480X, 640, 480, 256, sSVGA, "tr:3" }, { TRI800x600X, 800, 600, 256, sSVGA, "tr:4" }, { TRI1024x768X, 1024, 768, 256, sSVGA, "tr:5" }, /* Video 7 */ { V7800x600, 800, 600, 16, sSVGA, "v7:6"}, { V7640x480X, 640, 480, 256, sSVGA, "v7:7"}, { V71024x768, 1024, 768, 16, sSVGA, "v7:8"}, { V71024x768x2, 1024, 768, 2, sSVGA, "v7:9"}, { V72640x480X, 640, 480, 256, sSVGA, "v7:10"}, /* VRAM II */ { V72800x600X, 800, 600, 256, sSVGA, "v7:11"}, /* VRAM II */ { V721024x768X, 1024, 768, 256, sSVGA, "v7:12"}, /* VRAM II */ { 0, 0, 0, 0, sMISC, "" } }; /* The last entry should always be 0, no device located */ /* These 386 libs have the additional driver packages linked in */ /* others require driver files that the user may not have */ #ifdef MetawareC #define LinkedDrivers #endif #ifdef WatcomC #define LinkedDrivers #endif int FindBestDisplay( int maxx, int maxy, long maxclr ) /* Find the best display not exceeding the requested dimensions or colors Returns an InitGraphics display code */ { int i, hicolor, accel; device best; dirRec drvDir; #ifdef LinkedDrivers accel = hicolor = True; #else /* do they have metaccel or methicolor drivers ? */ accel = ResrcQuery( "METWND07.D??", &drvDir, 1); hicolor = ResrcQuery( "METWND09.D??", &drvDir, 1); #endif best.num = best.hres = best.vres = 0; best.colors = 0L; /* for each device in the table */ for( i = 0; o_dev[i].num; i++ ) { /* is it beyond our requirements ? */ if( o_dev[i].hres > maxx ) continue; /* yes */ if( o_dev[i].vres > maxy ) continue; /* yes */ if( o_dev[i].colors > maxclr ) continue; /* yes */ /* is driver present ? */ if( o_dev[i].id == s8514 || o_dev[i].id == sS3 ) if( !accel ) continue; /* nope */ if( o_dev[i].colors > 256 ) if( !hicolor ) continue; /* nope */ /* is card present ? */ if( QueryGraphics( o_dev[i].num ) ) continue; /* nope */ /* re-arrange the order of these tests if you wish the weightings other than colors - vertical - horizontal */ /* does it have the best color resolution so far ? */ if( o_dev[i].colors < best.colors ) continue; /* nope */ if( o_dev[i].colors > best.colors ) best = o_dev[i]; /* does it have the best vertical resolution so far ? */ if( o_dev[i].vres < best.vres ) continue; /* nope */ if( o_dev[i].vres > best.vres ) best = o_dev[i]; /* does it have the best horizontal resolution so far ? */ if( o_dev[i].hres < best.hres ) continue; /* nope */ if( o_dev[i].hres > best.hres ) best = o_dev[i]; } return best.num; } char * FindDisplayInfo( int num, int *xres, int *yres, long *clrs ) /* Return info on display type 'num' */ { int i; static char *stringtable[] = { "8514", "S3", "Hercules", "CGA", "EGA", "VGA", "Super VGA", "VESA", "" }; /* for each device in the table */ for( i = 0; o_dev[i].num; i++ ) { /* is it the num were after ? */ if( o_dev[i].num == num ) break; /* yes */ } *xres = o_dev[i].hres; *yres = o_dev[i].vres; *clrs = o_dev[i].colors; return (stringtable[ o_dev[i].id ] ); } int FindUserDisplay( int argc, char *argv[] ) /* Parse the command line or METAPARM environment variable for options. */ { int i, choice; char *p, *s, *d; char line[256]; line[0] = '\0'; /* concatenate command line args */ for( i = 1; argc > 1; argc-- ) strcat( line, argv[i++] ); /* is there a command line choice ? */ choice = False; p = line; while( *p ) { if( *p == '-' || *p == '/' ) choice = True; p++; } /* if no cmd line , is there an environment var? */ if( !choice ) { p = getenv("METAPARM"); if( p ) strcpy( line, p ); } /* force to lower case, remove spaces */ p = s = line; while( *s ) { *p = tolower( *s ); if( *p != ' ' ) p++; s++; } *p = '\0'; /* process each option on the line */ choice = 0; p = line; while( *p ) { /* scan for a '/' and/or '-' */ while( *p && ! ( *p == '/' || *p == '-' ) ) p++; if( *p == '\0' ) break; /* table look up for each output device */ for( i = 0; o_dev[i].num; i++) { s = o_dev[i].slash; /* s is the device in list to check against */ d = p + 1; /* d is the requested device to look for */ if( ! strcmp(s,d) ) { /* when 0, we matched */ choice = o_dev[i].num; break; } } p++; } /* end of while( *p ) */ return choice; } /* input device table */ int i_dev[] = { { MsDriver }, /* Mouse driver */ { MsCOM1 }, /* Microsoft mouse, COM1 */ { MsCOM2 }, /* Microsoft mouse, COM2 */ { MoCOM1 }, /* Logitech/Mouse Systems mouse, COM1 */ { MoCOM2 }, /* Logitech/Mouse Systems mouse, COM2 */ { JoyStick }, /* Joystick on game port */ { 0 }, }; /* The last entry should always be 0 , no device located */ int FindBestMouse( ) { int i; /* for each device in the table */ for( i = 0; i_dev[i]; i++ ) { /* is it present ? */ if( QueryMouse( i_dev[i] ) == 0 ) return i_dev[i]; } /* no mouse present */ return 0; } /* End of File - METFIND.C */