home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / PROGRAMM / FGL112B.ZIP / USER15.DOC < prev    next >
Text File  |  1992-10-05  |  6KB  |  169 lines

  1.  
  2.  
  3. Chapter 15
  4.  
  5. Miscellaneous Routines
  6. 254  Fastgraph User's Guide
  7.  
  8. Overview
  9.  
  10.      There are a few remaining Fastgraph routines that really don't fit into
  11. any of the categories discussed so far.  For this reason, they are described
  12. separately in this chapter.
  13.  
  14.  
  15. Determining Available Memory
  16.  
  17.      The fg_memavail routine returns the amount of free conventional memory
  18. (in bytes) available to DOS.  It returns the amount of memory as its function
  19. value, which is a 32-bit unsigned integer.  Fg_memavail has no arguments.
  20.  
  21.      Example 15-1 uses fg_memavail to show the effects of creating and
  22. releasing virtual pages.  When run in a video mode in which video pages 1 and
  23. 2 are physical pages, the amount of free memory remains the same because
  24. these pages use memory that is resident on the video adapter.  However, in
  25. modes where pages 1 and 2 are virtual pages, the amount of free memory
  26. decreases after each call to fg_allocate and returns to its original value
  27. after the calls to fg_freepage.  Note how the program requests and validates
  28. the video mode.
  29.  
  30.                                 Example 15-1.
  31.  
  32.        #include <fastgraf.h>
  33.        #include <stdio.h>
  34.        #include <stdlib.h>
  35.        void main(void);
  36.  
  37.        void main()
  38.        {
  39.           long original, mem0, mem1, mem2;
  40.           int  mode, old_mode;
  41.  
  42.           printf("Which video mode? ");
  43.           scanf("%d",&mode);
  44.  
  45.           if (fg_testmode(mode,0) == 0) {
  46.              printf("Your system does not support that video mode.\n");
  47.              exit(1);
  48.              }
  49.           if (fg_testmode(mode,3) == 0) {
  50.              printf("Your system does not have enough memory.\n");
  51.              exit(1);
  52.              }
  53.  
  54.           original = fg_memavail();
  55.           old_mode = fg_getmode();
  56.           fg_setmode(mode);
  57.           mem0 = fg_memavail();
  58.           fg_allocate(1);
  59.           mem1 = fg_memavail();
  60.           fg_allocate(2);
  61.           mem2 = fg_memavail();
  62.           fg_freepage(1);
  63.           fg_freepage(2);
  64.  
  65.                                       Chapter 15:  Miscellaneous Routines  255
  66.  
  67.           fg_setmode(old_mode);
  68.           fg_reset();
  69.  
  70.           printf("originally     = %ld\n",original);
  71.           printf("after setmode  = %ld\n",mem0);
  72.           printf("after 1st page = %ld\n",mem1);
  73.           printf("after 2nd page = %ld\n",mem2);
  74.           printf("at end         = %ld\n",memavail());
  75.        }
  76.  
  77.  
  78.  
  79. Choosing the Video Memory Update Function
  80.  
  81.      In Chapter 10, we saw how to use the fg_setfunc routine to perform XOR
  82. animation in native EGA and VGA graphics modes (modes 13 to 18).  In these
  83. video modes, fg_setfunc controls the logical operation applied when the
  84. contents of video memory change.  The specific operation is defined by its
  85. argument, as shown below.
  86.  
  87.                           value of  logical
  88.                           argument  operation
  89.  
  90.                               0     replacement
  91.                               1     and
  92.                               2     or
  93.                               3     exclusive or
  94.  
  95. If your program does not use the fg_setfunc routine, replacement mode is
  96. always used.  That is, information written to video memory replaces whatever
  97. was there before.  The fg_setfunc routine does nothing in CGA, Tandy/PCjr,
  98. Hercules, or MCGA graphics modes, or in any text modes.
  99.  
  100.      Example 15-2 demonstrates the fg_setfunc routine.  The program is
  101. similar to example 6-10 which displays 200 random rectangles on the screen.
  102. However, example 15-2 displays the rectangles in XOR mode, which means the
  103. rectangle intersections will appear in different colors.
  104.  
  105.                                 Example 15-2.
  106.  
  107.             #include <fastgraf.h>
  108.             #include <stdio.h>
  109.             #include <stdlib.h>
  110.             void main(void);
  111.  
  112.             #define RECTANGLES 200
  113.             #define SWAP(a,b,temp) { temp = a; a = b; b = temp; }
  114.  
  115.             void main()
  116.             {
  117.                int i;
  118.                int minx, maxx, miny, maxy;
  119.                int old_mode;
  120.                int temp;
  121.  
  122. 256  Fastgraph User's Guide
  123.  
  124.                int xres, yres;
  125.  
  126.                if (fg_egacheck() == 0) {
  127.                   printf("This program requires EGA or VGA.\n");
  128.                   exit(1);
  129.                   }
  130.  
  131.                old_mode = fg_getmode();
  132.                fg_setmode(fg_automode());
  133.                fg_setfunc(3);
  134.  
  135.                xres = fg_getmaxx() + 1;
  136.                yres = fg_getmaxy() + 1;
  137.  
  138.                for (i = 0; i < RECTANGLES; i++) {
  139.                   minx = rand() % xres;
  140.                   maxx = rand() % xres;
  141.                   miny = rand() % yres;
  142.                   maxy = rand() % yres;
  143.                   if (minx > maxx)
  144.                      SWAP(minx,maxx,temp);
  145.                   if (miny > maxy)
  146.                      SWAP(miny,maxy,temp);
  147.                   fg_setcolor(rand()%16);
  148.                   fg_rect(minx,maxx,miny,maxy);
  149.                   }
  150.  
  151.                fg_setmode(old_mode);
  152.                fg_reset();
  153.             }
  154.  
  155.  
  156.  
  157. Summary of Miscellaneous Routines
  158.  
  159.      This section summarizes the functional descriptions of the Fastgraph
  160. routines presented in this chapter.  More detailed information about these
  161. routines, including their arguments and return values, may be found in the
  162. Fastgraph Reference Manual.
  163.  
  164.      FG_MEMAVAIL returns the amount of memory available to DOS.
  165.  
  166.      FG_SETFUNC specifies the logical operation (replacement, or, and,
  167. exclusive or) applied when video memory changes in the native EGA and VGA
  168. graphics modes.  This routine has no effect in other video modes.
  169.