home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / fgl / fglight / manuals.arj / USER03.DOC < prev    next >
Text File  |  1995-02-06  |  40KB  |  859 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. Chapter 3
  8.  
  9.  
  10.  
  11.  
  12.  
  13. Initializing the
  14. Video Environment                                                              
  15. 42   Fastgraph User's Guide
  16.  
  17.  
  18. Overview
  19.  
  20.      Before Fastgraph can perform any text or graphics video operations, you
  21. must select a video mode in which your program will run. An important part of
  22. this selection depends on whether your program will run in a text mode, a
  23. graphics mode, or both. The first two sections in this chapter discuss the
  24. necessary video initialization for standard text and graphics modes, while the
  25. last section addresses the additional setup needed for SuperVGA (SVGA)
  26. graphics modes.
  27.  
  28.  
  29. Establishing a Text Mode
  30.  
  31.      When you write a program that only uses text modes, you must determine if
  32. the program will run on monochrome systems, color systems, or both. In
  33. general, there is no reason to exclude one type of system, because the
  34. additional programming required to support both is rather trivial.
  35.  
  36.      The Fastgraph routine fg_setmode establishes a video mode and initializes
  37. Fastgraph's internal parameters for that mode. This routine has a single
  38. integer argument whose value is a video mode number between 0 and 29. Its
  39. value can also be -1, which tells Fastgraph to use the current video mode.
  40. Specifying an fg_setmode argument of -1 is often useful in programs that only
  41. use text video modes.
  42.  
  43.      When you establish a text video mode, the ROM BIOS text cursor is made
  44. visible, and this is often undesirable. The Fastgraph routine fg_cursor
  45. controls the visibility of the text cursor. The fg_cursor routine has a single
  46. integer argument that specifies the cursor visibility. If its value is 0, the
  47. cursor is made invisible; if its value is 1, the cursor is made visible.
  48.  
  49.      At this point, an example may help clarify things. We'll start with a
  50. variation of Kernighan and Ritchie's famous "Hello, world" program that shows
  51. how to initialize Fastgraph for the 80-column color text mode (mode 3) and
  52. turn off the text mode cursor. It uses two Fastgraph routines that we have not
  53. yet discussed, fg_setcolor and fg_text. For now, it should suffice to know
  54. that fg_setcolor(15) makes subsequent text appear in white, and fg_text
  55. displays the characters passed to it.
  56.  
  57.                                  Example 3-1.
  58.  
  59.                         #include <fastgraf.h>
  60.                         void main(void);
  61.  
  62.                         void main()
  63.                         {
  64.                            fg_initpm();
  65.                            fg_setmode(3);
  66.                            fg_cursor(0);
  67.  
  68.                            fg_setcolor(15);
  69.                            fg_text("Hello, world.",13);
  70.                         }                                                      
  71.                            Chapter 3:  Initializing the Video Environment   43
  72.  
  73.      If you run example 3-1, notice the text displayed by the program appears
  74. in the upper left corner of the screen. On the line below this, the DOS prompt
  75. appears, waiting for your next DOS command. Furthermore, if your system uses
  76. the ANSI.SYS driver to set screen attributes (such as with Norton's SA
  77. program), you should also notice only the DOS prompt appears in the colors
  78. defined by the screen attributes -- the rest of the screen is blank.
  79.  
  80.      A more graceful return to DOS is needed. In example 3-2, we'll use the
  81. Fastgraph routine fg_reset. This routine erases the screen, and if the
  82. ANSI.SYS driver is loaded, fg_reset also restores any previously set screen
  83. attributes. We've also included a call to the Fastgraph routine fg_waitkey to
  84. wait for a keystroke before exiting. If we didn't do this, we would never see
  85. the program's output.
  86.  
  87.                                  Example 3-2.
  88.  
  89.                         #include <fastgraf.h>
  90.                         void main(void);
  91.  
  92.                         void main()
  93.                         {
  94.                            fg_initpm();
  95.                            fg_setmode(3);
  96.                            fg_cursor(0);
  97.  
  98.                            fg_setcolor(15);
  99.                            fg_text("Hello, world.",13);
  100.                            fg_waitkey();
  101.  
  102.                            fg_reset();
  103.                         }
  104.  
  105.  
  106.      Since examples 3-1 and 3-2 specifically use video mode 3, they would not
  107. work on a monochrome system. Ideally, we'd like to use fg_setmode(3) for color
  108. systems and fg_setmode(7) for monochrome systems. To do this, we need a way to
  109. determine whether the program is being run on a color system or on a
  110. monochrome system. The next example illustrates an easy way to do this.
  111.  
  112.      Example 3-3 uses the Fastgraph routine fg_testmode to determine if the
  113. user's system will support the video mode number specified as its first
  114. argument (the second argument is the number of video pages required, which
  115. will be 1 for all examples in this section). The fg_testmode routine returns a
  116. value of 1 (as its function value) if the requested video mode can be used,
  117. and it returns 0 if not. The program first sees if an 80-column color text
  118. mode is available (mode 3), and if so, it selects that mode. If the color mode
  119. is not available, it checks if the monochrome text mode is available (mode 7),
  120. and if so, it chooses the monochrome mode. If neither mode is available, then
  121. the program assumes the user's system has a 40-column display, issues a
  122. message stating the program requires an 80-column display, and then exits.
  123.  
  124.                                  Example 3-3.
  125.  
  126.                    #include <fastgraf.h>
  127.                    #include <stdio.h>
  128.                    #include <stdlib.h>                                         
  129. 44   Fastgraph User's Guide
  130.  
  131.                    void main(void);
  132.  
  133.                    void main()
  134.                    {
  135.                       int old_mode;
  136.  
  137.                       fg_initpm();
  138.                       old_mode = fg_getmode();
  139.  
  140.                       if (fg_testmode(3,1))
  141.                          fg_setmode(3);
  142.                       else if (fg_testmode(7,1))
  143.                          fg_setmode(7);
  144.                       else {
  145.                          printf("This program requires\n");
  146.                          printf("an 80-column display.\n");
  147.                          exit(1);
  148.                          }
  149.                       fg_cursor(0);
  150.  
  151.                       fg_setcolor(15);
  152.                       fg_text("Hello, world.",13);
  153.                       fg_waitkey();
  154.  
  155.                       fg_setmode(old_mode);
  156.                       fg_reset();
  157.                    }
  158.  
  159.  
  160.      Example 3-3 also illustrates another useful procedure. It is recommended,
  161. especially in graphics modes, to restore the original video mode and screen
  162. attributes before a program returns to DOS. We've already seen how the
  163. fg_reset routine restores the screen attributes, but how do we restore the
  164. original video mode? The Fastgraph routine fg_getmode returns the current
  165. video mode as its function value. If we call fg_getmode before calling
  166. fg_setmode, we can save the fg_getmode return value and pass it to fg_setmode
  167. just before the program exits.
  168.  
  169.      You also can use another Fastgraph routine, fg_bestmode, to determine if
  170. a video mode with a specific resolution is available on the user's system. The
  171. fg_bestmode routine requires three integer arguments: a horizontal resolution,
  172. a vertical resolution, and the number of video pages required. As its function
  173. value, fg_bestmode returns the video mode number that offers the most
  174. capabilities for the resolution and number of pages requested. It returns a
  175. value of -1 if no available video mode offers the requested criteria.
  176.  
  177.      For example, if we require an 80x25 text mode, we can use the function
  178. call fg_bestmode(80,25,1) to pick the "best" video mode available that offers
  179. this capability. In text modes, the term best means to give preference to a
  180. color text mode over a monochrome text mode. Example 3-4 performs the same
  181. function as example 3-3, but it uses fg_bestmode rather than fg_testmode.
  182.  
  183.                                  Example 3-4.
  184.  
  185.                    #include <fastgraf.h>
  186.                    #include <stdio.h>                                          
  187.                            Chapter 3:  Initializing the Video Environment   45
  188.  
  189.                    #include <stdlib.h>
  190.                    void main(void);
  191.  
  192.                    void main()
  193.                    {
  194.                       int old_mode;
  195.                       int new_mode;
  196.  
  197.                       fg_initpm();
  198.                       old_mode = fg_getmode();
  199.                       new_mode = fg_bestmode(80,25,1);
  200.  
  201.                       if (new_mode < 0) {
  202.                          printf("This program requires\n");
  203.                          printf("an 80-column display.\n");
  204.                          exit(1);
  205.                          }
  206.  
  207.                       fg_setmode(new_mode);
  208.                       fg_cursor(0);
  209.  
  210.                       fg_setcolor(15);
  211.                       fg_text("Hello, world.",13);
  212.                       fg_waitkey();
  213.  
  214.                       fg_setmode(old_mode);
  215.                       fg_reset();
  216.                    }
  217.  
  218.  
  219.  
  220. 43-line and 50-line Text Modes
  221.  
  222.      When using an 80-column text mode on a system equipped with an EGA, VGA,
  223. MCGA, or SVGA video display and adapter, you can extend the screen size from
  224. 25 lines to 43 or 50 lines. While all systems offer 25-line text modes, EGA
  225. systems also offer 43-line modes, MCGA systems also offer 50-line modes, and
  226. VGA and SVGA systems offer both 43-line and 50-line modes. The 43-line mode is
  227. not available on EGA systems equipped with an RGB display. If you extend the
  228. screen size to 43 or 50 lines, the physical character size is reduced
  229. proportionally so all lines appear on the screen.
  230.  
  231.      The fg_setlines routine defines the number of text rows per screen. It
  232. has a single integer argument whose value must be 25, 43, or 50. If you pass
  233. any other value to fg_setlines, or pass a value not supported by the host
  234. system's video configuration, fg_setlines does nothing. In addition, calling
  235. fg_setlines makes the text cursor visible. Another Fastgraph routine,
  236. fg_getlines, returns as its function value the number of text rows currently
  237. in effect. You also can use fg_getlines in graphics video modes.
  238.  
  239.      Example 3-5 illustrates the use of the fg_setlines and fg_getlines
  240. routines. The program first establishes the 80-column color text mode (this
  241. sets the screen size to its 25-line default) and makes the text cursor
  242. invisible. It then displays the words "first line" in the upper left corner of
  243. the screen. Next, the program checks if an EGA with enhanced display is
  244. available, and if so, changes the screen to 43 lines (video mode 16 is only    
  245. 46   Fastgraph User's Guide
  246.  
  247. available on EGA systems equipped with an enhanced display). Next, the program
  248. checks if a VGA, MCGA, or SVGA is available, and if so changes the screen to
  249. 50 lines (video mode 17 is only available on these systems). Finally, the
  250. program restores the original video mode, restores the number of lines per
  251. screen to its original setting, and restores the original screen attributes
  252. before exiting.
  253.  
  254.                                  Example 3-5.
  255.  
  256.                          #include <fastgraf.h>
  257.                          void main(void);
  258.  
  259.                          void main()
  260.                          {
  261.                             int lines;
  262.                             int old_lines;
  263.                             int old_mode;
  264.  
  265.                             fg_initpm();
  266.                             old_lines = fg_getlines();
  267.                             old_mode = fg_getmode();
  268.                             fg_setmode(3);
  269.                             fg_cursor(0);
  270.  
  271.                             fg_setcolor(15);
  272.                             fg_text("first line",10);
  273.                             fg_waitkey();
  274.  
  275.                             if (fg_testmode(16,0)) {
  276.                                fg_setlines(43);
  277.                                fg_cursor(0);
  278.                                fg_waitkey();
  279.                                }
  280.  
  281.                             if (fg_testmode(17,0)) {
  282.                                fg_setlines(50);
  283.                                fg_cursor(0);
  284.                                fg_waitkey();
  285.                                }
  286.  
  287.                             fg_setmode(old_mode);
  288.                             fg_setlines(old_lines);
  289.                             fg_reset();
  290.                          }
  291.  
  292.  
  293.  
  294. Establishing a Graphics Mode
  295.  
  296.      The steps for establishing a graphics mode are similar to establishing a
  297. text mode. However, there are more restrictions since some systems may not
  298. support all the graphics video modes. For example, a program could not run in
  299. mode 13 on a CGA system, nor could a program run in mode 9 on anything except
  300. a Tandy 1000 or PCjr system.                                                   
  301.                            Chapter 3:  Initializing the Video Environment   47
  302.  
  303.      For graphics programs, it may suffice to write a program to run in a
  304. specific video mode, but it is often more desirable to write a program that
  305. will run in any of several video modes. This is especially true for commercial
  306. products, since they should ideally run on as many different video
  307. configurations as possible.
  308.  
  309.      Fastgraph includes a routine named fg_automode that determines the
  310. graphics video mode that offers the most functionality for the user's video
  311. hardware configuration. For example, the Tandy 1000 series computers support
  312. all three CGA modes (4, 5, and 6) and the 320x200 16-color Tandy 1000 mode
  313. (9). Of these modes, mode 9 offers the most features from a graphics
  314. standpoint, so fg_automode will return a value of 9 when run on a Tandy 1000
  315. computer. The following table summarizes the video mode numbers returned by
  316. fg_automode for given adapter-display combinations. To maintain compatibility
  317. with earlier versions of Fastgraph, fg_automode does not consider the extended
  318. VGA graphics modes (modes 20 to 23) or SVGA graphics modes (modes 24 to 29)
  319. when selecting a video mode.
  320.  
  321.  
  322.                                          display
  323.                        adapter   mono   RGB   ECD   VGA
  324.  
  325.                           MDA       7     0     7     7
  326.                           HGC      11     0     0    11
  327.                           CGA       0     4     0     0
  328.                           EGA      15    13    16     0
  329.                           VGA      17    17    17    18
  330.                          MCGA      17    17    17    19
  331.                         Tandy       7     9     0     0
  332.                          PCjr       7     9     0     0
  333.  
  334.  
  335.      Example 3-6 shows how to use fg_automode to determine the "best" graphics
  336. mode for the user's video hardware. In graphics modes, the term best means the
  337. highest resolution, followed by the number of available colors. The program
  338. displays a message that includes the selected video mode number.
  339.  
  340.                                  Example 3-6.
  341.  
  342.                     #include <fastgraf.h>
  343.                     #include <stdio.h>
  344.                     void main(void);
  345.  
  346.                     void main()
  347.                     {
  348.                        int old_mode;
  349.                        int new_mode;
  350.                        char string[4];
  351.  
  352.                        fg_initpm();
  353.                        old_mode = fg_getmode();
  354.                        new_mode = fg_automode();
  355.                        fg_setmode(new_mode);
  356.  
  357.                        fg_setcolor(15);
  358.                        fg_text("I'm running in mode ",20);                     
  359. 48   Fastgraph User's Guide
  360.  
  361.                        sprintf(string,"%d.",new_mode);
  362.                        fg_text(string,3);
  363.                        fg_waitkey();
  364.  
  365.                        fg_setmode(old_mode);
  366.                        fg_reset();
  367.                     }
  368.  
  369.  
  370.      For simple programs such as example 3-6, different screen resolutions may
  371. not be an issue. However, in more complex graphics programs it is often
  372. desirable to write a program for a fixed screen resolution. A common practice
  373. is to develop graphics programs to run in modes 4 (for CGA), 9 (Tandy 1000 or
  374. PCjr), 12 (Hercules), 13 (EGA, VGA, or SVGA), and 19 or 20 (MCGA, VGA, or
  375. SVGA). The reason for selecting these five modes is they all use the same
  376. 320x200 resolution and will run on any IBM PC or PS/2 with graphics
  377. capabilities.
  378.  
  379.      Example 3-7 performs the same function as example 3-6, but it uses
  380. fg_bestmode instead of fg_automode to restrict the program to 320x200 graphics
  381. modes. For this resolution, the fg_bestmode routine will first check the
  382. availability of mode 20, followed by modes 19, 13, 9, 4, and 12. If
  383. fg_bestmode determines no 320x200 graphics mode is available (indicated by a
  384. return value of -1), the program prints an informational message and exits.
  385. Otherwise it selects the video mode fg_bestmode proposes and continues.
  386.  
  387.                                  Example 3-7.
  388.  
  389.      #include <fastgraf.h>
  390.      #include <stdio.h>
  391.      #include <stdlib.h>
  392.      void main(void);
  393.  
  394.      void main()
  395.      {
  396.         int old_mode;
  397.         int new_mode;
  398.         char string[4];
  399.  
  400.         fg_initpm();
  401.         old_mode = fg_getmode();
  402.         new_mode = fg_bestmode(320,200,1);
  403.  
  404.         if (new_mode < 0) {
  405.            printf("This program requires a 320 by 200 graphics mode.\n");
  406.            exit(1);
  407.            }
  408.  
  409.         fg_setmode(new_mode);
  410.  
  411.         fg_setcolor(15);
  412.         fg_text("I'm running in mode ",20);
  413.         sprintf(string,"%d.",new_mode);
  414.         fg_text(string,3);
  415.         fg_waitkey();                                                          
  416.                            Chapter 3:  Initializing the Video Environment   49
  417.  
  418.         fg_setmode(old_mode);
  419.         fg_reset();
  420.      }
  421.  
  422.  
  423.      If a program will run in specific video modes, you may want to consider
  424. using the fg_testmode routine instead of fg_bestmode to check for availability
  425. of these video modes. You also may want to use fg_testmode to change the video
  426. mode precedence used by fg_bestmode. For example, mode 13 (EGA) is faster than
  427. mode 19 (MCGA), so you may want to consider giving EGA precedence over MCGA,
  428. especially if your program does not use more than 16 colors.
  429.  
  430.      Example 3-8 is similar to example 3-7, but it will only run in the
  431. 320x200 EGA, MCGA, and CGA graphics modes (video modes 13, 19, and 4,
  432. respectively). The program uses fg_testmode to select its video mode. Note the
  433. order of calls to fg_testmode gives EGA precedence over MCGA, and MCGA
  434. precedence over CGA.
  435.  
  436.                                  Example 3-8.
  437.  
  438.         #include <fastgraf.h>
  439.         #include <stdio.h>
  440.         #include <stdlib.h>
  441.         void main(void);
  442.  
  443.         void main()
  444.         {
  445.            int old_mode;
  446.            char string[4];
  447.  
  448.            fg_initpm();
  449.            old_mode = fg_getmode();
  450.  
  451.            if (fg_testmode(13,1))
  452.               fg_setmode(13);
  453.            else if (fg_testmode(19,1))
  454.               fg_setmode(19);
  455.            else if (fg_testmode(4,1))
  456.               fg_setmode(4);
  457.            else {
  458.               printf("This program requires an EGA, MCGA, or CGA.\n");
  459.               exit(1);
  460.               }
  461.  
  462.            fg_setcolor(15);
  463.            fg_text("I'm running in mode ",20);
  464.            sprintf(string,"%d.",getmode());
  465.            fg_text(string,3);
  466.            fg_waitkey();
  467.  
  468.            fg_setmode(old_mode);
  469.            fg_reset();
  470.         }                                                                      
  471. 50   Fastgraph User's Guide
  472.  
  473.  
  474. SuperVGA Graphics Modes
  475.  
  476.      Unlike previous generations of graphics cards, there was no video
  477. standard in place when different companies began developing SVGA cards. As a
  478. result, they implemented enhanced SVGA features according to their own
  479. specifications based upon different video controller chips. Each such
  480. implementation is called a chipset. While each chipset generally offers the
  481. same video memory organization and common screen resolutions, the SVGA-
  482. specific features such as mode initialization, bank switching, and setting the
  483. display start address differ radically between chipsets. In other words, code
  484. written for one specific SVGA chipset will not run on another chipset, even at
  485. the same resolution. This is why many software vendors provide different SVGA
  486. drivers for their products.
  487.  
  488.      Fastgraph's integrated SVGA kernel makes these obscure differences
  489. between SVGA chipsets transparent, without the need for external drivers. This
  490. means, for instance, if you write an application for the 1024 by 768 256-color
  491. SVGA graphics mode, it will run without changes on any supported SVGA chipset
  492. which offers that resolution. The SVGA kernel supports the chipsets listed in
  493. the table below. A "Y" entry means the chipset supports the video mode, and an
  494. "N" means it doesn't. The last two rows of the table show the minimum amount
  495. of video memory required to support each mode and Fastgraph's corresponding
  496. video mode numbers.
  497.  
  498.                             -------- 256 colors --------   -- 16 colors --
  499. SVGA chipset               640x400 640x480 800x6001024x768 800x6001024x768
  500.  
  501. Ahead "A" type                Y       Y       Y       N       Y       Y
  502. Ahead "B" type                Y       Y       Y       Y       Y       Y
  503. ATI 18800                     Y       Y       Y       N       Y       N
  504. ATI 18800-1                   Y       Y       Y       N       Y       Y
  505. ATI 28800/38800/68800/88800   Y       Y       Y       Y       Y       Y
  506. Avance Logic 2000 series      Y       Y       Y       Y       Y       Y
  507. Chips & Technologies 82c451   Y       N       N       N       Y       N
  508. Chips & Technologies 82c452   Y       Y       N       N       Y       Y
  509. Chips & Technologies 82c453   Y       Y       Y       Y       Y       Y
  510. Cirrus Logic 5400 series      N       Y       Y       Y       Y       Y
  511. Cirrus Logic 6400 series      Y       Y       Y       Y       Y       Y
  512. Genoa 6000 series             Y       Y       Y       N       Y       Y
  513. NCR 77C22/77C32               Y       Y       Y       Y       Y       Y
  514. Oak OTI-067                   N       Y       Y       N       Y       Y
  515. Oak OTI-077                   N       Y       Y       Y       Y       Y
  516. Oak OTI-087                   Y       Y       Y       N       Y       Y
  517. Paradise PVGA1a               Y       Y       N       N       Y       N
  518. Paradise WD90C00/10           Y       Y       N       N       Y       Y
  519. Paradise WD90C11/30/31/33     Y       Y       Y       Y       Y       Y
  520. S3                            N       Y       Y       Y       Y       Y
  521. Trident 8800                  Y       Y       N       N       Y       Y
  522. Trident 8900/9000             Y       Y       Y       Y       Y       Y
  523. Tseng ET3000                  N       Y       Y       N       Y       Y
  524. Tseng ET4000                  Y       Y       Y       Y       Y       Y
  525. Video7                        Y       Y       Y       Y       Y       Y
  526.  
  527. minimum video RAM needed    256K    512K    512K     1MB    256K    512K
  528. Fastgraph mode number        24      25      26      27      28      29        
  529.                            Chapter 3:  Initializing the Video Environment   51
  530.  
  531.  
  532.  
  533. The SVGA kernel maps Fastgraph's video mode numbers (24 to 29) to the chipset-
  534. specific mode numbers. For example, the 640x480 256-color SVGA mode is 62 hex
  535. on an ATI card, 5D hex on a Trident card, and 2E hex on a Tseng card, but it's
  536. always mode 25 from Fastgraph's perspective. As we constantly add support for
  537. new SVGA chipsets, please refer to Fastgraph's READ.ME file for the current
  538. chipset list. The READ.ME file also lists known problems and limitations with
  539. the various chipsets.
  540.  
  541.      The Video Electronics Standards Association (VESA) has assumed the
  542. complex task of improving software compatibility of SVGA cards from different
  543. companies. Most SVGA cards sold today include VESA compatibility, either
  544. directly in ROM or through loadable software drivers supplied with the card.
  545. Besides supporting specific chipsets, Fastgraph's SVGA kernel supports any
  546. SVGA card with VESA compatibility. Note that VESA is not a chipset, but a
  547. BIOS-level interface between an application (the SVGA kernel in this case) and
  548. chipset-specific functions. While the current VESA standard covers all six
  549. SVGA graphics modes that Fastgraph supports, these modes are only available if
  550. the underlying chipset also supports them.
  551.  
  552.      When using VESA compatibility, the VESA BIOS handles all chipset-specific
  553. functions such as bank switching. The overhead imposed by the BIOS usually
  554. makes the VESA modes slower than using chipset-specific functions directly.
  555. For this reason, you can specify if you want to give precedence to the
  556. chipset-specific code or to the VESA BIOS. Chipset-specific precedence means
  557. the SVGA kernel will only use the VESA BIOS if no supported SVGA chipset is
  558. found. Conversely, VESA precedence means the kernel will only use the chipset-
  559. specific functions if no VESA BIOS is found.
  560.  
  561.      Before you use any SVGA graphics mode, you must use the fg_svgainit
  562. routine to initialize the SVGA kernel (fg_svgainit must be called before
  563. fg_setmode, fg_bestmode, or fg_testmode). There are three ways to initialize
  564. the SVGA kernel with fg_svgainit:
  565.  
  566.      * autodetect the SVGA chipset, precedence to chipset-specific code
  567.      * autodetect the SVGA chipset, precedence to the VESA BIOS
  568.      * use a designated SVGA chipset
  569.  
  570. The fg_svgainit routine's argument is an integer value between 0 and 27 that
  571. specifies which initialization method to use. Passing 0 to fg_svgainit uses
  572. the first method, in which the SVGA kernel searches for all supported chipsets
  573. before checking if a VESA BIOS is present. This means the SVGA kernel will
  574. only use VESA functions if fg_svgainit doesn't find one of the supported
  575. chipsets. Passing 1 to fg_svgainit also performs a chipset autodetect, but in
  576. this case the SVGA kernel first searches for a VESA BIOS, then through the
  577. list of supported chipsets. This means chipset-specific code will be used only
  578. when no VESA BIOS is found. You can also initialize the SVGA kernel for a
  579. specific chipset by passing a value between 2 and 27 to fg_svgainit. The
  580. following table summarizes the fg_svgainit initialization codes.
  581.  
  582.         code   chipset
  583.  
  584.           0    autodetect (with chipset-specific precedence)
  585.           1    autodetect (with VESA precedence)
  586.           2    Ahead "A" type                                                  
  587. 52   Fastgraph User's Guide
  588.  
  589.           3    Ahead "B" type
  590.           4    ATI 18800
  591.           5    ATI 18800-1
  592.           6    ATI 28800/38800/68800/88800
  593.           7    Chips & Technologies 82c451/455/456
  594.           8    Chips & Technologies 82c452
  595.           9    Chips & Technologies 82c453
  596.          10    Genoa 6000 series
  597.          11    Oak OTI-067
  598.          12    Paradise PVGA1a
  599.          13    Paradise WD90C00/WD90C10
  600.          14    Paradise WD90C11/WD90C30/WD90C31/WD90C33
  601.          15    Trident 8800
  602.          16    Trident 8900/9000
  603.          17    Tseng ET3000
  604.          18    Tseng ET4000
  605.          19    Video7
  606.          20    Cirrus Logic 5400 series
  607.          21    S3
  608.          22    NCR 77C22/77C32
  609.          23    Oak OTI-077
  610.          24    Oak OTI-087
  611.          25    reserved
  612.          26    Cirrus Logic 6400 series
  613.          27    Avance Logic 2000 series
  614.          >27   autodetect (with chipset-specific precedence)
  615.  
  616.      For autodetect requests, fg_svgainit returns a value between 1 and 27
  617. corresponding to the SVGA chipset found. If the return value is 1, it means a
  618. VESA BIOS will be used. A value between 2 and 27 means a specific SVGA chipset
  619. (as listed in the preceding table) will be used. If no VESA BIOS or supported
  620. SVGA chipset is found, fg_svgainit returns zero. In this case, Fastgraph's
  621. SVGA graphics modes are not available.
  622.  
  623.      When you request initialization for a specific chipset, fg_svgainit
  624. always returns the value passed to it. It does not check if that chipset is
  625. actually present, so this feature should be used judiciously.
  626.  
  627.      Example 3-9 is a simple program that checks if an SVGA card is present,
  628. and if so, displays the name of the SVGA chipset. It also displays how much
  629. video memory is present on the SVGA card and the version number of Fastgraph's
  630. SVGA kernel.
  631.  
  632.                                  Example 3-9.
  633.  
  634.             #include <fastgraf.h>
  635.             #include <stdio.h>
  636.             void main(void);
  637.  
  638.             char *description[] =
  639.             {
  640.                "cannot be determined",
  641.                "VESA",
  642.                "Ahead A",
  643.                "Ahead B",
  644.                "ATI 18800",                                                    
  645.                            Chapter 3:  Initializing the Video Environment   53
  646.  
  647.                "ATI 18800-1",
  648.                "ATI 28800/38800/68800/88800",
  649.                "Chips & Technologies 82c451/455/456",
  650.                "Chips & Technologies 82c452",
  651.                "Chips & Technologies 82c453",
  652.                "Genoa 6000 series",
  653.                "Oak OTI-067",
  654.                "Paradise PVGA1a",
  655.                "Paradise WD90C00/WD90C10",
  656.                "Paradise WD90C11/WD90C30/WD90C31/WD90C33",
  657.                "Trident 8800",
  658.                "Trident 8900/9000",
  659.                "Tseng ET3000",
  660.                "Tseng ET4000",
  661.                "Video7",
  662.                "Cirrus Logic 5400 series",
  663.                "S3",
  664.                "NCR 77C22/77C32",
  665.                "Oak OTI-077",
  666.                "Oak OTI-087",
  667.                " ",
  668.                "Cirrus Logic 6400 series",
  669.                "Avance Logic 2000 series"
  670.             };
  671.  
  672.             void main()
  673.             {
  674.                int id, major, minor;
  675.  
  676.                fg_initpm();
  677.                id = fg_svgainit(0);
  678.                printf("SVGA chipset:  %s\n",description[id]);
  679.                printf("video memory:  %d kilobytes\n",fg_memory());
  680.                fg_svgaver(&major,&minor);
  681.                printf("SVGA version:  %d.%2.2d\n",major,minor);
  682.             }
  683.  
  684.  
  685. This example uses fg_svgainit to detect the user's SVGA chipset automatically.
  686. It initializes the SVGA kernel so chipset-specific code is given precedence
  687. over VESA (passing 1 instead of 0 to fg_svgainit would give VESA precedence).
  688. Note that the program does not establish an SVGA graphics mode -- it just uses
  689. the fg_svgainit return value to identify which chipset is present.
  690.  
  691.      Example 3-9 also includes two other Fastgraph routines relevant to the
  692. SVGA kernel. The fg_memory function returns the amount of video memory (in
  693. kilobytes) resident on the user's video card. For example, the fg_memory
  694. return value is 1,024 for a 1MB SVGA card. Another routine, fg_svgaver,
  695. returns the major and minor numbers for the SVGA kernel, similar to the
  696. fg_version routine mentioned in Chapter 1. Note that the SVGA kernel version
  697. number is not the same as the Fastgraph version number.
  698.  
  699.      Another useful function is fg_svgastat, which returns information about
  700. the current state of Fastgraph's SVGA kernel. The function returns a bit mask
  701. in which bit 0 will be set if the SVGA kernel has been successfully
  702. initialized, and bit 1 will be set if the kernel is using the VESA BIOS. Other 
  703. 54   Fastgraph User's Guide
  704.  
  705. fg_svgastat bits provide information about the availability of extended video
  706. pages and whether or not the active chipset supports separate read and write
  707. banks. We'll discuss these features in later chapters.
  708.  
  709.      Our next example, 3-10, is an SVGA version of example 3-8. This program
  710. initializes the SVGA kernel so that VESA will have precedence over chipset-
  711. specific code. It then calls fg_testmode to find a supported 256-color SVGA
  712. graphics mode, first trying mode 27 (1024 by 768), then mode 26 (800x600), and
  713. finally mode 25 (640x480). Checking the modes in this sequence insures the
  714. program will use the highest resolution available, given the user's SVGA
  715. chipset (not all chipsets support all resolutions) and the amount of video
  716. memory present (mode 27 requires 1MB video RAM; modes 26 and 25 need 512K).
  717.  
  718.      If all three fg_testmode calls fail in example 3-10, the program displays
  719. an appropriate message and exits. This would happen if the program were run on
  720. a non-SVGA system, run on an unsupported SVGA chipset without VESA
  721. compatibility, or if the SVGA card does not have at least 512K video memory
  722. (modes 25, 26, and 27 all require at least 512K). In the first two cases, the
  723. fg_svgainit function wouldn't have initialized the SVGA kernel, so fg_testmode
  724. would fail when checking the availability of any SVGA graphics mode. That's
  725. why it's not necessary to check the fg_svgainit return value in this case.
  726.  
  727.                                  Example 3-10.
  728.  
  729.               #include <fastgraf.h>
  730.               #include <stdio.h>
  731.               #include <stdlib.h>
  732.               void main(void);
  733.  
  734.               void main()
  735.               {
  736.                  int old_mode;
  737.                  char string[4];
  738.  
  739.                  fg_initpm();
  740.                  old_mode = fg_getmode();
  741.                  fg_svgainit(1);
  742.  
  743.                  if (fg_testmode(27,1))
  744.                     fg_setmode(27);
  745.                  else if (fg_testmode(26,1))
  746.                     fg_setmode(26);
  747.                  else if (fg_testmode(25,1))
  748.                     fg_setmode(25);
  749.                  else {
  750.                     printf("This program requires an SVGA ");
  751.                     printf("with at least 512K video memory.\n");
  752.                     exit(1);
  753.                     }
  754.  
  755.                  fg_setcolor(15);
  756.                  fg_text("I'm running in mode ",20);
  757.                  sprintf(string,"%d.",fg_getmode());
  758.                  fg_text(string,3);
  759.                  fg_waitkey();                                                 
  760.                            Chapter 3:  Initializing the Video Environment   55
  761.  
  762.                  fg_setmode(old_mode);
  763.                  fg_reset();
  764.               }
  765.  
  766.  
  767.      While the VESA specification defines a common programming interface for
  768. chipset-specific SVGA functions, we must remember that VESA is just that -- a
  769. specification. Some manufacturers provide VESA drivers or BIOS implementations
  770. that realize the full VESA specification with only slight performance
  771. degradations. Others aren't as good, having problems with anything beyond the
  772. rudimentary functions of mode initialization and bank switching, not to
  773. mention performance issues.
  774.  
  775.      Other problems can occur with the few SVGA cards that do not completely
  776. follow the chipset manufacturer's predefined video mode numbers and register
  777. definitions. While the SVGA kernel allows for these problems when known, it's
  778. just not possible to support every problematic SVGA card. To complicate
  779. matters, some of these troublesome video cards only exhibit problems in
  780. certain revisions, meaning two apparently identical cards will behave
  781. differently. Fortunately, such problematic cards are by far the exception.
  782.  
  783.      If you're developing an SVGA product for general distribution, we
  784. recommend using Fastgraph's chipset-specific code by default, but also
  785. providing a way to override the chipset-specific code and use VESA support.
  786. Most often this is done by recognizing a command line switch or using an
  787. application-specific configuration file. Some programmers even take this one
  788. step farther by including a way to avoid the SVGA autodetection procedure and
  789. initialize Fastgraph's SVGA kernel for a specific chipset. This might be
  790. important if your product will run on laptop systems, which sometimes have
  791. SVGA video subsystems that don't respond to autodetection requests as reliably
  792. as their desktop counterparts.
  793.  
  794.      Another important point to consider when writing SVGA applications is the
  795. compatibility between the video card and monitor. Virtually all SVGA monitors
  796. made today have no problems supporting the bandwidth required by any of
  797. Fastgraph's SVGA graphics modes. However, some monitors (most notably older
  798. multisync monitors) cannot support the higher resolution modes such as 800x600
  799. and 1024 by 768. The SVGA kernel checks if the SVGA card supports the
  800. requested resolution, but it does not check if the card/monitor combination
  801. does.
  802.  
  803.  
  804. Summary of Video Initialization Routines
  805.  
  806.      This section summarizes the functional descriptions of the Fastgraph
  807. routines presented in this chapter. More detailed information about these
  808. routines, including their arguments and return values, may be found in the
  809. Fastgraph Reference Manual.
  810.  
  811.      FG_AUTOMODE determines the graphics video mode that offers the most
  812. features for the user's display and adapter configuration. The value it
  813. returns helps determine a suitable value to pass to the fg_setmode routine.
  814.  
  815.      FG_BESTMODE is similar to fg_automode, but it excludes video modes that
  816. do not offer the specified resolution and video page requirements.             
  817. 56   Fastgraph User's Guide
  818.  
  819.      FG_CURSOR makes the text mode cursor visible or invisible. This routine
  820. has no effect when used in a graphics mode.
  821.  
  822.      FG_GETLINES returns the number of text rows per screen for the current
  823. video mode.
  824.  
  825.      FG_GETMODE returns the current video mode. It is typically one of the
  826. first Fastgraph routines called in a program. The value returned by fg_getmode
  827. can be used to restore the original video mode when a program transfers
  828. control back to DOS.
  829.  
  830.      FG_MEMORY returns the amount of video memory present (in kilobytes) on
  831. the user's SVGA card. This routine is meaningful only after successfully
  832. initializing the SVGA kernel with fg_svgainit.
  833.  
  834.      FG_RESET is generally the last Fastgraph routine called in a program. It
  835. only functions in text video modes. When the ANSI.SYS driver is not loaded,
  836. fg_reset merely erases the screen. When ANSI.SYS is loaded, fg_reset also
  837. restores any previously set screen attributes.
  838.  
  839.      FG_SETLINES extends an 80-column text mode to 25, 43, or 50 lines per
  840. screen. This routine is only meaningful when running in 80-column text modes
  841. on EGA, VGA, or MCGA systems (in other cases it does nothing).
  842.  
  843.      FG_SETMODE establishes a video mode and initializes Fastgraph's internal
  844. parameters for that video mode. It must be called before any Fastgraph routine
  845. that performs video output. A program can call fg_setmode as many times as
  846. needed to switch between different video modes.
  847.  
  848.      FG_SVGAINIT initializes Fastgraph's SVGA kernel and performs chipset-
  849. specific SVGA initialization. This routine must be called before establishing
  850. an SVGA graphics mode with fg_setmode.
  851.  
  852.      FG_SVGASTAT returns information about the current state of Fastgraph's
  853. SVGA kernel.
  854.  
  855.      FG_SVGAVER returns the SVGA kernel's major and minor version numbers.
  856.  
  857.      FG_TESTMODE determines whether or not a specified video mode (with a
  858. given number of video pages) is available on the user's system.
  859.