home *** CD-ROM | disk | FTP | other *** search
- /*
- demomode.c
-
- ted 9/89
-
- C-scape 3.2 Example Program
- Copyright (c) 1990 by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- This program is a utility for managing the display modes accessible from
- the C-scape library. It detects the current mode, detects whether a given
- mode is supported by your display hardware, and sets the hardware to any
- supported mode that you specify.
-
- For instructions on how to use this program, see the message it prints out
- when you use the '-h' option: "demomode -h".
-
- This program relies only on the PC-specific portion of the Oakland
- Windowing Library (OWL). All the C-scape functions used by this program
- are declared in the header file "pcmode.h".
-
- Revision History:
- -----------------
- 10/17/90 ted fixed help options and text mode operation.
- 12/01/90 ted ansified function declarations of main() & showmode().
- 12/01/90 ted added tag name for enum.
- */
-
- static char cpyr[] = "Copyright (c) 1989, by Oakland Group, Inc.";
-
- /* Version number: */
- static char major = 1;
- static char minor = 0;
-
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
-
- #include "oak.h"
- #include "odisp.h"
- #include "pcmode.h"
-
- typedef enum _msgkind {
- SHOWMODE,
- GETMODE,
- SUPPORTED,
- NOTSUPPORTED,
- SUPPARGBAD,
- NOARG,
- HELP
- } msgkind;
-
- #define XMODE_NONE -1
- #define XMODE_GRAPHICS -2
- #define XMODE_TEXT -3
-
- /* Turbo C++ complains if main is prototyped */
- #ifndef TCP
- int main(int argc, char *argv[]);
- #endif
-
- int showmode(msgkind whichmsg);
-
- /* -------------------------------------------------------------------------- */
-
- int main(int argc, char *argv[])
- {
- int iarg, imode, i;
-
- iarg = 1;
-
- if (argc <= iarg) {
- return(showmode(NOARG)); /* Print the current mode, return 0 */
- }
- for (i = strlen(argv[iarg]); i > 0; i--) {
- argv[iarg][i-1] = tolower(argv[iarg][i-1]);
- }
- if (!strcmp(argv[iarg], "h") || !strcmp(argv[iarg], "-h") ||
- !strcmp(argv[iarg], "help") || !strcmp(argv[iarg], "-help") ||
- !strcmp(argv[iarg], "?") || !strcmp(argv[iarg], "-?")) {
- return(showmode(HELP)); /* Print out the help stuff */
- }
- if (!strcmp(argv[iarg], "support") ||
- !strcmp(argv[iarg], "supp") ||
- !strcmp(argv[iarg], "s")) {
- iarg++;
- if (argc <= iarg) {
- return(showmode(SHOWMODE)); /* Print the current mode, return 0 */
- }
- for (i = strlen(argv[iarg]); i > 0; i--) argv[iarg][i-1] = tolower(argv[iarg][i-1]);
- }
- else if (!strcmp(argv[iarg], "current") ||
- !strcmp(argv[iarg], "curr")) {
- return(showmode(GETMODE)); /* Print the current mode, return mode # */
- }
-
- imode = XMODE_NONE;
- if (!strcmp(argv[iarg], "0")) { imode = 0; }
- else if (!strcmp(argv[iarg], "1")) { imode = 1; }
- else if (!strcmp(argv[iarg], "2")) { imode = 2; }
- else if (!strcmp(argv[iarg], "3")) { imode = 3; }
- else if (!strcmp(argv[iarg], "4")) { imode = 4; }
- else if (!strcmp(argv[iarg], "5")) { imode = 5; }
- else if (!strcmp(argv[iarg], "6")) { imode = 6; }
- else if (!strcmp(argv[iarg], "7")) { imode = 7; }
- else if (!strcmp(argv[iarg], "d")) { imode = 13; }
- else if (!strcmp(argv[iarg], "e")) { imode = 14; }
- else if (!strcmp(argv[iarg], "f")) { imode = 15; }
- else if (!strcmp(argv[iarg], "10")) { imode = 16; }
- else if (!strcmp(argv[iarg], "11")) { imode = 17; }
- else if (!strcmp(argv[iarg], "12")) { imode = 18; }
- else if (!strcmp(argv[iarg], "13")) { imode = 19; }
- else if (!strcmp(argv[iarg], "13")) { imode = 19; }
- else if (!strcmp(argv[iarg], "g")) { imode = XMODE_GRAPHICS; }
- else if (!strcmp(argv[iarg], "graphics")){ imode = XMODE_GRAPHICS; }
- else if (!strcmp(argv[iarg], "t")) { imode = XMODE_TEXT; }
- else if (!strcmp(argv[iarg], "text")) { imode = XMODE_TEXT; }
- else if (!strcmp(argv[iarg], "h")) { imode = PCMODE_HERC0; }
- else if (!strcmp(argv[iarg], "h0")) { imode = PCMODE_HERC0; }
- else if (!strcmp(argv[iarg], "herc")) { imode = PCMODE_HERC0; }
- else if (!strcmp(argv[iarg], "herc0")) { imode = PCMODE_HERC0; }
- else if (!strcmp(argv[iarg], "h1")) { imode = PCMODE_HERC1; }
- else if (!strcmp(argv[iarg], "herc1")) { imode = PCMODE_HERC1; }
- else if (!strcmp(argv[iarg], "c")) { imode = PCMODE_CPQ40; }
- else if (!strcmp(argv[iarg], "compaq")) { imode = PCMODE_CPQ40; }
- else if (!strcmp(argv[iarg], "43")) { imode = PCMODE_EGA43; }
- else if (!strcmp(argv[iarg], "ega43")) { imode = PCMODE_EGA43; }
- else if (!strcmp(argv[iarg], "43line")) { imode = PCMODE_EGA43; }
- else if (!strcmp(argv[iarg], "50")) { imode = PCMODE_VGA50; }
- else if (!strcmp(argv[iarg], "vga50")) { imode = PCMODE_VGA50; }
- else if (!strcmp(argv[iarg], "50line")) { imode = PCMODE_VGA50; }
-
- switch (imode) {
- case XMODE_NONE:
- return(showmode(HELP)); /* Print out the help stuff */
- default:
- if (pc_ModeSupport(imode)) {
- if (iarg == 1) pc_SetMode(imode);
- }
- else return(showmode(NOTSUPPORTED)); /* Print the mode-not-supported msg */
- break;
- case XMODE_GRAPHICS: /* Graphics */
- if (iarg == 1) {
- if (!pc_SetModeGraphics()) return(showmode(NOTSUPPORTED)); /* Print the mode-not-supported msg */
- }
- else return(showmode(SUPPARGBAD)); /* Print the bad-support-arg msg */
- break;
- case XMODE_TEXT: /* Text */
- if (iarg == 1) {
- imode = pc_GetMode();
- if (imode > 0x03 && imode != 0x07) {
- if (pc_ModeSupport(3)) {
- pc_SetMode(3);
- }
- else if (pc_ModeSupport(7)) {
- pc_SetMode(7);
- }
- }
- }
- break;
- }
- if (iarg == 1) return(showmode(SHOWMODE)); /* New mode set; print it out */
- else return(showmode(SUPPORTED)); /* Print mode supported message */
- }
- /* -------------------------------------------------------------------------- */
-
- int showmode(msgkind whichmsg)
- {
- int currmode;
-
- printf("The Oakland PC video mode selector/detector utility, Version %d.%d\n", major, minor);
- printf("%s\n", cpyr);
-
- switch (whichmsg) {
- case SUPPORTED:
- printf("The mode you specified is supported by your hardware.\n");
- break;
- case NOTSUPPORTED:
- printf("The video mode you selected is not supported by your hardware.\n");
- break;
- case SUPPARGBAD:
- printf("You must give a specific mode to find out if it's supported.\n");
- break;
- case NOARG:
- printf("Use the '-h' option for a list of all options: \"demomode -h\".\n");
- break;
- case HELP:
- printf("Usage: demomode [current | [support] <mode spec>]\n");
- printf(" demomode <mode spec> : Set the mode to the one specified\n");
- printf(" demomode support <mode spec> : Say whether the specified mode is supported\n");
- printf(" demomode current : Display the current mode, set errorlevel to it\n");
- printf("Mode specs recognized:\n");
- printf(" 0,1,2,3 : IBM CGA compatible text modes.\n");
- printf(" 4,5,6 : IBM CGA compatible graphics modes.\n");
- printf(" 7 : IBM compatible monochrome text mode.\n");
- printf(" D,E,F,10 : IBM EGA compatible graphics modes.\n");
- printf(" 11,12,13 : IBM VGA compatible graphics modes.\n");
- printf(" herc,herc0 : Hercules compatible graphics mode, page 0.\n");
- printf(" herc1 : Hercules compatible graphics mode, page 1.\n");
- printf(" ega43,43 : EGA compatible 43 line text mode.\n");
- printf(" vga50,50 : EGA compatible 50 line text mode.\n");
- printf(" compaq,c : ATT/Compaq compatible 640x400 graphics mode.\n\n");
- printf("On return, the DOS errorlevel is set to 0, except if the 'support'\n");
- printf(" parameter was given and the specified mode was not supported,\n");
- printf(" or if the 'current' parameter was given, in which case\n");
- printf(" the errorlevel is set to the number of the current graphics mode.\n");
- break;
- }
-
- printf("The current mode is ");
-
- currmode = pc_GetMode();
- switch(currmode) {
- case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
- printf("mode %d.", currmode);
- break;
- case 0xD: case 0xE: case 0xF: case 0x10: case 0x11: case 0x12: case 0x13:
- printf("mode hex %x.", currmode);
- break;
- case PCMODE_EGA43:
- printf("EGA 43 line text mode.");
- case PCMODE_VGA50:
- printf("VGA 50 line text mode.");
- break;
- case PCMODE_CPQ40:
- printf("Compaq/ATT 640x400 graphics mode.");
- break;
- case PCMODE_HERC0:
- printf("Hercules Graphics mode, page 0.");
- break;
- case PCMODE_HERC1:
- printf("Hercules Graphics mode, page 1.");
- break;
- default:
- printf("unrecognized.");
- break;
- }
- switch (whichmsg) {
- case GETMODE:
- printf("\nSetting DOS errorlevel to mode # : %d", currmode);
- return(currmode);
- case SHOWMODE:
- case SUPPORTED:
- case HELP:
- default:
- return(0);
- case NOTSUPPORTED:
- case SUPPARGBAD:
- return(1);
- }
- }
- /* -------------------------------------------------------------------------- */
-
-