If this page looks like garbage then you need one of these browsers...Please sign my programmer's page guestbook. |
Completed Graphics FunctionsWe have without a doubt covered much ground on the VGA graphics. Of course, there are a few things that we have yet to cover, but we will get to them as we need to. For now, the functions that were presented should be plenty to get started off with. Now, we must consider how we are to use these functions later on. From here on out, much of what we write will build upon these functions so we must have these functions available for future code. So what we should do is create a library with a group of headers and source code so that we can include these functions in programs that we write in the future. To help you with this, I have already included the VGA code and have made the header files and source files available. To view the completed header file click here.
Creating the libraryNaturally we do not want to have to include the source file for every new program that we write using the functions. We should be able to just include the header file and link it to our library for the precompiled function. But first, we must create a library. Before we do, let's agree on some specifics here.
Our directory tree should look similar to this... Parent directory where the samples are stored Examples include "A:\", "C:\MYDEMOS", etc. | +---INCLUDE | VGA256.H | +---LIB | \---SOURCE VGA256.C Using the code and the directory tree established, from the parent directory (where we plan to store the demo programs at) key in the following line to compile the VGA256.C source file.
tcc -mm -c -1 source\vga256.c
This will compile the VGA256.C file using the Medium Memory model (-mm switch), which is the best for games. It will compile only to OBJ, not try to make an EXE also (-c switch), and use 186/286 real mode instructions (-1 switch). Once this process is finished, our directory tree should look similar to the following: Parent directory where the samples are stored Examples include "A:\", "C:\MYDEMOS", etc. | | VGA256.OBJ | +---INCLUDE | VGA256.H | +---LIB | \---SOURCE VGA256.C Move the file VGA256.OBJ to the LIB subdirectory. From DOS use:
move vga256.obj lib
Then change to the LIB subdirectory and create the library called GAME_13H.LIB with the following command line. tlib game_13h.lib +vga256.obj, game_13h.txt
Now the directory tree should look like this:
Parent directory where the samples are stored Examples include "A:\", "C:\MYDEMOS", etc. | | +---INCLUDE | VGA256.H | +---LIB | VGA256.OBJ | GAME_13H.TXT | GAME_13H.LIB | \---SOURCE VGA256.C
Then, if you want, you can list the contents of the listing file (GAME_13H.TXT) and see the following... Publics by module VGA256 size = 2794 _Circle _CircleC _DeleteCache _GetPaletteRegister _Gputch _GputchC _Gputs _GputsC _InitCache _Line _LineC _SetPaletteRegister _SetVideoMode _WaitForVertRetrace _cacheLines _cacheMem _cacheSize _charSet _videoMem Now whenever you want to include the graphics functions, you can do it much more efficiently. Let's create a sample program using the library to see how it's done. /* TESTVGA.C * * This file does a demo of the VGA functions we've written so far. */ #include <conio.h> #include <stdlib.h> #include <stdio.h> /* Enable this line for compile within the IDE */ /* #include "source\vga256.c" */ /* Enable this line for compile with at the command line */ #include "include\vga256.h" int main(void) { int i; long count; char string[41]; SetVideoMode(VGA256); while (!kbhit()) SetPixel(rand()%320, rand()%200, rand()%256); getch(); FillScreen(0); Gputs(0, 0, "Gary Neal Jr.", 4, -1); getch(); FillScreen(0); while (!kbhit()) Line(rand()%320, rand()%200, rand()%320, rand()%200, rand()%256); getch(); FillScreen(0); while (!kbhit()) Circle(rand()%320, rand()%200, rand()%100, rand()%256); getch(); FillScreen(0); Gputs(0, 0, "Counting vertical retrace periods.", 15, 0); count = 0L; while(!kbhit()) { WaitForVertRetrace(); count++; sprintf(string, "%ld vertical retraces.", count); Gputs(0, 32, string, 15, 0); } getch(); SetVideoMode(TEXT_MODE); return 0; } Save the above to a file called TESTVGA.C in the parent directory. Your directory tree should look like this:
Parent directory where the samples are stored Examples include "A:\", "C:\MYDEMOS", etc. | | TESTVGA.C | +---INCLUDE | VGA256.H | +---LIB | VGA256.OBJ | GAME_13H.TXT | GAME_13H.LIB | \---SOURCE VGA256.C
Then at the command prompt, in the parent directory, compile the program to EXE using this command line... tcc -mm -1 testvga.c lib\game_13h.lib Your directory tree should now look like this:
Parent directory where the samples are stored Examples include "A:\", "C:\MYDEMOS", etc. | | TESTVGA.C | TESTVGA.OBJ | TESTVGA.EXE | +---INCLUDE | VGA256.H | +---LIB | VGA256.OBJ | GAME_13H.TXT | GAME_13H.LIB | \---SOURCE VGA256.C
Now you can run the resulting TESTVGA.EXE file to see the results. If you are compiling the TESTVGA.C program from within the Turbo C++ IDE, make sure that the path is set to your "parent directory" using the File / Change Dir... menu. You may have noticed that there are a few functions that we have not covered yet that were included in the available copies of the VGA256 source codes. Here is another TESTVGA.C program that gives a more in depth test of the VGA256 functions not covered. Save this file to the parent directory and compile it just as you did the previous TESTVGA.C program listed above. We will cover these functions later on. Send your questions, comments, or ideas to: wilkeg@gamewood.net This page hosted by
Get your own Free Home Page |