home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / mgl11 / demo / main.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-09  |  5.1 KB  |  180 lines

  1. /****************************************************************************
  2. *
  3. *                    Demo - Demonstration Program for the
  4. *                        MegaGraph Graphics Library
  5. *
  6. *                    Copyright (C) 1994 SciTech Software.
  7. *                            All rights reserved.
  8. *
  9. * Filename:        $RCSfile: main.cpp $
  10. * Version:        $Revision: 1.2 $
  11. *
  12. * Language:        C++ 3.0
  13. * Environment:    any
  14. *
  15. * Description:    Main program code for the demo program. This _must_ not be
  16. *                compiled with anything but normal 8086 instructions, since
  17. *                it must be able to detect an incorrect processor
  18. *                configuration!
  19. *
  20. * $Id: main.cpp 1.2 1994/03/09 11:29:38 kjb release $
  21. *
  22. ****************************************************************************/
  23.  
  24. #include "demo.hpp"
  25.  
  26. #pragma    hdrstop
  27.  
  28. #include <ctype.h>
  29. #include "sysinfo.h"
  30. #include "getopt.h"
  31.  
  32. /*------------------------------ Implementation ---------------------------*/
  33.  
  34. #include <alloc.h>
  35.  
  36. void badHeap(void)
  37. {
  38.     MGL_exit();
  39.     cerr << "Heap corrupted\n";
  40.     exit(1);
  41. }
  42.  
  43. void checkHeap(void)
  44. {
  45.     if (heapcheck() == _HEAPCORRUPT)
  46.         badHeap();
  47. }
  48.  
  49. #pragma option -1-                // Compile _only_ for 8086 operation!!
  50.  
  51. void checkHardware(void)
  52. /****************************************************************************
  53. *
  54. * Function:        checkHardware
  55. *
  56. * Description:    Checks the hardware for compatibility, bombing out if
  57. *                it is incompatible. This module should not be compiled
  58. *                with any 286 or better instructions!
  59. *
  60. ****************************************************************************/
  61. {
  62.     // Check to see that the processor is approriate!!
  63.  
  64.     cpu_type cpu = SYS_cpu();
  65.     if (cpu < cpu_386) {
  66.         cerr << "This machine has an '";
  67.         switch (cpu) {
  68.             case cpu_86:    cerr << "8086";        break;
  69.             case cpu_286:
  70.             case cpu_286p:    cerr << "80286";    break;
  71.             default:
  72.                 cerr << "Misidentified CPU - report this!\n";
  73.                 break;
  74.             }
  75.         cerr << "' microprocessor, but this program requires\n"
  76.              << "an i386 or better to operate.\n";
  77.         exit(EXIT_FAILURE);
  78.         }
  79.  
  80. #ifndef    FIXED_POINT
  81.  
  82.     fpu_type fpu = SYS_fpu();
  83.     if (fpu == fpu_none) {
  84.         cerr << "This program requires a floating point co-processor (287,387,487)\n";
  85.         cerr << "to operate effectively. Without a floating point co-processor you\n";
  86.         cerr << "must use the fixed point version of the program.\n\n";
  87.         exit(EXIT_FAILURE);
  88.         }
  89.  
  90. #endif
  91. }
  92.  
  93. void help(void)
  94. /****************************************************************************
  95. *
  96. * Function:        help
  97. *
  98. * Description:    Provide usage information about the program.
  99. *
  100. ****************************************************************************/
  101. {
  102.     cerr << "Usage: demo [-ega|vga|vesa] [-hfbsp]\n\n";
  103.     cerr << "-ega    Use the standard EGA device drivers\n";
  104.     cerr << "-vga    Use the standard VGA device drivers\n";
  105.     cerr << "-vesa   Use the standard VESA VBE device drivers. By default the system will\n";
  106.     cerr << "        try to use the accelerated drivers.\n";
  107.     cerr << "-f      Turn off special SuperVGA performance enhancements.\n";
  108.     cerr << "-b      Program the palette via the BIOS (XGA and Non VGA style SuperVGA's).\n";
  109.     cerr << "-s      Use slower palette routines for VLB compatability.\n";
  110.     cerr << "-p<arg> Set the palette snow level factor (defaults to 100).\n";
  111.     cerr << "-h      Provide this usage information.\n\n";
  112.     cerr << "If you have a VESA VLB Local Bus based video card, the palette may not be\n";
  113.     cerr << "programmed correctly. In this case, try using the -s option to slow down the\n";
  114.     cerr << "palette programming routines, or the -b option to use the BIOS. You will need\n";
  115.     cerr << "to use the -b option if the video card is an XGA with the VESA VBE TSR\n";
  116.     cerr << "installed.\n\n";
  117.     cerr << "The -p option is used to set the number of palette entries programmed per\n";
  118.     cerr << "vertical retrace. You can speed up the palette programming by increasing this\n";
  119.     cerr << "value, but you may experience snow during palette rotations and fades. Decrease\n";
  120.     cerr << "the value if you experience snow during palette programming.\n\n";
  121.     exit(1);
  122. }
  123.  
  124. int main(int argc,char *argv[])
  125. {
  126.     int        option;
  127.     char    *argument;
  128.  
  129.     checkHardware();
  130.  
  131.     // Parse command line options
  132.  
  133.     do {
  134.         option = getopt(argc,argv,"Ee:Vv:FfBbSsPp:Hh",&argument);
  135.         if (option > 0) option = tolower(option);
  136.         switch(option) {
  137.             case 'e':
  138.                 forcedriver = grEGA;
  139.                 break;
  140.             case 'v':
  141.                 if (tolower(argument[0]) == 'g')
  142.                     forcedriver = grVGA;
  143.                 else if (tolower(argument[0]) == 'e')
  144.                     forcedriver = grSVGA;
  145.                 else help();
  146.                 break;
  147.             case 'f':
  148.                 MGL_slowSuperVGA(true);
  149.                 break;
  150.             case 'b':
  151.                 MGL_useBIOSPalette(true);
  152.                 break;
  153.             case 's':
  154.                 MGL_slowPalette(true);
  155.                 break;
  156.             case 'p':
  157.                 snowlevel = atoi(argument);
  158.                 break;
  159.             case PARAMETER:
  160.             case INVALID:
  161.             case 'h':
  162.                 help();
  163.             }
  164.         } while (option != ALLDONE);
  165.  
  166.     // Keep re-starting the application while we recieve the cmRestart
  167.     // command code. This allows the application to change video modes
  168.     // on the fly.
  169.  
  170.     ushort endState = cmRestart;
  171.     while (endState == cmRestart) {
  172.         checkHeap();
  173.         Demo *demo = new Demo;
  174.         endState = demo->run();
  175.         delete demo;
  176.         checkHeap();
  177.         }
  178.     return 0;
  179. }
  180.