home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-05-09 | 77.4 KB | 2,681 lines |
- BC 4.0 Lib
- Borland C/C++ v4.0 Library
- v1.1 (C) Copyright 1994
- Rockland Software Productions
-
- Description:
- BC40Lib is a programming library for Borland C/C++ v4.0. It includes
- libraries for mouse, joystick, graphics, math, file I/O, and other
- miscellaneous functions.
-
- Differences between the registered and unregistered versions:
- The unregistered version contains a lib for small memory model. This
- allows you to try the library. The registered version comes with source
- code. Please use the unregistered version for evaluation purposes ONLY.
- If you end up using BC40LIB code, you ARE required to register.
-
- Archive contents:
- BC40LIB.doc BC40LIB documentation
- *.h header files
- *.lib library files
- *.c source files (registered version only)
- catalog.doc Rockland Software Productions catalog
- order.frm order form
- support.doc support information
- vendor.txt distribution policy
-
- Installing:
- 1. Copy the .lib file(s) to your \bc4\lib directory.
- 2. Copy the .h files to \bc4\include directory.
- 3. Copy the .c files (registered version only) to your \bc4\source
- directory.
-
- Using:
- 1. Project options - directories - source directories: add \bc4\source.
- 2. Project options - directories - include directories: add \bc4\include.
- 3. In each source file that uses a library, be sure to #include the .h
- file.
- 4. In the project window, add any included .c or .lib files to the project
- tree.
-
- Support:
- Support is available via phone, BBS, email, or mail. See support.doc for
- details.
-
- The Library files:
- BC40Lib consists of the following library files:
- Edit - ascii file editor.
- Fileio - text and binary file i/o.
- Generic2 - miscellaneous routines.
- Graf - device independant graphics.
- Joystick - joystick routines.
- Keyboard - interrupt driven keyboard routines.
- Math2 - math routines.
- Mouse - mouse routines.
- Timer - timing routines.
- Help - ascii help file viewer with search and print.
- Getfile - file selection dialog box.
- Each library of routines has a .c or .obj file, and a .h file.
-
- A note on color variables:
- Anywhere that the library uses color variables, the allowable values
- are 0-15 or 0-255, depending on the current graphics mode. The values
- correspond to the pallete entries currently in effect. For a default
- CGA thru VGA 16 color palette the values are 0=black, 1=blue, 2=green,
- etc.
-
- A note on string variables:
- All string variables use null terminated strings. They are pointers to
- arrays of characters.
-
- A note on coordinate variables:
- All coordinate variable are virtual coordinates (0-10000 by 0-10000)
- unless otherwise noted.
-
- A note on fillstyle variables:
- All fillstyle variables ues the same values as the standard BGI.
-
- A note on 256 color palettes:
- All 256 color palettes are stored in an array[256] of palrec.
-
- A note on areas:
- All areas for fills, getting bitmaps, etc. are defined by the coordinates
- of the upper left (x1,y1) and lower right (x2,y2) corners.
-
- A note on text variables:
- All of the following text variable types use the standard values of the
- BGI: font, textsize, orientation, horizontal and vertical justifications,
- and scaling factors.
-
- ==============================================================================
-
- Edit.c:
- This library provides a basic ascii text editor that runs in graphics
- mode. It contains one routine:
-
- --------------------------------------------------------------------------
-
- void editfile(char *s,int fore,int fore2,int bak);
-
- S is the name of the ascii file to edit. Fore is text color. Fore2 is
- text shadow color. Bak is background color. This routine draws a large
- panel on the screen and shows the text on the panel. Editing keys work
- in the usual manner. Pressing Esc exits with an option to save. Example:
-
- #include <graphics.h>
- #include <edit.h>
- #include <graf.h>
- #include <mouse.h>
- void main()
- {
- vidmode=0;
- grafon();
- resetmouse();
- /* edit autoexec.bat using white text
- with black shadow on blue background. */
- editfile("c:\\autoexec.bat",15,0,1);
- closegraph();
- }
-
- ==============================================================================
-
- Fileio.c:
- This library provides easy to use routines for both text and binary file
- input and output. Use these routines instead of fopen, fread, etc. The
- routines in this library call fopen, fread, etc. for you with the proper
- parameters. This library's .h file includes stdio.h. This means you
- don't have to include stdio.h in files that include fileio.h. The
- routines in fileio.c are as follows:
-
- --------------------------------------------------------------------------
-
- int filefound(char *s);
-
- Searches for a file. S is the name of the file to search for. Returns a 1
- if the file is found, else returns a 0. Example:
-
- #include <fileio.h>
- void main()
- {
- if (filefound("c:\\autoexec.bat")) printf("autoexec found\n");
- else printf("autoexec not found\n");
- }
-
- --------------------------------------------------------------------------
-
- int readfile(FILE *f,char *s);
-
- Reads a string from an ascii text file. F is the file to read from.
- S is the string to read into. returns 1 on success, else returns 0.
- Example:
-
- #include <fileio.h>
- char s[100];
- FILE *f;
- void main()
- {
- f=infile("c:\\autoexec.bat");
- while (readfile(f,s)) printf("%s",s);
- fclose(f);
- }
-
- --------------------------------------------------------------------------
-
- int writefile(FILE *f,char *s);
-
- Writes a string to an ascii text file with a cr/lf. F is the file to
- write to. S is the string to write. Returns 1 on success, else returns 0.
- Example:
-
- #include <fileio.h>
- FILE *f;
- void main()
- {
- f=outfile("test.doc");
- writefile(f,"this is a test.");
- fclose(f);
- }
-
- --------------------------------------------------------------------------
-
- int writefile2(FILE *f,char *s);
-
- Writes a string to an ascii text file without a cr/lf. F is the file to
- write to. S is the string to write. Returns 1 on success, else returns 0.
- Example:
-
- #include <fileio.h>
- FILE *f;
- void main()
- {
- f=outfile("test.doc");
- writefile2(f,"this is");
- writefile(f," a test."); /* writes: this is a test. */
- fclose(f);
- }
-
- --------------------------------------------------------------------------
-
- FILE *infile(char *s);
-
- Opens an ascii text file for input. S is the name of the file to open.
- Returns a file pointer for the opened file. Example:
-
- #include <fileio.h>
- char s[100];
- FILE *f;
- void main()
- {
- f=infile("c:\\autoexec.bat");
- while (readfile(f,s)) printf("%s\n",s);
- fclose(f);
- }
-
- --------------------------------------------------------------------------
-
- FILE *outfile(char *s);
-
- Opens an ascii text file for output. S is the name of the file to open.
- Returns a file pointer for the newly opened file. Example:
-
- #include <fileio.h>
- FILE *f;
- void main()
- {
- f=outfile("test.doc");
- writefile(f,"this is a test.");
- fclose(f);
- }
-
- --------------------------------------------------------------------------
-
- FILE *appendfile(char *s);
-
- Opens an ascii file for appending output to the end of the file. S is the
- name of the file to open. Returns a file pointer to the newly opened
- file. Example:
-
- #include <fileio.h>
- FILE *f;
- void main()
- {
- f=appendfile("c:\\autoexec.bat");
- writefile(f,"echo Hello World!");
- fclose(f);
- }
-
- --------------------------------------------------------------------------
-
- FILE *appendfilebin(char *s);
-
- Opens a binary file for appending output to the end of the file. S is the
- name of the file to open. Returns a file pointer to the newly opened
- file. Example:
-
- #include <string.h>
- #include <fileio.h>
- struct addressrec
- {
- char name[20],address[50],phone[20];
- };
- struct addressrec r;
- FILE *f;
- void main()
- {
- strcpy(r.name,"Joe Blow");
- strcpy(r.address,"123 anystreet, Fairfax VA, 22033");
- strcpy(r.phone,"703-555-1212");
- f=appendfilebin("address.dat");
- writefilebin(f,&r,sizeof(r));
- fclose(f);
- }
-
- --------------------------------------------------------------------------
-
- FILE *infilebin(char *s);
-
- Opens a binary file for input. S is the name of the file to open. Returns
- a file pointer to the newly opened file. Example:
-
- #include <fileio.h>
- struct addressrec
- {
- char name[20],address[50],phone[20];
- };
- struct addressrec r;
- FILE *f;
- void main()
- {
- f=infilebin("address.dat");
- readfilebin(f,&r,sizeof(r));
- fclose(f);
- printf("%s\n",r.name);
- printf("%s\n",r.address);
- printf("%s\n",r.phone);
- }
-
- --------------------------------------------------------------------------
-
- FILE *outfilebin(char *s);
-
- Opens a binary file for output. S is the name of the file to open.
- Returns a file pointer to the newly opened file. Example:
-
- #include <fileio.h>
- struct addressrec
- {
- char name[20],address[50],phone[20];
- };
- struct addressrec r;
- FILE *f;
- void main()
- {
- strcpy(r.name,"Joe Blow");
- strcpy(r.address,"123 anystreet, Fairfax VA, 22033");
- strcpy(r.phone,"703-555-1212");
- f=outfilebin("address.dat");
- writefilebin(f,&r,sizeof(r));
- fclose(f);
- }
-
- --------------------------------------------------------------------------
-
- int readfilebin(FILE *f,void *rec,int recsize);
-
- Reads a record from a binary file. F is the file pointer of the file to
- read from. Rec points to the record to read into. Recsize is the size (in
- bytes) of the record to be read. Example:
-
- #include <fileio.h>
- struct addressrec
- {
- char name[20],address[50],phone[20];
- };
- struct addressrec r;
- FILE *f;
- void main()
- {
- f=infilebin("address.dat");
- readfilebin(f,&r,sizeof(r));
- fclose(f);
- printf("%s\n",r.name);
- printf("%s\n",r.address);
- printf("%s\n",r.phone);
- }
-
- --------------------------------------------------------------------------
-
- int writefilebin(FILE *f,void *rec,int recsize);
-
- Writes a record to a binary file. F is the file pointer of the file to
- write to. Rec points to the record to write. Recsize is the size (in
- bytes) of the record to be written. Example:
-
- #include <fileio.h>
- struct addressrec
- {
- char name[20],address[50],phone[20];
- };
- struct addressrec r;
- FILE *f;
- void main()
- {
- strcpy(r.name,"Joe Blow");
- strcpy(r.address,"123 anystreet, Fairfax VA, 22033");
- strcpy(r.phone,"703-555-1212");
- f=outfilebin("address.dat");
- writefilebin(f,&r,sizeof(r));
- fclose(f);
- }
-
- ==============================================================================
-
- Generic2.c:
-
- This library provides miscellaneous routines. It includes sound, keyboard,
- string, and dos routines. Routines are as follows:
-
- --------------------------------------------------------------------------
-
- void beep(int f, int d);
-
- Produces a beep on the PC's speaker. F is the frequency (in Hertz) of the
- beep. D is the duration of the beep in milliseconds. Example:
-
- #include <generic2.h>
- void main()
- {
- /* produces a beep similar to character 7, the bell character */
- beep(1000,100);
- }
-
- --------------------------------------------------------------------------
-
- void nokey();
-
- Waits until no keyboard keys are being pressed. Example:
-
- #include <stdio.h>
- #include <conio.h>
- #include <generic2.h>
- void main()
- {
- printf("Press a key to continue...\n");
- nokey();
- /* waits for no keystrokes, emptying keyboard buffer, then continues */
- getch(); /* gets a keystroke */
- }
-
- --------------------------------------------------------------------------
-
- int inserton();
-
- Returns 1 if insert is on, else returns 0. Example:
-
- #include <stdio.h>
- #include <generic2.h>
- void main()
- {
- if (inserton()) printf("insert is on\n");
- else printf("insert is off\n");
- }
-
- --------------------------------------------------------------------------
-
- void delchar(char *s,int first,int num);
-
- Deletes characters from a string. S is the (null terminated) string to
- delete characters from. First is the 1st character to delete (zero based,
- just like character arrays). Num is the number of characters to delete.
- Example:
-
- #include <stdio.h>
- #include <string.h>
- #include <generic2.h>
- void main()
- {
- strcpy(s,"joe blow");
- /* delete 5 characters from S, starting with character 3. */
- delchar(s,3,5);
- printf("%s\n",s); /* prints out "joe" */
- }
-
- --------------------------------------------------------------------------
-
- void copyfile(char *s,char *s2);
-
- Copies a file. S is the source filename. S2 is the destination filename.
- Example:
-
- #include <generic2.h>
- void main()
- {
- copyfile("c:\\autoexec.bat","c:\\autoexec.bak"); /* backup the autoexec */
- }
-
- --------------------------------------------------------------------------
-
- void chdrv(int i);
-
- Changes the current drive. I is the drive to change to (0=A:, 1=B:, 2=C:,
- etc.). Example:
-
- #include <generic2.h>
- void main()
- {
- chdrv(2); /* change to C: */
- }
-
- --------------------------------------------------------------------------
-
- int deviceready(char *s);
-
- Returns 1 if device s is ready. Otherwise returns 0. S can be: "prn",
- "lpt1", "lpt2", "lpt3", "com1", "com2", "com3", or "com4". Example:
-
- #include <generic2.h>
- #include <stdio.h>
- void main()
- {
- if (deviceready("prn")) printf("Printer is ready...\n");
- else printf("Error: printer not ready.\n");
- }
-
- --------------------------------------------------------------------------
-
- void stringcopy(char *fromstr,char *tostr,int startchar,int numchars);
-
- Copies part of a string to another string. Fromstr is the string to copy
- from. Tostr is the string to copy to. Startchar is the first character to
- copy (zero based). Numchars is the number of characters to copy. Example:
-
- #include <generic2.h>
- #include <stdio.h>
- #include <string.h>
- void main()
- {
- strcpy(s,"This is a test");
- stringcopy(s,s2,5,4);
- printf("%s\n",s2); /* prints "is a". */
- }
-
- --------------------------------------------------------------------------
-
- void doscommand(char *s);
-
- Executes a dos command. S is the command as you would enter it at the dos
- prompt. Example:
-
- #include <generic2.h>
- #include <stdio.h>
- #include <conio.h>
- void main()
- {
- char s[100],s2[100];
- printf("Enter search spec...\n");
- scanf("%s",s);
- strcpy(s2,"dir ");
- strcat(s2,s);
- doscommand(s2);
- printf("Press a key...\n");
- getch();
- }
-
- --------------------------------------------------------------------------
-
- void slash(char *s);
-
- Adds a backslash to the end of string s if the last character is not a
- backslash. Use this to add a backslash (if needed) to a directory name
- before adding a filename to the end of the dirctory name. Example:
-
- #include <generic2.h>
- #include <string.h>
- void main()
- {
- char s[100];
- strcpy(s,"c:\\"); /* s = "c:\" */
- slash(s); /* s = "c:\" */
- strcat(s,"command.com"); /* s = "c:\command.com" */
- strcpy(s,"c:\\dos"); /* s = "c:\dos" */
- slash(s); /* s = "c:\dos\" */
- strcat(s,"edit.exe"); /* s = "c:\dos\edit.exe" */
- }
-
- --------------------------------------------------------------------------
-
- void filenameonly(char *fullname,char *filename);
-
- Returns the filename and extension of a full filename. Fullname is the
- complete filename (drive, directory, filename, and extension). The
- filename with extension is returned in the string <filename>. Example:
-
- #include <generic2.h>
- #include <string.h>
- void main()
- {
- char s[100],s2[100];
- strcpy(s,"c:\\command.com");
- filenameonly(s,s2); /* returns "command.com" in s2 */
- }
-
- --------------------------------------------------------------------------
-
- long diskfree(int i);
-
- Returns the number of bytes free on a disk. I is the disk (0=current
- drive, 1=A:, 2=B:, 3=C:, etc). Returns -1 if i is not a valid drive.
-
- ==============================================================================
-
- Graf.c:
- This library provides device independant graphics. It works on a virtual
- coordinate system 0 to 10000 by 0 to 10000 which is then automatically
- mapped to the resolution of the video mode being run (ie 640x480,
- 1024x768, etc.). It contains a wide range of routines for graphics.
- It also declares some data structures for use in graphics programming.
- Data structures are as follows:
-
- --------------------------------------------------------------------------
-
- struct palrec
- {
- unsigned char redval,greenval,blueval;
- };
-
- This record type holds the information for one palette entry of a 256
- color palette. It is usually used as the element of an array[256] which
- is a 256 color palette (ie: struct palrec mypal[256]; ). Example:
-
- #include <graphics.h>
- #include <graf.h>
- /* note that PAL, a 256 color palette, is declared as an array[256]
- (ie 0 to 255) of palrec! */
- struct palrec pal[256];
- void main()
- {
- grafmode=1;
- grafon();
- getallrgbpalette(pal); /* copy current palette into PAL */
- savepal("default.pal",pal); /* save PAL to disk */
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- extern int graffontsize;
-
- This variable is set automatically by the grafon() routine. It is the
- text size used by the menus, dialog boxes, etc in the BC 40 Lib library.
- It is set so that text will be approximately the same size reguardless of
- what video mode you are running. Use it in your saygraf, saygraf3d, and
- settextstyle calls to keep text device independant. It is designed to
- yield approximately 3/8 inch tall characters when font #2 (litt.chr) is
- used. Example:
-
- #include <conio.h>
- #include <graphics.h>
- #include <graf.h>
- void main()
- {
- vidmode=0;
- grafon();
- saygraf3d(5000,5000,15,7,2,graffontsize,0,1,1,1,1,1,1,"Hello world!");
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- extern int vidmode;
-
- This variable is set by you before you call grafon(). It tells grafon()
- what graphics mode to go into. It also can be used to determine what
- graphics mode you're in once you call grafon(). Allowable values are:
- 0 - vga 640x350x16 2 vid pages
- 1 - vga 648x480x16
- 2 - vga 320x200x256*
- 3 - vesa svga 640x400x256*
- 4 - vesa svga 640x480x256*
- 5 - vesa svga 800x600x256*
- 6 - vesa svga 1024x768x256*
- * requires bgi256v2.bgi, a popular sharware VESA SVGA bgi driver
- (not included).
- Example:
-
- #include <graphics.h>
- #include <conio.h>
- #include <graf.h>
- void main()
- {
- vidmode=1; /* set graphics to start in 640x480x16 VGA. */
- grafon(); /* go to graphics mode */
- saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,"Hello world!");
- getch();
- closegraph(); /* end graphics mode, return to text mode */
- }
-
- --------------------------------------------------------------------------
-
- extern char m[25][100];
-
- This array of strings is used by the menus and dialog boxes in the Graf
- library. It is used to hold menu options, or dialog box text. When
- you aren't calling routines that use the array, you may use it for your
- own purposes. To use it with a routine such as a menu, you first copy
- the desired strings into the array, and then call the menu routine. The
- menu routine will use the text in the array for the menu. Example:
-
- #include <graf.h>
- #include <graphics.h>
- #include <mouse.h>
- #include <string.h>
- int i;
- void main()
- {
- vidmode=1;
- grafon();
- resetmouse();
- /* load menu options into array */
- strcpy(m[0],"Please select...");
- strcpy(m[1],"Yes");
- strcpy(m[2],"No");
- /* call menu routine */
- i=popupmenu(-1,-1,2,15,0,1,1);
- if (i==1)
- saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,"Yes selected");
- else saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,"No selected");
- nobutton();
- do
- {
- }
- while (mousebutton()==0);
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void loadpal(char *s, struct palrec *pal);
-
- This routine loads a 256 color palette from disk into an array[256] of
- palrec. S is the filename of the palette data file to load. Pal is a
- pointer to an array[256] of palrec that the palette will be read into.
- Example:
-
- #include <conio.h>
- #include <graphics.h>
- #include <graf.h>
- struct palrec pal[256];
- void main()
- {
- grafmode=2;
- grafon();
- loadpal("test.pal",pal); /* load test.pal from disk into PAL*/
- setallrgbpalette(pal); /* set palette to PAL */
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void savepal(char *s, struct palrec *pal);
-
- Saves a 256 color palette to disk. S is the name of the palette data file
- to create. Pal is a pointer to an array[256] of palrec, which is the
- palette to be saved. Example:
-
- #include <graphics.h>
- #include <graf.h>
- struct palrec pal[256];
- void main()
- {
- grafmode=1;
- grafon();
- getallrgbpalette(pal); /* copy current palette into PAL */
- savepal("default.pal",pal); /* save PAL to disk */
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void setallrgbpalette(struct palrec *pal);
-
- Sets the computer's 256 color palette. Pal points to an array[256] of
- palrec that contains the new values for the computer's palette. Uses
- a rom bios interrupt call to set the palette. Example:
-
- #include <conio.h>
- #include <graphics.h>
- #include <graf.h>
- struct palrec pal[256];
- void main()
- {
- grafmode=2;
- grafon();
- loadpal("test.pal",pal); /* load test.pal from disk into PAL*/
- setallrgbpalette(pal); /* set palette to PAL */
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- int x2vidx(int x);
-
- Converts a virtual x coordinate to a hardware x coordinate. X is the
- virtual x coordinate to convert. Returns the hardware x coordinate.
- Example:
-
- #include <graf.h>
- #include <graphics.h>
- #include <stdio.h>
- int i;
- void main()
- {
- vidmode=2; /* 640x480x16 */
- grafon();
- i=x2vidx(10000);
- closegraph();
- printf("%d\n",i); /* prints 639 */
- }
-
- --------------------------------------------------------------------------
-
- int y2vidy(int y);
-
- Converts a virtual y coordinate to a hardware y coordinate. Y is the
- virtual y coordinate to convert. Returns the hardware y coordinate.
- Example:
-
- #include <graf.h>
- #include <graphics.h>
- #include <stdio.h>
- int i;
- void main()
- {
- vidmode=2; /* 640x480x16 */
- grafon();
- i=y2vidy(10000);
- closegraph();
- printf("%d\n",i); /* prints 479 */
- }
-
- --------------------------------------------------------------------------
-
- int mousex2x(int x);
-
- Converts a harware or mouse x coordinate to a virtual x coordinate. X is
- the hardware or mouse x coordinate to convert. Returns the virtual x
- coordinate. Example:
-
- #include <graf.h>
- #include <graphics.h>
- #include <stdio.h>
- int i;
- void main()
- {
- vidmode=2; /* 640x480x16 */
- grafon();
- i=mousex2x(639);
- closegraph();
- printf("%d\n",i); /* prints 10000 */
- }
-
- --------------------------------------------------------------------------
-
- int mousey2y(int y);
-
- Converts a harware or mouse y coordinate to a virtual y coordinate. Y is
- the hardware or mouse y coordinate to convert. Returns the virtual y
- coordinate. Example:
-
- #include <graf.h>
- #include <graphics.h>
- #include <stdio.h>
- int i;
- void main()
- {
- vidmode=2; /* 640x480x16 */
- grafon();
- i=mousey2y(479);
- closegraph();
- printf("%d\n",i); /* prints 10000 */
- }
-
- --------------------------------------------------------------------------
-
- void grafpie(int x, int y, int startangle, int endangle, int radius,
- int color, int fillstyle);
-
- Draws a filled pieslice. x,y are the point of the pieslice. Startangle is
- the angle (in degrees) of the beginning edge of the pieslice. Endangle
- is the angle (in degrees) of the ending edge of the pieslice. Radius is
- the radius of the pieslice in virual coordinates. Color is the color of
- the pieslice, and Fillstyle is the fill pattern used to fill the pieslice.
- Example:
-
- #include <graf.h>
- #include <graphics.h>
- #include <conio.h>
- void main()
- {
- vidmode=1;
- grafon();
- pieslice(5000,5000,0,45,4000,14,9);
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void *grafload(char *s);
-
- Loads a bitmap from disk. S is the filename of the bitmap to load from
- disk. Returns a pointer to the bitmap. Once you're done with the bitmap,
- don't forget to dispose of it by calling free(). Example:
-
- #include <conio.h>
- #include <graf.h>
- #include <graphics.h>
- void *p;
- void main()
- {
- vidmode=1;
- grafon();
- p=grafload("bitmap1.grf");
- grafput(0,0,0,p);
- free(p);
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void grafsave(char *s,void *p);
-
- Saves a bitmap to disk. S is the filename to save as. P points to the
- bitmap to save. Once you're done with a bitmap, don't forget to dispose
- of it by calling free(). Example:
-
- #include <graf.h>
- #include <graphics.h>
- void *p;
- void main()
- {
- vidmode=1;
- grafon();
- fillgraf(2000,2000,3000,3000,14,9);
- p=grafget(1000,1000,4000,4000);
- grafsave("test.grf",p);
- free(p);
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void getallrgbpalette(struct palrec *pal);
-
- Gets the current 256 color palette. Puts the current palette values into
- Pal. Example:
-
- #include <graphics.h>
- #include <graf.h>
- struct palrec pal[256];
- void main()
- {
- grafmode=1;
- grafon();
- getallrgbpalette(pal); /* copy current palette into PAL */
- savepal("default.pal",pal); /* save PAL to disk */
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void fillgraf(int x1,int y1,int x2,int y2,int color,int fill);
-
- Fills a rectangular area with a color and fillstyle. x1,y1,x2,y2 are
- the coordinates of the area to fill. Color is the color to fill the area
- with. Fill is the fillstyle to use when filling the area. Example:
-
- #include <conio.h>
- #include <graf.h>
- #include <graphics.h>
- void main()
- {
- grafmode=1;
- grafon();
- fillgraf(1000,1000,2000,2000,14,9);
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void clsgraf(int color,int fill);
-
- Clears the screen. Color is the color to be used. Fill is the fillstyle
- to be used. Example:
-
- #include <conio.h>
- #include <graf.h>
- #include <graphics.h>
- void main()
- {
- vidmode=1;
- grafon();
- clsgraf(14,9);
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void grafon();
-
- Turns on graphics. Use instead of initgraph(). Set vidmode to the
- desired video mode before calling grafon(). This routine sets
- graffontsize according to the vidmode selected. Don't forget to
- use closegraph() to turn off graphics mode when you're done with
- graphics mode. Example:
-
- #include <conio.h>
- #include <graf.h>
- #include <graphics.h>
- void main()
- {
- vidmode=1;
- grafon();
- saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,"640x480x16");
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void saygraf3d(int x, int y, int fore, int bak, int font, int size,
- int orientation, int hjust, int vjust, int xmul, int xdiv,
- int ymul, int ydiv,const char *s);
-
- Writes 3D text on the screen. Writes text at position x,y. Fore and
- Bak are the text and text shadow colors. Font is the font to use.
- Size is the size of the text. Orientation is 0 for horizontal, or
- 1 for vertical. Hjust and Vjust are the horizontal and vertical
- justification to use. They work the same as in the BGI routine
- settextjustify(). Xmul, Xdiv, Ymul, and Ydiv are scaleing factors. They
- work the same as in the BGI routine setusercharsize(). S is the string of
- text to write to the screen. Example:
-
- #include <conio.h>
- #include <graf.h>
- #include <graphics.h>
- void main()
- {
- vidmode=1;
- grafon();
- saygraf3d(5000,5000,15,7,2,graffontsize,0,1,1,1,1,1,1,"3D Text");
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void saygraf(int x, int y, int fore, int font, int size, int orientation,
- int hjust, int vjust, int xmul, int xdiv, int ymul, int ydiv,
- char *s);
-
- Writes text on the screen. Writes text at position x,y. Fore is the text
- color. Font is the font to use. Size is the size of the text. Orientation
- is 0 for horizontal, or 1 for vertical. Hjust and Vjust are the
- horizontal and vertical justification to use. They work the same as in
- the BGI routine settextjustify(). Xmul, Xdiv, Ymul, and Ydiv are
- scaleing factors. They work the same as in the BGI routine
- setusercharsize(). S is the string of text to write to the screen.
- Example:
-
- #include <conio.h>
- #include <graf.h>
- #include <graphics.h>
- void main()
- {
- vidmode=1;
- grafon();
- saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,"This is some text");
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void *grafget(int x1,int y1,int x2,int y2);
-
- Gets an area from the screen and stores it in a bitmap. x1,y1,x2,y2 are
- the coordinates of the area to get. Returns a pointer to the bitmap.
- Don't forget to dispose of the bitmap when you're done with it by calling
- free(). Example:
-
- #include <graf.h>
- #include <graphics.h>
- void *p;
- void main()
- {
- vidmode=1;
- grafon();
- fillgraf(2000,2000,3000,3000,14,9);
- p=grafget(1000,1000,4000,4000);
- grafsave("test.grf",p);
- free(p);
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void grafline(int x1,int y1,int x2,int y2,int color,int style,
- int thickness);
-
- Draws a line. x1,y1 and x2,y2 are the endpoints of the line. Color is
- the color to use. Style is the line style. It uses standard BGI line
- style constants just like the standard BGI routine setlinestyle() does.
- Thickness is the line thickness. It uses standard BGI line thickness
- constants just like the standard BGI routine setlinestyle(). Example:
-
- #include <conio.h>
- #include <graf.h>
- #include <graphics.h>
- void main()
- {
- vidmode=1;
- grafon();
- grafline(1000,1000,9000,9000,15,0,1);
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void grafpix(int x, int y, int color);
-
- Draws a pixel on the screen. X,Y are the pixel coordinates. Color is the
- color to draw the pixel. Example:
-
- #include <conio.h>
- #include <graf.h>
- #include <graphics.h>
- int i;
- void main()
- {
- vidmode=1;
- grafon();
- for (i=0; i<=10000; i+=100) grafpix(i,i,15);
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void panel(int x1, int y1, int x2, int y2, int color, int pressed);
-
- Draws a beveled panel. x1,y1,x2,y2 is the area the panel covers. Color
- is the panel color. Pressed is a boolean. Set Pressed = 1 for pressed
- in look. Set Pressed = 0 for popped out look. Example:
-
- #include <conio.h>
- #include <graf.h>
- #include <graphics.h>
- int i;
- void main()
- {
- vidmode=1;
- grafon();
- panel(3000,3000,7000,7000,7,0);
- panel(4000,4000,5000,4500,9,0);
- panel(4000,5000,5000,5500,7,1);
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void graftri(int x1,int y1,int x2,int y2,int x3,int y3,int color,
- int fill);
-
- Draws a triangle. x1,y1,xc2,y2,x3,y3 are the corners of the triangle.
- Color and Fill are the color and fillstyle for the triangle. Example:
-
- #include <conio.h>
- #include <graf.h>
- #include <graphics.h>
- int i;
- void main()
- {
- vidmode=1;
- grafon();
- graftri(1000,9000,5000,1000,9000,9000,13,10);
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void grafput(int x, int y, int put, void *p);
-
- Puts a bitmap to the screen. x,y is the upper left corner for the bitmap.
- Put is a standard BGI put type constant just like in the standard BGI
- routine putimage(). Note that you may also use the extended put types
- available with BGI256V2.BGI, a popular shareware VESA SVGA BGI driver.
- Example:
-
- #include <conio.h>
- #include <graf.h>
- #include <graphics.h>
- void *p;
- void main()
- {
- vidmode=1;
- grafon();
- p=grafload("bitmap1.grf");
- grafput(0,0,0,p);
- free(p);
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void grafmsg(int x, int y, int i, int fore,int fore2, int bak,
- int doclick,int dopause, int doprint);
-
- Displays a message box. x,y are the upper left corner of the box. If
- x=-1, box will be centered left to right. If y=-1, box will be centered
- top to bottom. I is the index of the last string in the message (ie. for
- a message that uses m[0] thru m[7], i=7). Fore and Fore2 are the text and
- text shadow colors. Bak is the box color. Uses the global array of
- strings m[] to hold the text.
- If doprint=1: the box won't be drawn at all, and the contents will be
- printed to PRN. Dopause and Doclick are ignored.
- If doprint=0: If dopause=1: the screen behind the box will be saved, and
- the last line of the message box will read
- "Press P to print or a mouse button to
- continue...". When a mouse button is pressed,
- the screen will be restored. If the user
- presses P, the text of the box will be
- printed on device PRN. If doclick=1, the
- speaker will make a click sound when the
- mouse is pressed to clear the message box.
- If doclick=0, no sound will be made.
- If dopause=0: the box will be drawn, and grafmsg will then
- return. doclick is ignored.
- Example:
-
- #include <string.h>
- #include <graf.h>
- #include <graphics.h>
- #include <mouse.h>
- void main()
- {
- vidmode=1;
- grafon();
- resetmouse();
- strcpy(m[0],"This is a message box");
- strcpy(m[1],"Text of the message goes here");
- grafmsg(-1,-1,1,15,0,1,1,1,0);
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void grafrect(int x1,int y1,int x2,int y2,int color,int style,
- int thickness);
-
- Draws a rectangle. x1,y1,x2,y2 is the area covered by the rectangle.
- Color and Style are the color and fill style for the rectangle. Thickness
- is the line thickness for the edges of the rectangle. Example:
-
- #include <conio.h>
- #include <graf.h>
- #include <graphics.h>
- void main()
- {
- vidmode=1;
- grafon();
- grafrect(1000,1000,3000,2000,12,3,1);
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void clsstars();
-
- Clears the screen, using a stary background. Example:
-
- #include <conio.h>
- #include <graf.h>
- #include <graphics.h>
- void main()
- {
- vidmode=1;
- grafon();
- clsstars();
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void select(int *x, int *y,int doclick);
-
- Gets a selection using the mouse. Shows the mouse, waits for a button to
- be pressed, then hides the mouse and returns the mouse position in
- virtual coordinates. X,Y return the mouse's position when a button is
- pressed. If doclick=1, the speaker will make a click sound when the mouse
- button is pressed. If doclick=0, no click sound will be made. Example:
-
- #include <graf.h>
- #include <graphics.h>
- #include <mouse.h>
- #include <stdio.h>
- int x,y;
- void main()
- {
- vidmode=1;
- grafon();
- resetmouse();
- select(&x,&y,1);
- closegraph();
- printf("x=%d y=%d\n",x,y);
- }
-
- --------------------------------------------------------------------------
-
- int popupmenu(int x,int y,int i,int fore,int fore2,int bak,int doclick);
-
- Does a popup menu. Menu appears, mouse appears, once an option is
- selected, mouse disappears, then menu disappears. x,y is the upper left
- corner of the menu. If x=-1, menu is centered left to right. If y=-1,
- menu is centered top to bottom. Uses global string array m[] to hold the
- title (m[0]) and options (m[1], m[2], etc). I is the index of the last
- string used (ie for a menu that uses m[0] thru m[2], i=2). Fore and Fore2
- are the text and text shadow colors. Bak is the menu color. If Doclick=1,
- the speaker will click when the mouse button is pressed. If Doclick=0,
- no click will be made. Returns the number of the menu option selected (ie
- returns 1 if they select the 1st menu option, 2 if they select the second
- menu option, etc). Example:
-
- #include <graf.h>
- #include <graphics.h>
- #include <mouse.h>
- #include <string.h>
- int i;
- void main()
- {
- vidmode=1;
- grafon();
- resetmouse();
- /* load menu options into array */
- strcpy(m[0],"Please select...");
- strcpy(m[1],"Yes");
- strcpy(m[2],"No");
- /* call menu routine */
- i=popupmenu(-1,-1,2,15,0,1,1);
- if (i==1)
- saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,"Yes selected");
- else saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,"No selected");
- nobutton();
- do
- {
- }
- while (mousebutton()==0);
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void getstr(char *promptstr,char *returnstr,int fore,int fore2,int bak);
-
- Lets the user edit a string. Draws a dialog box, displays a prompt, then
- lets the user edit a string. Promptstr is the prompt string. Returnstr
- is the string to edit. Returnstr also returns the string edited by the
- user. Fore and Fore2 are text and text shadow colors. Bak is dialog box
- color. Example:
-
- #include <stdio.h>
- #include <graf.h>
- #include <graphics.h>
- char s[100];
- void main()
- {
- vidmode=1;
- grafon();
- strcpy(s,"");
- getstr("Enter a string...",s,15,0,1);
- closegraph();
- printf("%s\n",s);
- }
-
- --------------------------------------------------------------------------
-
- int getnum(char *promptstr,int fore,int fore2,int bak,int doclick);
-
- Gets an integer from the user, using a popup numeric keypad. Keypad
- appears with a prompt, then the mouse appears. Once the user enters
- a number and selects ok, the mouse disappears, then the keypad
- disappears. Promptstr is the prompt string. Fore and Fore2 are the text
- text shadow colors. Bak is the keypad color. If doclick=1, the speaker
- will click when a mouse button is pressed. If doclick=0, the speaker will
- not click. Returns the integer the user entered. The keypad has keys 0
- thru 9, C (clear), and Ok. Example:
-
- #include <stdio.h>
- #include <graf.h>
- #include <graphics.h>
- #include <mouse.h>
- int i;
- void main()
- {
- vidmode=1;
- grafon();
- resetmouse();
- i=getnum("Enter a number...",15,0,1,1);
- closegraph();
- printf("%d\n",i);
- }
-
- --------------------------------------------------------------------------
-
- void getfile(char *promptstr, char *searchspec, char *returnstr,int fore,
- int fore2,int bak,int doclick);
-
- Gets a filename from the user. Displays a menu listing files. The menu
- has More and Cancel options as well as filenames. Shows the mouse, and
- lets the user select from the menu. Returns the filename selected.
- Returns an empty string (ie "") for cancel. Promptstr is the prompt that
- appears as the menu title. Searchspec is the file search spec for the
- list of filenames. Wildcard characters are allowed in the search
- filespec. Returnstr returns the selected filename. Fore and Fore2 are
- text and text shadow colors. Bak is menu color. If doclick=1, speaker
- will click when a mouse button is pressed. If doclick=0 , speaker will
- not click. Example:
-
- #include <stdio.h>
- #include <graf.h>
- #include <graphics.h>
- #include <mouse.h>
- char s[100];
- void main()
- {
- vidmode=1;
- grafon();
- resetmouse();
- getfile("Select a file...","c:\\*.*",s,15,0,1,1);
- closegraph();
- printf("%s\n",s);
- }
-
- --------------------------------------------------------------------------
-
- void setborder(int i);
-
- Sets the border color. I is the color for the border. Does not work on
- all hardware. Example:
-
- #include <conio.h>
- #include <graf.h>
- #include <graphics.h>
- void main()
- {
- vidmode=1;
- grafon();
- setborder(1);
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- int getcol(char *s,int fore,int fore2,int bak,int doclick);
-
- Gets a color from the user. Displays a menu of colors. Lets the user
- select a color with the mouse. Returns the color selected. S is the
- prompt string for the color menu. Fore and Fore2 are the text and text
- shadow colors. Bak is the menu color. If doclick=1, speaker
- will click when a mouse button is pressed. If doclick=0 , speaker will
- not click. This routine will automaticaly use either a 16 color or 256
- color menu, depending on the current video mode. Example:
-
- #include <stdio.h>
- #include <graf.h>
- #include <graphics.h>
- #include <mouse.h>
- int i;
- void main()
- {
- vidmode=1;
- grafon();
- resetmouse();
- i=getcol("Select a color...",15,0,1,1);
- closegraph();
- printf("%d\n",i);
- }
-
- --------------------------------------------------------------------------
-
- int getfill(char *s,int fore,int fore2,int bak,int color,int doclick);
-
- Gets a fillstyle from the user. Shows a menu of fill styles. Lets the
- user select a fillstyle with the mouse. Returns the fillstyle selected.
- S is the prompt string for the fillstyle menu. Fore and Fore2 are the
- text and text shadow colors. Bak is the menu color. Color is the color
- for the fillpatterns in the menu. If doclick=1, speaker will click when a
- mouse button is pressed. If doclick=0 , speaker will not click. Example:
-
- #include <stdio.h>
- #include <graf.h>
- #include <graphics.h>
- #include <mouse.h>
- int i;
- void main()
- {
- vidmode=1;
- grafon();
- resetmouse();
- i=getfill("Select a fillstyle...",15,0,1,14,1);
- closegraph();
- printf("%d\n",i);
- }
-
- --------------------------------------------------------------------------
-
- void getarea(int x1,int y1,int *x2,int *y2);
-
- Gets an area from the user. Shows the mouse, waits for the user to select
- the upper left corner of the area. Then does a rubberband box while the
- user moves to the lower right corner. When the user selects the lower
- right corner, the rubber band box disappears. The uppper left and lower
- right coordinates of the area selected are returned in x1,y1,x2,y2.
- Example:
-
- #include <conio.h>
- #include <graf.h>
- #include <graphics.h>
- #include <mouse.h>
- int x1,y1,x2,y2;
- void main()
- {
- vidmode=1;
- grafon();
- resetmouse();
- saygraf(5000,500,15,2,graffontsize,0,1,1,1,1,1,1,"Select an area...");
- getarea(x1,y1,x2,y2);
- fillgraf(x1,y1,x2,y2,14,4);
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- int getpix(int x,int y);
-
- Gets the current color of a pixel. x,y are the pixel's coordinates.
- Returns the pixel's color. Example:
-
- #include <stdio.h>
- #include <graf.h>
- #include <graphics.h>
- int i;
- void main()
- {
- vidmode=1;
- grafon();
- i=getpix(5000,5000);
- closegraph();
- printf("%d\n",i);
- }
-
- --------------------------------------------------------------------------
-
- void fillstars(int x1,int y1,int x2,int y2);
-
- Fills an area with a stary pattern. x1,y1,x2,y2 are the area's
- coordinates. Example:
-
- #include <conio.h>
- #include <graf.h>
- #include <graphics.h>
- void main()
- {
- vidmode=1;
- grafon();
- fillstars(1000,1000,5000,5000);
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void grafcircle(int x,int y,int rad,int color,int style,int thickness);
-
- Draws a filled circle. x,y is the center of the circle. Rad is the
- radius. Color and Style are the fill color and fill style to use.
- Thickness is the line thickness for the edge of the circle. Example:
-
- #include <conio.h>
- #include <graf.h>
- #include <graphics.h>
- void main()
- {
- vidmode=1;
- grafon();
- grafcircle(5000,5000,1000,4,7,1);
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void wait4retrace(void);
-
- Waits until the beginning of the next vertical retrace. Use this to time
- your screen updates with the CRT's vertical retrace interval to reduce
- flicker. Example:
-
- #include <graf.h>
- #include <graphics.h>
- void main()
- {
- int i;
- vidmode=1;
- grafon();
- clsgraf(0,1);
- for (i=0; i<9000; i++)
- {
- waitforretrace();
- fillgraf(i,4000,i+1000,5000,15,1);
- waitforretrace();
- fillgraf(i,4000,i+1000,5000,0,1);
- }
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void fadeout(void);
-
- Fades a 256 color palette to black. Example:
-
- #include <graf.h>
- #include <graphics.h>
- #include <math2.h>
- #include <stdlib.h>
- void main()
- {
- int i,j,k;
- randomize();
- vidmode=2;
- grafon();
- clsgraf(0,1);
- for (i=0; i<9000; i++)
- {
- j=dice(9000);
- k=dice(9000);
- fillgraf(j,k,j+1000,k+,dice(15),dice(11));
- }
- fadeout();
- closegraph();
- }
-
-
- --------------------------------------------------------------------------
-
- void fadein(struct palrec *pal);
-
- Fades in a 256 color palette from black. Example:
-
- #include <graf.h>
- #include <graphics.h>
- #include <math2.h>
- #include <stdlib.h>
- void main()
- {
- int i,j,k;
- struct palrec pal[256],pal2[256];
- randomize();
- vidmode=2;
- grafon();
- clsgraf(0,1);
- memset(pal,0,sizeof(pal));
- getallrgbpalette(pal2);
- setallrgbpalette(pal);
- for (i=0; i<9000; i++)
- {
- j=dice(9000);
- k=dice(9000);
- fillgraf(j,k,j+1000,k+,dice(15),dice(11));
- }
- fadein(pal2);
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- char getdrv(char *s, int fore, int fore2, int bak, int doclick);
-
- Lets the user select a drive from a menu. Returns the letter of the
- selected drive. Returns ' ' (a space) if user cancels. S is the prompt
- for the menu. Fore is the text color. Fore2 is the text shadow color.
- Bak is the menu color. Example:
-
- #include <graf.h>
- #include <graphics.h>
- #include <generic2.h>
- void main()
- {
- char c;
- vidmode=1;
- grafon();
- c=getdrv("Change to drive...");
- if (c != ' ') chdrv(c);
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void refreshon(void);
-
- Turns on video refresh. Use with refreshoff() to control video refresh.
- NOTE: Turning refresh off is like turning down the monitor brightness all
- the way - I.E. the screen goes black. Example:
-
- #include <graf.h>
- #include <graphics.h>
- #include <conio.h>
- void main()
- {
- struct palrec pal[256];
- vidmod=2;
- grafon();
- getallrgbpalette2(pal);
- fadeout();
- refreshoff();
- /* draw stuff now. drawing goes faster with refresh off supposedly. */
- refreshon();
- fadein(pal);
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void refreshoff(void);
-
- Turns off video refresh. Use with refreshon() to control video refresh.
- NOTE: Turning refresh off is like turning down the monitor brightness all
- the way - I.E. the screen goes black. Example:
-
- #include <graf.h>
- #include <graphics.h>
- #include <conio.h>
- void main()
- {
- struct palrec pal[256];
- vidmod=2;
- grafon();
- getallrgbpalette2(pal);
- fadeout();
- refreshoff();
- /* draw stuff now. drawing goes faster with refresh off supposedly. */
- refreshon();
- fadein(pal);
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void getgrafsize(void *p, int *x, int *y);
-
- Gets the size of a bitmap. P points to the bitmap. The width is returned
- in X, the height in Y. The size returned is in hardware coordinates
- (pixels), not BC40LIB GRAF coordinates. Use mousex2x() and mousey2y() to
- convert to GRAF coordinates. Example:
-
- #include <graf.h>
- #include <graphics.h>
- #include <stdlib.h>
- void main()
- {
- int x,y;
- void *p;
- vidmode=2; /* 320x200x256 */
- grafon();
- p=grafget(0,0,10000,10000); /* get entire screen */
- getgrafsize(p,&x,&y);
- /* x is now 320. y is now 200. */
- x=mousex2x(x);
- y=mousey2y(y);
- /* x is now 10000. y is now 10000 */
- free(p);
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void grafcopy(int x,int y,void *p,void *p2);
-
- Copies a bitmap into another bitmap. P is the source bitmap to copy. P2
- is the target bitmap to copy into. The copy is done offscreen in memory.
- The source bitmap is copied into the target bitmap beginning at
- offset x,y from the upper left corner of the target bitmap. This routine
- is currently under construction. Do not use it. It doesn't work yet. This
- description is included to keep you from wondering what it is.
-
- --------------------------------------------------------------------------
-
- void setallrgbpalette2(struct palrec *pal);
-
- Sets the computer's 256 color palette. Pal points to an array[256] of
- palrec that contains the new values for the computer's palette. Uses
- port addressing to set the palette. Appears to be slightly faster than
- setallrgbpalette() which uses a bios call to set the palette. Example:
-
- #include <conio.h>
- #include <graphics.h>
- #include <graf.h>
- struct palrec pal[256];
- void main()
- {
- grafmode=2;
- grafon();
- loadpal("test.pal",pal); /* load test.pal from disk into PAL*/
- setallrgbpalette(pal); /* set palette to PAL */
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void setrgbpalette2(int regnum,int red,int green,int blue);
-
- As BC40's setrgbpalette(). Sets a 256 color palette register using a rom
- bios interrupt call. Appears to be slightly faster than BC40's
- setrgbpalette() routine. Example:
-
- #include <graphics.h>
- #include <graf.h>
- #include <conio.h>
- void main()
- {
- int i;
- grafmode=2;
- grafon();
- clsgraf(0,1); /* clear screen to black */
- for (i=0; i<256; i++) /* fade in red */
- setrgbpalette2(0,i,0,0);
- getch();
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- void setrgbpalette3(int regnum,int red,int green,int blue);
-
- As BC40's setrgbpalette(). Sets a 256 color palette register using port
- Addressing. Appears to be slightly faster than setrgbpalette2() which
- uses a bios call. Example:
-
- #include <graphics.h>
- #include <graf.h>
- #include <conio.h>
- void main()
- {
- int i;
- grafmode=2;
- grafon();
- clsgraf(0,1); /* clear screen to black */
- for (i=0; i<256; i++) /* fade in purple */
- setrgbpalette2(0,i,0,i);
- getch();
- closegraph();
- }
-
- ==============================================================================
-
- Joystick.c:
- This library provides joystick support routines. Variables and routines
- are as follows:
-
- --------------------------------------------------------------------------
-
- extern int hasstick;
-
- Boolean variable set by detectstick(). Hasstick=1 means a game port is
- connected. A joystick may or may not be connected to the game port.
- Detectstick can't tell if there's a joystick, only a game port.
- Hasstick=0 means no game port found, therefore no joystick. Example:
-
- #include <stdio.h>
- #include <joystick.h>
- void main()
- {
- detectstick();
- if (hasstick) printf("Game port found\n");
- else printf("No game port found\n");
- }
-
- --------------------------------------------------------------------------
-
- void getstik(int *x, int *y, int *b1, int *b2);
-
- Gets the current joystick status. Returns joystick information in x,y,b1,
- and b2. X and y are numbers returned by the stick that indicate position.
- The minimum and maximum values returned for x and y depend on computer
- speed, and will vary from machine to machine. For x, the minimum value is
- all the way left. For y, the minimum value is all the way forward.
- Because the minimum and maximum values for x and y vary with machine, you
- will need to write a joystick calibration routine to determine the
- minimum and maximum x and y values returned. B1 and B2 return the status
- of the buttons. B1 is for button #1, and B2 is for button #2. A value of
- 1 indicates pressed, 0 means not pressed. Example:
-
- #include <stdio.h>
- #include <joystick.h>
- int x,y,b1,b2;
- void main()
- {
- printf("move stick to upper left and press button 1...\n");
- do
- {
- getstik(&x,&y,*b1,&b2);
- }
- while (b1==0);
- printf("minimum x value is %d\n",x);
- printf("minimum y value is %d\n",y);
- }
-
- --------------------------------------------------------------------------
-
- void nostikbutton();
-
- Waits until no joystick buttons are being pressed. Example:
-
- #include <stdio.h>
- #include <joystick.h>
- int x,y,b1,b2;
- void main()
- {
- printf("press joystick button 1...\n");
- do
- {
- getstik(&x,&y,*b1,&b2);
- }
- while (b1==0);
- printf("button 1 pressed\n");
- nostikbutton();
- printf("button 1 released\n");
- }
-
- --------------------------------------------------------------------------
-
- void detectstick();
-
- Checks for existance of a game port. Sets the global variable Hasstick to
- 1 if a game port is found, else sets hasstick to 0. Example:
-
- #include <stdio.h>
- #include <joystick.h>
- void main()
- {
- detectstick();
- if (hasstick) printf("Game port found\n");
- else printf("No game port found\n");
- }
-
- ==============================================================================
-
- Keyboard.c:
- This library provides interrupt driven keyboard input. It can be used for
- programs such as keyboard driven realtime simulator games. It replaces
- the keyboard interrupt handler with a routine that updates an array that
- stores the current state (pressed or not pressed) of the keys. Once the
- new handler is installed, the kepressed() function can be used to get the
- current state (pressed or not pressed) of a key. Routines are as follows:
-
- --------------------------------------------------------------------------
-
- void startkeyboard();
-
- Clears keys array, saves old interrupt 9 (keyboard) handler address,
- installs new interrupt 9 handler. The new handler updates an array that
- tracks the state (pressed or not pressed) of the keys, and then calls the
- old int 9 handler. Call once before accessing keys array via keypressed().
- Example:
-
- #include <keyboard.h>
- #include <stdio.h>
- void main()
- {
- startkeyboard();
- do
- {
- printf("Esc not pressed\n");
- }
- while (! keypressed(0));
- do
- {
- printf("Esc is pressed\n");
- }
- while (keypressed(0));
- stopkeyboard();
- }
-
-
- --------------------------------------------------------------------------
-
- int keypressed(int i);
-
- Returns the state of a key. I is the scancode of the key. Returns 1 if
- the key is being pressed, else returns 0. Example:
-
- #include <keyboard.h>
- #include <stdio.h>
- void main()
- {
- startkeyboard();
- do
- {
- printf("Esc not pressed\n");
- }
- while (! keypressed(0));
- do
- {
- printf("Esc is pressed\n");
- }
- while (keypressed(0));
- stopkeyboard();
- }
-
-
- --------------------------------------------------------------------------
-
- void stopkeyboard();
-
- Restores the old interrupt 9 handler. Call this routine once when you're
- done accessing keys array. Example:
-
- #include <keyboard.h>
- #include <stdio.h>
- void main()
- {
- startkeyboard();
- do
- {
- printf("Esc not pressed\n");
- }
- while (! keypressed(0));
- do
- {
- printf("Esc is pressed\n");
- }
- while (keypressed(0));
- stopkeyboard();
- }
-
- ==============================================================================
-
- Math2.c:
- This library provides various math routines. Data structures and routines
- are as follows:
-
- --------------------------------------------------------------------------
-
- extern float sinof[360],cosof[360];
-
- These arrays are lookup tables that hold the values of the sins and
- cosines of angles from 0 to 359 degrees. For example sinof[0] holds the
- sin of 0 degrees. Cosof[0] holds the cosine of 0 degrees. They must be
- initialized by a call to inittrigtables(). After that you may access them
- instead of calling sin() and cos(). Accessing the lookup tables runs MUCH
- faster than calling sin() or cos(). Example:
-
- #include <math2.h>
- #include <stdio.h>
- int i;
- void main()
- {
- inittrigtables();
- for (i=0; i<360; i++)
- printf("i=%d sin(i)=%f cos(i)=%f\n",i,sinof[i],cosof[i]);
- }
-
- --------------------------------------------------------------------------
-
- int round(float f);
-
- Returns the rounded off value of a number. The number is rounded to the
- nearest integer. Example:
-
- #include <math2.h>
- #include <stdio.h>
- int i;
- void main()
- {
- i=round(3.141);
- printf("Round(3.141)=%d\n",i);
- }
-
- --------------------------------------------------------------------------
-
- int headingto(long x1, long y1, long x2, long y2);
-
- Returns the compass heading (0 to 359 degrees) from point x1,y1 to point
- x2,y2. The points are points on a right cartiesan plane coordinate
- system. Example:
-
- #include <math2.h>
- #include <stdio.h>
- int i;
- void main()
- {
- i=headingto(1,1,2,2); /* i is 45 degrees */
- printf("heading from 1,1 to 2,2 is %d degrees\n",i);
- }
-
- --------------------------------------------------------------------------
-
- int markvalue(long x1, long y1, long z1, long x2, long y2, long z2);
-
- Returns the spherical coordinate system second angle (rho - angle of
- inclination) from the point x1,y1,z1 to the point x2,y2,z2. The points
- are in right cartesian coordinates. For the value returned, 0 is
- horizontal, 90 is up, -90 is down 180/-180 is upsidedown & opposite
- direction. Example:
-
- #include <math2.h>
- #include <stdio.h>
- int i;
- void main()
- {
- i=markvalue(1,1,1,2,2,2); /* i is 45 degrees */
- printf("markvalue from 1,1,1 to 2,2,2 is %d degrees\n",i);
- }
-
- --------------------------------------------------------------------------
-
- long dist3d(long x1, long y1, long z1, long x2, long y2, long z2);
-
- Returns the 3 dimentional distance from point x1,y1,z1 to point x2,y2,z2.
- the points are in right cartesian coodinates. Example:
-
- #include <math2.h>
- #include <stdio.h>
- long l;
- void main()
- {
- l=dist3d(1,1,1,20,20,20);
- printf("distance from 1,1,1 to 20,20,20 is %d\n",l);
- }
-
- --------------------------------------------------------------------------
-
- void i2s(long i,char *s);
-
- Converts an integer to a string. I is the integer to convert. S is the
- string to return the result in. Example:
-
- #include <math2.h>
- #include <stdio.h>
- int i;
- char s[100];
- void main()
- {
- i=45;
- i2s(i,s);
- printf("i = %s\n",s);
- }
-
- --------------------------------------------------------------------------
-
- void l2s(long i,char *s);
-
- Converts a long integer to a string. I is the integer to convert. S is the
- string to return the result in. Example:
-
- #include <math2.h>
- #include <stdio.h>
- int i;
- char s[100];
- void main()
- {
- i=45;
- i2s(i,s);
- printf("i = %s\n",s);
- }
-
- --------------------------------------------------------------------------
-
- void f2s(float f,char *s);
-
- Converts a float to a string. F is the float to convert. S is the
- string to return the result in. The result will have 20 digits. Example:
-
- #include <math2.h>
- #include <stdio.h>
- float i;
- char s[100];
- void main()
- {
- i=1.0;
- f2s(i,s);
- printf("i = %s\n",s); /* prints "i = 1.0000000000000000000" */
- }
-
- --------------------------------------------------------------------------
-
- void f2s2(float f,char *s);
-
- Converts a float to a string. F is the float to convert. S is the
- string to return the result in. The result will have 2 decimal places.
- Example:
-
- #include <math2.h>
- #include <stdio.h>
- float i;
- char s[100];
- void main()
- {
- i=1.0;
- f2s(i,s);
- printf("i = %s\n",s); /* prints "i = 1.00" */
- }
-
- --------------------------------------------------------------------------
-
- int s2i(char *s);
-
- Converts a string to an integer. Returns the integer value of string S.
- Example:
-
- #include <math2.h>
- #include <stdio.h>
- #include <string.h>
- int i;
- char s[100];
- void main()
- {
- strcpy(s,"100");
- i=s2i(s);
- printf("s = %d\n",i);
- }
-
- --------------------------------------------------------------------------
-
- long s2l(char *s);
-
- Converts a string to a long integer. Returns the integer value of string
- S. Example:
-
- #include <math2.h>
- #include <stdio.h>
- #include <string.h>
- long i;
- char s[100];
- void main()
- {
- strcpy(s,"100000");
- i=s2l(s);
- printf("s = %d\n",i);
- }
-
- --------------------------------------------------------------------------
-
- int isin(int x, int y, int x1, int y1, int x2, int y2);
-
- Returns 1 if point x,y is in the area x1,y1,x2,y2. Otherwise returns 0.
- Useful for seeing if the user clicked in an area, etc. Example:
-
- #include <math2.h>
- #include <graf.h>
- #include <graphics.h>
- #include <mouse.h>
- int x,y;
- void main()
- {
- vidmode=1;
- grafon();
- resetmouse();
- grafrect(1000,1000,2000,2000,15,0,1);
- saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,
- "Click in rectangle to quit");
- do
- {
- select(x,y,1);
- }
- while (! isin(x,y,1000,1000,2000,2000));
- closegraph();
- }
-
- --------------------------------------------------------------------------
-
- int dice(int i);
-
- Returns the roll of a I sided die. Ie: dice(6) returns the roll of a 6
- sided die, and dice(100) retruns the roll of a 100 sided die. You must
- call the standard routine randomize() once at program start to initialize
- the random number generator before you can call dice(). Example:
-
- #include <stdlib.h>
- #include <math2.h>
- #include <stdio.h>
- void main()
- {
- randomize();
- printf("%d\n",dice(6)); /* prints random number 1 to 6 */
- }
-
- --------------------------------------------------------------------------
-
- void ulim(int *i, int j);
-
- Upper limits i to a value no greater than j. IE: if i>j, i=j. Example:
-
- #include <math2.h>
- #include <stdio.h>
- int i;
- void main()
- {
- i=10;
- ulim(&i,5);
- printf("%d\n",i); /* prints 5 */
- i=10;
- ulim(&i,20);
- printf("%d\n",i); /* prints 10 */
- }
-
- --------------------------------------------------------------------------
-
- void normalize(int *i);
-
- Converts a degree value i to its equivalent value in the range 0 to 359
- degrees. Example:
-
- #include <math2.h>
- #include <stdio.h>
- int i;
- void main()
- {
- i=35;
- normalize(&i);
- printf("%d\n",i); /* prints 35 */
- i=-45;
- normalize(&i);
- printf("%d\n",i); /* prints 315 */
- i=360;
- normalize(&i);
- printf("%d\n",i); /* prints 0 */
- }
-
- --------------------------------------------------------------------------
-
- void llim(int *i, int j);
-
- Lower limits i to a value no less than j. IE: if i<j i=j. Example:
-
- #include <math2.h>
- #include <stdio.h>
- int i;
- void main()
- {
- i=10;
- llim(&i,5);
- printf("%d\n",i); /* prints 10 */
- i=10;
- llim(&i,20);
- printf("%d\n",i); /* prints 20 */
- }
-
- --------------------------------------------------------------------------
-
- void inittrigtables();
-
- Initializes the sinof[] and cosof[] lookup table arrays. Call once before
- using the sinof[] and cosof[] lookup table arrays. Example:
-
- #include <math2.h>
- #include <stdio.h>
- int i;
- void main()
- {
- inittrigtables();
- for (i=0; i<360; i++)
- printf("i=%d sin(i)=%f cos(i)=%f\n",i,sinof[i],cosof[i]);
- }
-
- --------------------------------------------------------------------------
-
- long dist2d(long x1, long y1, long x2, long y2);
-
- Returns the 2 dimentional distance from point x1,y1 to point x2,y2.
- the points are in right cartesian coodinates. Example:
-
- #include <math2.h>
- #include <stdio.h>
- long l;
- void main()
- {
- l=dist2d(1,1,20,20);
- printf("distance from 1,1 to 20,20 is %d\n",l);
- }
-
- ==============================================================================
-
- Mouse.c:
- This library provides routines for using a Microsoft compatable mouse.
- Data structures and routines are as follows:
-
- --------------------------------------------------------------------------
-
- extern int hasmouse;
-
- Global boolean. If hasmouse=1, then they have a mouse. If hasmouse=0 they
- don't. This variable is set by the resetmouse() routine. Example:
-
- #include <stdio.h>
- #include <mouse.h>
- void main()
- {
- resetmouse();
- if (hasmouse) printf("mouse found\n");
- else printf("mouse not found\n");
- }
-
- --------------------------------------------------------------------------
-
- void resetmouse();
-
- Resets the mouse. Call once at program start before using the mouse.
- Sets the hasmouse variable. Example:
-
- #include <stdio.h>
- #include <mouse.h>
- void main()
- {
- resetmouse();
- if (hasmouse) printf("mouse found\n");
- else printf("mouse not found\n");
- }
-
- --------------------------------------------------------------------------
-
- int mousebutton();
-
- Returns the current mouse button state. The values returned are:
- 0=no buttons pressed.
- 1=left button pressed.
- 2=right button pressed.
- 3=left and right buttons pressed.
- 4=middle button pressed.
- 5=middle and left buttons pressed.
- 6=middle and right buttons pressed.
- 7=all three buttons pressed.
- Example:
-
- #include <stdio.h>
- #include <mouse.h>
- int i;
- void main()
- {
- resetmouse();
- do
- {
- i=mousebutton();
- if (i==1) printf("left button pressed\n");
- }
- while (i != 2);
- }
-
- --------------------------------------------------------------------------
-
- void nobutton();
-
- Waits until no mouse buttons are being pressed. Example:
-
- #include <stdio.h>
- #include <mouse.h>
- void main()
- {
- resetmouse();
- printf("press and hold left mouse button\n");
- do
- {
- }
- while (mousebutton() != 1);
- printf("release all mouse buttons\n");
- nobutton();
- }
-
- --------------------------------------------------------------------------
-
- void showmouse();
-
- Makes the mouse cursor appear on the screen. Example:
-
- #include <stdio.h>
- #include <mouse.h>
- void main()
- {
- resetmouse();
- showmouse();
- do
- {
- }
- while (! mousebutton());
- hidemouse();
- }
-
- --------------------------------------------------------------------------
-
- void hidemouse();
-
- Makes the mouse cursor disappear. Example:
-
- #include <stdio.h>
- #include <mouse.h>
- void main()
- {
- resetmouse();
- showmouse();
- do
- {
- }
- while (! mousebutton());
- hidemouse();
- nobutton();
- do
- {
- }
- while (! mousebutton());
- showmouse();
- nobutton();
- do
- {
- }
- while (! mousebutton());
- hidemouse();
- }
-
- --------------------------------------------------------------------------
-
- void getmouse(int *x,int *y,int *b);
-
- Gets the current state of the mouse. x,y is its position on screen in
- hardware video coordinates. B is the button state. Values for B are the
- same as in the mousebutton() routine. Example:
-
- #include <stdio.h>
- #include <mouse.h>
- int x,y,b;
- void main()
- {
- resetmouse();
- showmouse();
- do
- {
- getmouse(&x,&y,&b);
- }
- while (b==0);
- hidemouse();
- }
-
- --------------------------------------------------------------------------
-
- void putmouse(int x,int y);
-
- Moves the mouse to point x,y (video hardware coordinates). Example:
-
- #include <stdio.h>
- #include <mouse.h>
- int x,y,b;
- void main()
- {
- resetmouse();
- showmouse(); /* show mouse */
- do /* wait for click */
- {
- getmouse(&x,&y,&b);
- }
- while (b==0);
- hidemouse(); /* hide mouse */
- putmouse(0,0); /* move mouse to upper left corner of screen */
- showmouse(); /* show mouse */
- nobutton(); /* wait for no mouse buttons */
- do /* wait for click */
- {
- getmouse(&x,&y,&b);
- }
- while (b==0);
- hidemouse(); /* hide mouse */
- }
-
- ==============================================================================
-
- Timer.c:
- This library provides routines for accurate timing delays. The routines
- run off the DOS system clock. This gives you delays that are the same
- on different PCs. These routines work well for timing screen updates to
- soundcard music. Routines are as follows:
-
- --------------------------------------------------------------------------
-
- void starttimer();
-
- Initializes the timer to zero. Call this routine to begin timing. Example:
-
- #include <timer.h>
- #include <stdio.h>
- void main()
- {
- int i;
- long l;
- starttimer();
- for (i=0; i<1000; i++)
- {
- }
- l=elapsedtime();
- printf("%d\n",l); /* print # of millisecs to run the loop */
- }
-
- --------------------------------------------------------------------------
-
- long elapsedtime(void);
-
- Returns the elapsed time (in milliseconds) since starttimer() was called.
- Example:
-
- #include <timer.h>
- #include <stdio.h>
- void main()
- {
- int i;
- long l;
- starttimer();
- for (i=0; i<1000; i++)
- {
- }
- l=elapsedtime();
- printf("%d\n",l); /* print # of millisecs to run the loop */
- }
-
- ==============================================================================
-
- Help.c:
- This library provides you with a help file viewer. The viewer runs in
- graphics, and has search and print capabilites. The viewer can display
- any ascii file. The help library contains one routine:
-
- --------------------------------------------------------------------------
-
- void showhelp(char *s2);
-
- Shows an ascii file. S2 is the name of the file to show. Example:
-
- #include <graf.h>
- #include <mouse.h>
- #include <graphics.h>
- void main()
- {
- vidmode=1;
- grafon();
- resetmouse();
- showhelp("c:\\autoexec.bat");
- closegraph();
- }
-
- ==============================================================================
-
- Getfile.c:
- This library provides a file selection dialog box. The library consists
- of one routine getfile() which shows a dialog box and lets the user select
- a file.
-
- --------------------------------------------------------------------------
-
- void getfile(char *promptstr, char *searchspec, char *returnstr,
- int forecolor,int forecolor2,int bakcolor,int doaclick);
-
- Shows a dialog box that lets the user select a file. Promptstr is the
- prompt to display (such as "Load file..."). Searchspec is the filespec
- used for showing files (such as "*.*" or "*.dat" etc). Returnstr is the
- string that the name of the selected file is returned in. Forecolor is
- the text color, forecolor2 is the text shadow color, and bakcolor is the
- box color. If doaclick=1, a click will be made when the user clicks on
- a selection. No click will be made if doclick=0. Returns the complete
- filename (drive, directory, filename, and extension). Saves and restores
- the screen behind the box. Returns "" if user cancels. User can change
- drives, directories, and the searchspec. User can select a file, enter
- a filename, or cancel. Shows alpabetized listings of files and subdirs.
- User can scroll and page through subdir and file lists. Sorts lists in
- memory for speed. Can handle up to 100 subdirs per directory, and 1000
- files per directory. Example:
-
- #include <graf.h>
- #include <graphics.h>
- #include <getfile.h>
- #include <edit.h>
- #include <string.h>
- #include <mouse.h>
- void main()
- {
- char s[100];
- vidmode=1;
- grafon();
- resetmouse();
- getfile("Select file to edit...","*.*",s,15,0,7,1);
- if (strcmp(s,"") !=0) editfile(s,15,0,7,1);
- closegraph();
- }
-
- ==============================================================================
-
-
-
-