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 >
Wrap
Text File
|
1992-10-05
|
6KB
|
169 lines
Chapter 15
Miscellaneous Routines
254 Fastgraph User's Guide
Overview
There are a few remaining Fastgraph routines that really don't fit into
any of the categories discussed so far. For this reason, they are described
separately in this chapter.
Determining Available Memory
The fg_memavail routine returns the amount of free conventional memory
(in bytes) available to DOS. It returns the amount of memory as its function
value, which is a 32-bit unsigned integer. Fg_memavail has no arguments.
Example 15-1 uses fg_memavail to show the effects of creating and
releasing virtual pages. When run in a video mode in which video pages 1 and
2 are physical pages, the amount of free memory remains the same because
these pages use memory that is resident on the video adapter. However, in
modes where pages 1 and 2 are virtual pages, the amount of free memory
decreases after each call to fg_allocate and returns to its original value
after the calls to fg_freepage. Note how the program requests and validates
the video mode.
Example 15-1.
#include <fastgraf.h>
#include <stdio.h>
#include <stdlib.h>
void main(void);
void main()
{
long original, mem0, mem1, mem2;
int mode, old_mode;
printf("Which video mode? ");
scanf("%d",&mode);
if (fg_testmode(mode,0) == 0) {
printf("Your system does not support that video mode.\n");
exit(1);
}
if (fg_testmode(mode,3) == 0) {
printf("Your system does not have enough memory.\n");
exit(1);
}
original = fg_memavail();
old_mode = fg_getmode();
fg_setmode(mode);
mem0 = fg_memavail();
fg_allocate(1);
mem1 = fg_memavail();
fg_allocate(2);
mem2 = fg_memavail();
fg_freepage(1);
fg_freepage(2);
Chapter 15: Miscellaneous Routines 255
fg_setmode(old_mode);
fg_reset();
printf("originally = %ld\n",original);
printf("after setmode = %ld\n",mem0);
printf("after 1st page = %ld\n",mem1);
printf("after 2nd page = %ld\n",mem2);
printf("at end = %ld\n",memavail());
}
Choosing the Video Memory Update Function
In Chapter 10, we saw how to use the fg_setfunc routine to perform XOR
animation in native EGA and VGA graphics modes (modes 13 to 18). In these
video modes, fg_setfunc controls the logical operation applied when the
contents of video memory change. The specific operation is defined by its
argument, as shown below.
value of logical
argument operation
0 replacement
1 and
2 or
3 exclusive or
If your program does not use the fg_setfunc routine, replacement mode is
always used. That is, information written to video memory replaces whatever
was there before. The fg_setfunc routine does nothing in CGA, Tandy/PCjr,
Hercules, or MCGA graphics modes, or in any text modes.
Example 15-2 demonstrates the fg_setfunc routine. The program is
similar to example 6-10 which displays 200 random rectangles on the screen.
However, example 15-2 displays the rectangles in XOR mode, which means the
rectangle intersections will appear in different colors.
Example 15-2.
#include <fastgraf.h>
#include <stdio.h>
#include <stdlib.h>
void main(void);
#define RECTANGLES 200
#define SWAP(a,b,temp) { temp = a; a = b; b = temp; }
void main()
{
int i;
int minx, maxx, miny, maxy;
int old_mode;
int temp;
256 Fastgraph User's Guide
int xres, yres;
if (fg_egacheck() == 0) {
printf("This program requires EGA or VGA.\n");
exit(1);
}
old_mode = fg_getmode();
fg_setmode(fg_automode());
fg_setfunc(3);
xres = fg_getmaxx() + 1;
yres = fg_getmaxy() + 1;
for (i = 0; i < RECTANGLES; i++) {
minx = rand() % xres;
maxx = rand() % xres;
miny = rand() % yres;
maxy = rand() % yres;
if (minx > maxx)
SWAP(minx,maxx,temp);
if (miny > maxy)
SWAP(miny,maxy,temp);
fg_setcolor(rand()%16);
fg_rect(minx,maxx,miny,maxy);
}
fg_setmode(old_mode);
fg_reset();
}
Summary of Miscellaneous Routines
This section summarizes the functional descriptions of the Fastgraph
routines presented in this chapter. More detailed information about these
routines, including their arguments and return values, may be found in the
Fastgraph Reference Manual.
FG_MEMAVAIL returns the amount of memory available to DOS.
FG_SETFUNC specifies the logical operation (replacement, or, and,
exclusive or) applied when video memory changes in the native EGA and VGA
graphics modes. This routine has no effect in other video modes.