home *** CD-ROM | disk | FTP | other *** search
/ Point Programming 1 / PPROG1.ISO / c / bc40lib / bc40lib.doc next >
Encoding:
Text File  |  1994-05-08  |  76.9 KB  |  2,660 lines

  1.                  BC 4.0 Lib
  2.               Borland C/C++ v4.0 Library
  3.                v1.0 (C) Copyright 1994
  4.             Rockland Software Productions
  5.  
  6. Description:
  7.     BC40Lib is a programming library for Borland C/C++ v4.0. It includes
  8.     libraries for mouse, joystick, graphics, math, file I/O, and other 
  9.     miscellaneous functions.
  10.  
  11. Differences between the registered and unregistered versions:
  12.     The unregistered version contains a lib for small memory model. This
  13.     allows you to try the library. The registered version comes with source
  14.     code. Please use the unregistered version for evaluation purposes ONLY.
  15.     If you end up using BC40LIB code, you ARE required to register.
  16.  
  17. Archive contents:
  18.     BC40LIB.doc                      BC40LIB documentation
  19.     *.h                              header files
  20.     *.lib                            library files
  21.     *.c                              source files (registered version only)
  22.     catalog.doc                      Rockland Software Productions catalog
  23.     order.frm                        order form
  24.     support.doc                      support information
  25.     vendor.txt                       distribution policy
  26.  
  27. Installing:
  28.     1. Copy the .lib file(s) to your \bc4\lib directory.
  29.     2. Copy the .h files to \bc4\include directory.
  30.     3. Copy the .c files (registered version only) to your \bc4\source
  31.        directory.
  32.  
  33. Using:
  34.    1. Project options - directories - source directories: add \bc4\source.
  35.    2. Project options - directories - include directories: add \bc4\include.
  36.    3. In each source file that uses a library, be sure to #include the .h
  37.       file.
  38.    4. In the project window, add any included .c or .lib files to the project
  39.       tree.
  40.  
  41. Support:
  42.     Support is available via phone, BBS, email, or mail. See support.doc for
  43.     details.
  44.  
  45. The Library files:
  46.     BC40Lib consists of the following library files:
  47.     Edit - ascii file editor.
  48.     Fileio - text and binary file i/o.
  49.     Generic2 - miscellaneous routines.
  50.     Graf - device independant graphics.
  51.     Joystick - joystick routines.
  52.     Keyboard - interrupt driven keyboard routines.
  53.     Math2 - math routines.
  54.     Mouse - mouse routines.
  55.     Timer - timing routines.
  56.     Help - ascii help file viewer with search and print.
  57.     Getfile - file selection dialog box.
  58.     Each library of routines has a .c or .obj file, and a .h file.
  59.  
  60. A note on color variables:
  61.     Anywhere that the library uses color variables, the allowable values
  62.     are 0-15 or 0-255, depending on the current graphics mode. The values
  63.     correspond to the pallete entries currently in effect. For a default
  64.     CGA thru VGA 16 color palette the values are 0=black, 1=blue, 2=green,
  65.     etc.
  66.  
  67. A note on string variables:
  68.     All string variables use null terminated strings. They are pointers to
  69.     arrays of characters.
  70.  
  71. A note on coordinate variables:
  72.     All coordinate variable are virtual coordinates (0-10000 by 0-10000)
  73.     unless otherwise noted.
  74.  
  75. A note on fillstyle variables:
  76.     All fillstyle variables ues the same values as the standard BGI.
  77.  
  78. A note on 256 color palettes:
  79.     All 256 color palettes are stored in an array[256] of palrec.
  80.  
  81. A note on areas:
  82.     All areas for fills, getting bitmaps, etc. are defined by the coordinates
  83.     of the upper left (x1,y1) and lower right (x2,y2) corners.
  84.  
  85. A note on text variables:
  86.     All of the following text variable types use the standard values of the
  87.     BGI: font, textsize, orientation, horizontal and vertical justifications,
  88.     and scaling factors.
  89.  
  90. ==============================================================================
  91.  
  92. Edit.c:
  93.     This library provides a basic ascii text editor that runs in graphics
  94.     mode. It contains one routine:
  95.  
  96.     --------------------------------------------------------------------------
  97.  
  98.     void editfile(char *s,int fore,int fore2,int bak);
  99.  
  100.     S is the name of the ascii file to edit. Fore is text color. Fore2 is 
  101.     text shadow color. Bak is background color. This routine draws a large 
  102.     panel on the screen and shows the text on the panel. Editing keys work 
  103.     in the usual manner. Pressing Esc exits with an option to save. Example:
  104.  
  105.     #include <graphics.h>
  106.     #include <edit.h>
  107.     #include <graf.h>
  108.     #include <mouse.h>
  109.     void main()
  110.     {
  111.     vidmode=0;
  112.     grafon();
  113.     resetmouse();
  114.           /* edit autoexec.bat using white text
  115.              with black shadow on blue background. */
  116.     editfile("c:\\autoexec.bat",15,0,1);
  117.     closegraph();
  118.     }
  119.  
  120. ==============================================================================
  121.  
  122. Fileio.c:
  123.     This library provides easy to use routines for both text and binary file
  124.     input and output. Use these routines instead of fopen, fread, etc. The
  125.     routines in this library call fopen, fread, etc. for you with the proper
  126.     parameters. This library's .h file includes stdio.h. This means you
  127.     don't have to include stdio.h in files that include fileio.h. The
  128.     routines in fileio.c are as follows:
  129.  
  130.     --------------------------------------------------------------------------
  131.  
  132.     int filefound(char *s);
  133.  
  134.     Searches for a file. S is the name of the file to search for. Returns a 1
  135.     if the file is found, else returns a 0. Example:
  136.  
  137.     #include <fileio.h>
  138.     void main()
  139.     {
  140.     if (filefound("c:\\autoexec.bat")) printf("autoexec found\n");
  141.     else printf("autoexec not found\n");
  142.     }
  143.  
  144.     --------------------------------------------------------------------------
  145.  
  146.     int readfile(FILE *f,char *s);
  147.  
  148.     Reads a string from an ascii text file. F is the file to read from.
  149.     S is the string to read into. returns 1 on success, else returns 0.
  150.     Example:
  151.  
  152.     #include <fileio.h>
  153.     char s[100];
  154.     FILE *f;
  155.     void main()
  156.     {
  157.     f=infile("c:\\autoexec.bat");
  158.     while (readfile(f,s)) printf("%s",s);
  159.     fclose(f);
  160.     }
  161.  
  162.     --------------------------------------------------------------------------
  163.  
  164.     int writefile(FILE *f,char *s);
  165.  
  166.     Writes a string to an ascii text file. F is the file to write to. S is
  167.     the string to write. Returns 1 on success, else returns 0. Example:
  168.  
  169.     #include <fileio.h>
  170.     FILE *f;
  171.     void main()
  172.     {
  173.     f=outfile("test.doc");
  174.     writefile(f,"this is a test.");
  175.     fclose(f);
  176.     }
  177.  
  178.     --------------------------------------------------------------------------
  179.  
  180.     FILE *infile(char *s);
  181.  
  182.     Opens an ascii text file for input. S is the name of the file to open.
  183.     Returns a file pointer for the opened file. Example:
  184.  
  185.     #include <fileio.h>
  186.     char s[100];
  187.     FILE *f;
  188.     void main()
  189.     {
  190.     f=infile("c:\\autoexec.bat");
  191.     while (readfile(f,s)) printf("%s\n",s);
  192.     fclose(f);
  193.     }
  194.  
  195.     --------------------------------------------------------------------------
  196.  
  197.     FILE *outfile(char *s);
  198.  
  199.     Opens an ascii text file for output. S is the name of the file to open.
  200.     Returns a file pointer for the newly opened file. Example:
  201.  
  202.     #include <fileio.h>
  203.     FILE *f;
  204.     void main()
  205.     {
  206.     f=outfile("test.doc");
  207.     writefile(f,"this is a test.");
  208.     fclose(f);
  209.     }
  210.  
  211.     --------------------------------------------------------------------------
  212.  
  213.     FILE *appendfile(char *s);
  214.  
  215.     Opens an ascii file for appending output to the end of the file. S is the
  216.     name of the file to open. Returns a file pointer to the newly opened
  217.     file. Example:
  218.  
  219.     #include <fileio.h>
  220.     FILE *f;
  221.     void main()
  222.     {
  223.     f=appendfile("c:\\autoexec.bat");
  224.     writefile(f,"echo Hello World!");
  225.     fclose(f);
  226.     }
  227.  
  228.     --------------------------------------------------------------------------
  229.  
  230.     FILE *appendfilebin(char *s);
  231.  
  232.     Opens a binary file for appending output to the end of the file. S is the
  233.     name of the file to open. Returns a file pointer to the newly opened
  234.     file. Example:
  235.  
  236.     #include <string.h>
  237.     #include <fileio.h>
  238.     struct addressrec
  239.        {
  240.        char name[20],address[50],phone[20];
  241.        };
  242.     struct addressrec r;
  243.     FILE *f;
  244.     void main()
  245.     {
  246.     strcpy(r.name,"Joe Blow");
  247.     strcpy(r.address,"123 anystreet, Fairfax VA, 22033");
  248.     strcpy(r.phone,"703-555-1212");
  249.     f=appendfilebin("address.dat");
  250.     writefilebin(f,&r,sizeof(r));
  251.     fclose(f);
  252.     }
  253.  
  254.     --------------------------------------------------------------------------
  255.  
  256.     FILE *infilebin(char *s);
  257.  
  258.     Opens a binary file for input. S is the name of the file to open. Returns
  259.     a file pointer to the newly opened file. Example:
  260.  
  261.     #include <fileio.h>
  262.     struct addressrec
  263.        {
  264.        char name[20],address[50],phone[20];
  265.        };
  266.     struct addressrec r;
  267.     FILE *f;
  268.     void main()
  269.     {
  270.     f=infilebin("address.dat");
  271.     readfilebin(f,&r,sizeof(r));
  272.     fclose(f);
  273.     printf("%s\n",r.name);
  274.     printf("%s\n",r.address);
  275.     printf("%s\n",r.phone);
  276.     }
  277.  
  278.     --------------------------------------------------------------------------
  279.  
  280.     FILE *outfilebin(char *s);
  281.  
  282.     Opens a binary file for output. S is the name of the file to open.
  283.     Returns a file pointer to the newly opened file. Example:
  284.  
  285.     #include <fileio.h>
  286.     struct addressrec
  287.        {
  288.        char name[20],address[50],phone[20];
  289.        };
  290.     struct addressrec r;
  291.     FILE *f;
  292.     void main()
  293.     {
  294.     strcpy(r.name,"Joe Blow");
  295.     strcpy(r.address,"123 anystreet, Fairfax VA, 22033");
  296.     strcpy(r.phone,"703-555-1212");
  297.     f=outfilebin("address.dat");
  298.     writefilebin(f,&r,sizeof(r));
  299.     fclose(f);
  300.     }
  301.  
  302.     --------------------------------------------------------------------------
  303.  
  304.     int readfilebin(FILE *f,void *rec,int recsize);
  305.  
  306.     Reads a record from a binary file. F is the file pointer of the file to
  307.     read from. Rec points to the record to read into. Recsize is the size (in
  308.     bytes) of the record to be read. Example:
  309.  
  310.     #include <fileio.h>
  311.     struct addressrec
  312.        {
  313.        char name[20],address[50],phone[20];
  314.        };
  315.     struct addressrec r;
  316.     FILE *f;
  317.     void main()
  318.     {
  319.     f=infilebin("address.dat");
  320.     readfilebin(f,&r,sizeof(r));
  321.     fclose(f);
  322.     printf("%s\n",r.name);
  323.     printf("%s\n",r.address);
  324.     printf("%s\n",r.phone);
  325.     }
  326.  
  327.     --------------------------------------------------------------------------
  328.  
  329.     int writefilebin(FILE *f,void *rec,int recsize);
  330.  
  331.     Writes a record to a binary file. F is the file pointer of the file to
  332.     write to. Rec points to the record to write. Recsize is the size (in
  333.     bytes) of the record to be written. Example:
  334.  
  335.     #include <fileio.h>
  336.     struct addressrec
  337.        {
  338.        char name[20],address[50],phone[20];
  339.        };
  340.     struct addressrec r;
  341.     FILE *f;
  342.     void main()
  343.     {
  344.     strcpy(r.name,"Joe Blow");
  345.     strcpy(r.address,"123 anystreet, Fairfax VA, 22033");
  346.     strcpy(r.phone,"703-555-1212");
  347.     f=outfilebin("address.dat");
  348.     writefilebin(f,&r,sizeof(r));
  349.     fclose(f);
  350.     }
  351.  
  352. ==============================================================================
  353.  
  354. Generic2.c:
  355.  
  356.     This library provides miscellaneous routines. It includes sound, keyboard,
  357.     string, and dos routines. Routines are as follows:
  358.  
  359.     --------------------------------------------------------------------------
  360.  
  361.     void beep(int f, int d);
  362.  
  363.     Produces a beep on the PC's speaker. F is the frequency (in Hertz) of the
  364.     beep. D is the duration of the beep in milliseconds. Example:
  365.  
  366.     #include <generic2.h>
  367.     void main()
  368.     {
  369.      /* produces a beep similar to character 7, the bell character */
  370.     beep(1000,100);
  371.     }
  372.  
  373.     --------------------------------------------------------------------------
  374.  
  375.     void nokey();
  376.  
  377.     Waits until no keyboard keys are being pressed. Example:
  378.  
  379.     #include <stdio.h>
  380.     #include <conio.h>
  381.     #include <generic2.h>
  382.     void main()
  383.     {
  384.     printf("Press a key to continue...\n");
  385.     nokey();
  386.     /* waits for no keystrokes, emptying keyboard buffer, then continues */
  387.     getch();   /* gets a keystroke */
  388.     }
  389.  
  390.     --------------------------------------------------------------------------
  391.  
  392.     int inserton();
  393.  
  394.     Returns 1 if insert is on, else returns 0. Example:
  395.  
  396.     #include <stdio.h>
  397.     #include <generic2.h>
  398.     void main()
  399.     {
  400.     if (inserton()) printf("insert is on\n");
  401.     else printf("insert is off\n");
  402.     }
  403.  
  404.     --------------------------------------------------------------------------
  405.  
  406.     void delchar(char *s,int first,int num);
  407.  
  408.     Deletes characters from a string. S is the (null terminated) string to
  409.     delete characters from. First is the 1st character to delete (zero based,
  410.     just like character arrays). Num is the number of characters to delete.
  411.     Example:
  412.  
  413.     #include <stdio.h>
  414.     #include <string.h>
  415.     #include <generic2.h>
  416.     void main()
  417.     {
  418.     strcpy(s,"joe blow");
  419.       /* delete 5 characters from S, starting with character 3. */
  420.     delchar(s,3,5);
  421.     printf("%s\n",s);      /* prints out "joe" */
  422.     }
  423.  
  424.     --------------------------------------------------------------------------
  425.  
  426.     void copyfile(char *s,char *s2);
  427.  
  428.     Copies a file. S is the source filename. S2 is the destination filename.
  429.     Example:
  430.  
  431.     #include <generic2.h>
  432.     void main()
  433.     {
  434.     copyfile("c:\\autoexec.bat","c:\\autoexec.bak"); /* backup the autoexec */
  435.     }
  436.  
  437.     --------------------------------------------------------------------------
  438.  
  439.     void chdrv(int i);
  440.  
  441.     Changes the current drive. I is the drive to change to (0=A:, 1=B:, 2=C:,
  442.     etc.). Example:
  443.  
  444.     #include <generic2.h>
  445.     void main()
  446.     {
  447.     chdrv(2);     /*     change to C:    */
  448.     }
  449.  
  450.     --------------------------------------------------------------------------
  451.  
  452.     int deviceready(char *s);
  453.  
  454.     Returns 1 if device s is ready. Otherwise returns 0. S can be: "prn",
  455.     "lpt1", "lpt2", "lpt3", "com1", "com2", "com3", or "com4". Example:
  456.  
  457.     #include <generic2.h>
  458.     #include <stdio.h>
  459.     void main()
  460.     {
  461.     if (deviceready("prn")) printf("Printer is ready...\n");
  462.     else printf("Error: printer not ready.\n");
  463.     }
  464.  
  465.     --------------------------------------------------------------------------
  466.  
  467.     void stringcopy(char *fromstr,char *tostr,int startchar,int numchars);
  468.  
  469.     Copies part of a string to another string. Fromstr is the string to copy
  470.     from. Tostr is the string to copy to. Startchar is the first character to
  471.     copy (zero based). Numchars is the number of characters to copy. Example:
  472.  
  473.     #include <generic2.h>
  474.     #include <stdio.h>
  475.     #include <string.h>
  476.     void main()
  477.     {
  478.     strcpy(s,"This is a test");
  479.     stringcopy(s,s2,5,4);
  480.     printf("%s\n",s2);          /* prints "is a".   */
  481.     }
  482.  
  483.     --------------------------------------------------------------------------
  484.  
  485.     void doscommand(char *s);
  486.  
  487.     Executes a dos command. S is the command as you would enter it at the dos
  488.     prompt. Example:
  489.  
  490.     #include <generic2.h>
  491.     #include <stdio.h>
  492.     #include <conio.h>
  493.     void main()
  494.     {
  495.     char s[100],s2[100];
  496.     printf("Enter search spec...\n");
  497.     scanf("%s",s);
  498.     strcpy(s2,"dir ");
  499.     strcat(s2,s);
  500.     doscommand(s2);
  501.     printf("Press a key...\n");
  502.     getch();
  503.     }
  504.  
  505.     --------------------------------------------------------------------------
  506.  
  507.     void slash(char *s);
  508.  
  509.     Adds a backslash to the end of string s if the last character is not a
  510.     backslash. Use this to add a backslash (if needed) to a directory name
  511.     before adding a filename to the end of the dirctory name. Example:
  512.  
  513.     #include <generic2.h>
  514.     #include <string.h>
  515.     void main()
  516.     {
  517.     char s[100];
  518.     strcpy(s,"c:\\");          /*    s = "c:\"               */
  519.     slash(s);                  /*    s = "c:\"               */
  520.     strcat(s,"command.com");   /*    s = "c:\command.com"    */
  521.     strcpy(s,"c:\\dos");       /*    s = "c:\dos"            */
  522.     slash(s);                  /*    s = "c:\dos\"           */
  523.     strcat(s,"edit.exe");      /*    s = "c:\dos\edit.exe"   */
  524.     }
  525.  
  526.     --------------------------------------------------------------------------
  527.  
  528.     void filenameonly(char *fullname,char *filename);
  529.  
  530.     Returns the filename and extension of a full filename. Fullname is the
  531.     complete filename (drive, directory, filename, and extension). The
  532.     filename with extension is returned in the string <filename>. Example:
  533.  
  534.     #include <generic2.h>
  535.     #include <string.h>
  536.     void main()
  537.     {
  538.     char s[100],s2[100];
  539.     strcpy(s,"c:\\command.com");
  540.     filenameonly(s,s2);            /* returns "command.com" in s2 */
  541.     }
  542.  
  543.     --------------------------------------------------------------------------
  544.  
  545.     long diskfree(int i);
  546.  
  547.     Returns the number of bytes free on a disk. I is the disk (0=current
  548.     drive, 1=A:, 2=B:, 3=C:, etc). Returns -1 if i is not a valid drive.
  549.  
  550. ==============================================================================
  551.  
  552. Graf.c:
  553.     This library provides device independant graphics. It works on a virtual
  554.     coordinate system 0 to 10000 by 0 to 10000 which is then automatically
  555.     mapped to the resolution of the video mode being run (ie 640x480,
  556.     1024x768, etc.). It contains a wide range of routines for graphics.
  557.     It also declares some data structures for use in graphics programming.
  558.     Data structures are as follows:
  559.  
  560.     --------------------------------------------------------------------------
  561.  
  562.     struct palrec
  563.        {
  564.        unsigned char redval,greenval,blueval;
  565.        };
  566.  
  567.     This record type holds the information for one palette entry of a 256
  568.     color palette. It is usually used as the element of an array[256] which
  569.     is a 256 color palette (ie: struct palrec mypal[256]; ). Example:
  570.  
  571.     #include <graphics.h>
  572.     #include <graf.h>
  573.      /* note that PAL, a 256 color palette, is declared as an array[256]
  574.     (ie 0 to 255) of palrec!   */
  575.     struct palrec pal[256];
  576.     void main()
  577.     {
  578.     grafmode=1;
  579.     grafon();
  580.     getallrgbpalette(pal);   /* copy current palette into PAL */
  581.     savepal("default.pal",pal);       /* save PAL to disk */
  582.     closegraph();
  583.     }
  584.  
  585.     --------------------------------------------------------------------------
  586.  
  587.     extern int graffontsize;
  588.  
  589.     This variable is set automatically by the grafon() routine. It is the
  590.     text size used by the menus, dialog boxes, etc in the BC 40 Lib library.
  591.     It is set so that text will be approximately the same size reguardless of
  592.     what video mode you are running. Use it in your saygraf, saygraf3d, and
  593.     settextstyle calls to keep text device independant. It is designed to
  594.     yield approximately 3/8 inch tall characters when font #2 (litt.chr) is
  595.     used. Example:
  596.  
  597.     #include <conio.h>
  598.     #include <graphics.h>
  599.     #include <graf.h>
  600.     void main()
  601.     {
  602.     vidmode=0;
  603.     grafon();
  604.     saygraf3d(5000,5000,15,7,2,graffontsize,0,1,1,1,1,1,1,"Hello world!");
  605.     getch();
  606.     closegraph();
  607.     }
  608.  
  609.     --------------------------------------------------------------------------
  610.  
  611.     extern int vidmode;
  612.  
  613.     This variable is set by you before you call grafon(). It tells grafon()
  614.     what graphics mode to go into. It also can be used to determine what
  615.     graphics mode you're in once you call grafon(). Allowable values are:
  616.     0 - vga 640x350x16 2 vid pages
  617.     1 - vga 648x480x16
  618.     2 - vga 320x200x256*
  619.     3 - vesa svga 640x400x256*
  620.     4 - vesa svga 640x480x256*
  621.     5 - vesa svga 800x600x256*
  622.     6 - vesa svga 1024x768x256*
  623.     * requires bgi256v2.bgi, a popular sharware VESA SVGA bgi driver
  624.       (not included).
  625.     Example:
  626.  
  627.     #include <graphics.h>
  628.     #include <conio.h>
  629.     #include <graf.h>
  630.     void main()
  631.     {
  632.     vidmode=1;   /* set graphics to start in 640x480x16 VGA. */
  633.     grafon();    /* go to graphics mode */
  634.     saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,"Hello world!");
  635.     getch();
  636.     closegraph();   /* end graphics mode, return to text mode */
  637.     }
  638.  
  639.     --------------------------------------------------------------------------
  640.  
  641.     extern char m[25][100];
  642.  
  643.     This array of strings is used by the menus and dialog boxes in the Graf
  644.     library. It is used to hold menu options, or dialog box text. When
  645.     you aren't calling routines that use the array, you may use it for your
  646.     own purposes. To use it with a routine such as a menu, you first copy
  647.     the desired strings into the array, and then call the menu routine. The
  648.     menu routine will use the text in the array for the menu. Example:
  649.  
  650.     #include <graf.h>
  651.     #include <graphics.h>
  652.     #include <mouse.h>
  653.     #include <string.h>
  654.     int i;
  655.     void main()
  656.     {
  657.     vidmode=1;
  658.     grafon();
  659.     resetmouse();
  660.     /* load menu options into array */
  661.     strcpy(m[0],"Please select...");
  662.     strcpy(m[1],"Yes");
  663.     strcpy(m[2],"No");
  664.     /* call menu routine */
  665.     i=popupmenu(-1,-1,2,15,0,1,1);
  666.     if (i==1)
  667.        saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,"Yes selected");
  668.     else saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,"No selected");
  669.     nobutton();
  670.     do
  671.       {
  672.       }
  673.       while (mousebutton()==0);
  674.     closegraph();
  675.     }
  676.  
  677.     --------------------------------------------------------------------------
  678.  
  679.     void loadpal(char *s, struct palrec *pal);
  680.  
  681.     This routine loads a 256 color palette from disk into an array[256] of
  682.     palrec. S is the filename of the palette data file to load. Pal is a
  683.     pointer to an array[256] of palrec that the palette will be read into.
  684.     Example:
  685.  
  686.     #include <conio.h>
  687.     #include <graphics.h>
  688.     #include <graf.h>
  689.     struct palrec pal[256];
  690.     void main()
  691.     {
  692.     grafmode=2;
  693.     grafon();
  694.     loadpal("test.pal",pal);   /* load test.pal from disk into PAL*/
  695.     setallrgbpalette(pal);     /* set palette to PAL */
  696.     getch();
  697.     closegraph();
  698.     }
  699.  
  700.     --------------------------------------------------------------------------
  701.  
  702.     void savepal(char *s, struct palrec *pal);
  703.  
  704.     Saves a 256 color palette to disk. S is the name of the palette data file
  705.     to create. Pal is a pointer to an array[256] of palrec, which is the
  706.     palette to be saved. Example:
  707.  
  708.     #include <graphics.h>
  709.     #include <graf.h>
  710.     struct palrec pal[256];
  711.     void main()
  712.     {
  713.     grafmode=1;
  714.     grafon();
  715.     getallrgbpalette(pal);   /* copy current palette into PAL */
  716.     savepal("default.pal",pal);       /* save PAL to disk */
  717.     closegraph();
  718.     }
  719.  
  720.     --------------------------------------------------------------------------
  721.  
  722.     void setallrgbpalette(struct palrec *pal);
  723.  
  724.     Sets the computer's 256 color palette. Pal points to an array[256] of
  725.     palrec that contains the new values for the computer's palette. Uses
  726.     a rom bios interrupt call to set the palette. Example:
  727.  
  728.     #include <conio.h>
  729.     #include <graphics.h>
  730.     #include <graf.h>
  731.     struct palrec pal[256];
  732.     void main()
  733.     {
  734.     grafmode=2;
  735.     grafon();
  736.     loadpal("test.pal",pal);   /* load test.pal from disk into PAL*/
  737.     setallrgbpalette(pal);     /* set palette to PAL */
  738.     getch();
  739.     closegraph();
  740.     }
  741.  
  742.     --------------------------------------------------------------------------
  743.  
  744.     int x2vidx(int x);
  745.  
  746.     Converts a virtual x coordinate to a hardware x coordinate. X is the
  747.     virtual x coordinate to convert. Returns the hardware x coordinate.
  748.     Example:
  749.  
  750.     #include <graf.h>
  751.     #include <graphics.h>
  752.     #include <stdio.h>
  753.     int i;
  754.     void main()
  755.     {
  756.     vidmode=2;   /* 640x480x16 */
  757.     grafon();
  758.     i=x2vidx(10000);
  759.     closegraph();
  760.     printf("%d\n",i);   /* prints 639 */
  761.     }
  762.  
  763.     --------------------------------------------------------------------------
  764.  
  765.     int y2vidy(int y);
  766.  
  767.     Converts a virtual y coordinate to a hardware y coordinate. Y is the
  768.     virtual y coordinate to convert. Returns the hardware y coordinate.
  769.     Example:
  770.  
  771.     #include <graf.h>
  772.     #include <graphics.h>
  773.     #include <stdio.h>
  774.     int i;
  775.     void main()
  776.     {
  777.     vidmode=2;   /* 640x480x16 */
  778.     grafon();
  779.     i=y2vidy(10000);
  780.     closegraph();
  781.     printf("%d\n",i);   /* prints 479 */
  782.     }
  783.  
  784.     --------------------------------------------------------------------------
  785.  
  786.     int mousex2x(int x);
  787.  
  788.     Converts a harware or mouse x coordinate to a virtual x coordinate. X is
  789.     the hardware or mouse x coordinate to convert. Returns the virtual x
  790.     coordinate. Example:
  791.  
  792.     #include <graf.h>
  793.     #include <graphics.h>
  794.     #include <stdio.h>
  795.     int i;
  796.     void main()
  797.     {
  798.     vidmode=2;   /* 640x480x16 */
  799.     grafon();
  800.     i=mousex2x(639);
  801.     closegraph();
  802.     printf("%d\n",i);   /* prints 10000 */
  803.     }
  804.  
  805.     --------------------------------------------------------------------------
  806.  
  807.     int mousey2y(int y);
  808.  
  809.     Converts a harware or mouse y coordinate to a virtual y coordinate. Y is
  810.     the hardware or mouse y coordinate to convert. Returns the virtual y
  811.     coordinate. Example:
  812.  
  813.     #include <graf.h>
  814.     #include <graphics.h>
  815.     #include <stdio.h>
  816.     int i;
  817.     void main()
  818.     {
  819.     vidmode=2;   /* 640x480x16 */
  820.     grafon();
  821.     i=mousey2y(479);
  822.     closegraph();
  823.     printf("%d\n",i);   /* prints 10000 */
  824.     }
  825.  
  826.     --------------------------------------------------------------------------
  827.  
  828.     void grafpie(int x, int y, int startangle, int endangle, int radius,
  829.          int color, int fillstyle);
  830.  
  831.     Draws a filled pieslice. x,y are the point of the pieslice. Startangle is
  832.     the angle (in degrees) of the beginning edge of the pieslice. Endangle
  833.     is the angle (in degrees) of the ending edge of the pieslice. Radius is
  834.     the radius of the pieslice in virual coordinates. Color is the color of
  835.     the pieslice, and Fillstyle is the fill pattern used to fill the pieslice.
  836.     Example:
  837.  
  838.     #include <graf.h>
  839.     #include <graphics.h>
  840.     #include <conio.h>
  841.     void main()
  842.     {
  843.     vidmode=1;
  844.     grafon();
  845.     pieslice(5000,5000,0,45,4000,14,9);
  846.     getch();
  847.     closegraph();
  848.     }
  849.  
  850.     --------------------------------------------------------------------------
  851.  
  852.     void *grafload(char *s);
  853.  
  854.     Loads a bitmap from disk. S is the filename of the bitmap to load from
  855.     disk. Returns a pointer to the bitmap. Once you're done with the bitmap,
  856.     don't forget to dispose of it by calling free(). Example:
  857.  
  858.     #include <conio.h>
  859.     #include <graf.h>
  860.     #include <graphics.h>
  861.     void *p;
  862.     void main()
  863.     {
  864.     vidmode=1;
  865.     grafon();
  866.     p=grafload("bitmap1.grf");
  867.     grafput(0,0,0,p);
  868.     free(p);
  869.     getch();
  870.     closegraph();
  871.     }
  872.  
  873.     --------------------------------------------------------------------------
  874.  
  875.     void grafsave(char *s,void *p);
  876.  
  877.     Saves a bitmap to disk. S is the filename to save as. P points to the
  878.     bitmap to save. Once you're done with a bitmap, don't forget to dispose
  879.     of it by calling free(). Example:
  880.  
  881.     #include <graf.h>
  882.     #include <graphics.h>
  883.     void *p;
  884.     void main()
  885.     {
  886.     vidmode=1;
  887.     grafon();
  888.     fillgraf(2000,2000,3000,3000,14,9);
  889.     p=grafget(1000,1000,4000,4000);
  890.     grafsave("test.grf",p);
  891.     free(p);
  892.     closegraph();
  893.     }
  894.  
  895.     --------------------------------------------------------------------------
  896.  
  897.     void getallrgbpalette(struct palrec *pal);
  898.  
  899.     Gets the current 256 color palette. Puts the current palette values into
  900.     Pal. Example:
  901.  
  902.     #include <graphics.h>
  903.     #include <graf.h>
  904.     struct palrec pal[256];
  905.     void main()
  906.     {
  907.     grafmode=1;
  908.     grafon();
  909.     getallrgbpalette(pal);   /* copy current palette into PAL */
  910.     savepal("default.pal",pal);       /* save PAL to disk */
  911.     closegraph();
  912.     }
  913.  
  914.     --------------------------------------------------------------------------
  915.  
  916.     void fillgraf(int x1,int y1,int x2,int y2,int color,int fill);
  917.  
  918.     Fills a rectangular area with a color and fillstyle. x1,y1,x2,y2 are
  919.     the coordinates of the area to fill. Color is the color to fill the area
  920.     with. Fill is the fillstyle to use when filling the area. Example:
  921.  
  922.     #include <conio.h>
  923.     #include <graf.h>
  924.     #include <graphics.h>
  925.     void main()
  926.     {
  927.     grafmode=1;
  928.     grafon();
  929.     fillgraf(1000,1000,2000,2000,14,9);
  930.     getch();
  931.     closegraph();
  932.     }
  933.  
  934.     --------------------------------------------------------------------------
  935.  
  936.     void clsgraf(int color,int fill);
  937.  
  938.     Clears the screen. Color is the color to be used. Fill is the fillstyle
  939.     to be used. Example:
  940.  
  941.     #include <conio.h>
  942.     #include <graf.h>
  943.     #include <graphics.h>
  944.     void main()
  945.     {
  946.     vidmode=1;
  947.     grafon();
  948.     clsgraf(14,9);
  949.     getch();
  950.     closegraph();
  951.     }
  952.  
  953.     --------------------------------------------------------------------------
  954.  
  955.     void grafon();
  956.  
  957.     Turns on graphics. Use instead of initgraph(). Set vidmode to the
  958.     desired video mode before calling grafon(). This routine sets
  959.     graffontsize according to the vidmode selected. Don't forget to
  960.     use closegraph() to turn off graphics mode when you're done with
  961.     graphics mode. Example:
  962.  
  963.     #include <conio.h>
  964.     #include <graf.h>
  965.     #include <graphics.h>
  966.     void main()
  967.     {
  968.     vidmode=1;
  969.     grafon();
  970.     saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,"640x480x16");
  971.     getch();
  972.     closegraph();
  973.     }
  974.  
  975.     --------------------------------------------------------------------------
  976.  
  977.     void saygraf3d(int x, int y, int fore, int bak, int font, int size,
  978.            int orientation, int hjust, int vjust, int xmul, int xdiv,
  979.            int ymul, int ydiv,const char *s);
  980.  
  981.     Writes 3D text on the screen. Writes text at position x,y. Fore and
  982.     Bak are the text and text shadow colors. Font is the font to use.
  983.     Size is the size of the text. Orientation is 0 for horizontal, or
  984.     1 for vertical. Hjust and Vjust are the horizontal and vertical
  985.     justification to use. They work the same as in the BGI routine
  986.     settextjustify(). Xmul, Xdiv, Ymul, and Ydiv are scaleing factors. They
  987.     work the same as in the BGI routine setusercharsize(). S is the string of
  988.     text to write to the screen. Example:
  989.  
  990.     #include <conio.h>
  991.     #include <graf.h>
  992.     #include <graphics.h>
  993.     void main()
  994.     {
  995.     vidmode=1;
  996.     grafon();
  997.     saygraf3d(5000,5000,15,7,2,graffontsize,0,1,1,1,1,1,1,"3D Text");
  998.     getch();
  999.     closegraph();
  1000.     }
  1001.  
  1002.     --------------------------------------------------------------------------
  1003.  
  1004.     void saygraf(int x, int y, int fore, int font, int size, int orientation,
  1005.          int hjust, int vjust, int xmul, int xdiv, int ymul, int ydiv,
  1006.          char *s);
  1007.  
  1008.     Writes text on the screen. Writes text at position x,y. Fore is the text
  1009.     color. Font is the font to use. Size is the size of the text. Orientation
  1010.     is 0 for horizontal, or 1 for vertical. Hjust and Vjust are the
  1011.     horizontal and vertical justification to use. They work the same as in
  1012.     the BGI routine settextjustify(). Xmul, Xdiv, Ymul, and Ydiv are
  1013.     scaleing factors. They work the same as in the BGI routine
  1014.     setusercharsize(). S is the string of text to write to the screen.
  1015.     Example:
  1016.  
  1017.     #include <conio.h>
  1018.     #include <graf.h>
  1019.     #include <graphics.h>
  1020.     void main()
  1021.     {
  1022.     vidmode=1;
  1023.     grafon();
  1024.     saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,"This is some text");
  1025.     getch();
  1026.     closegraph();
  1027.     }
  1028.  
  1029.     --------------------------------------------------------------------------
  1030.  
  1031.     void *grafget(int x1,int y1,int x2,int y2);
  1032.  
  1033.     Gets an area from the screen and stores it in a bitmap. x1,y1,x2,y2 are
  1034.     the coordinates of the area to get. Returns a pointer to the bitmap.
  1035.     Don't forget to dispose of the bitmap when you're done with it by calling
  1036.     free(). Example:
  1037.  
  1038.     #include <graf.h>
  1039.     #include <graphics.h>
  1040.     void *p;
  1041.     void main()
  1042.     {
  1043.     vidmode=1;
  1044.     grafon();
  1045.     fillgraf(2000,2000,3000,3000,14,9);
  1046.     p=grafget(1000,1000,4000,4000);
  1047.     grafsave("test.grf",p);
  1048.     free(p);
  1049.     closegraph();
  1050.     }
  1051.  
  1052.     --------------------------------------------------------------------------
  1053.  
  1054.     void grafline(int x1,int y1,int x2,int y2,int color,int style,
  1055.           int thickness);
  1056.  
  1057.     Draws a line. x1,y1 and x2,y2 are the endpoints of the line. Color is
  1058.     the color to use. Style is the line style. It uses standard BGI line
  1059.     style constants just like the standard BGI routine setlinestyle() does.
  1060.     Thickness is the line thickness. It uses standard BGI line thickness
  1061.     constants just like the standard BGI routine setlinestyle(). Example:
  1062.  
  1063.     #include <conio.h>
  1064.     #include <graf.h>
  1065.     #include <graphics.h>
  1066.     void main()
  1067.     {
  1068.     vidmode=1;
  1069.     grafon();
  1070.     grafline(1000,1000,9000,9000,15,0,1);
  1071.     getch();
  1072.     closegraph();
  1073.     }
  1074.  
  1075.     --------------------------------------------------------------------------
  1076.  
  1077.     void grafpix(int x, int y, int color);
  1078.  
  1079.     Draws a pixel on the screen. X,Y are the pixel coordinates. Color is the
  1080.     color to draw the pixel. Example:
  1081.  
  1082.     #include <conio.h>
  1083.     #include <graf.h>
  1084.     #include <graphics.h>
  1085.     int i;
  1086.     void main()
  1087.     {
  1088.     vidmode=1;
  1089.     grafon();
  1090.     for (i=0; i<=10000; i+=100) grafpix(i,i,15);
  1091.     getch();
  1092.     closegraph();
  1093.     }
  1094.  
  1095.     --------------------------------------------------------------------------
  1096.  
  1097.     void panel(int x1, int y1, int x2, int y2, int color, int pressed);
  1098.  
  1099.     Draws a beveled panel. x1,y1,x2,y2 is the area the panel covers. Color
  1100.     is the panel color. Pressed is a boolean. Set Pressed = 1 for pressed
  1101.     in look. Set Pressed = 0 for popped out look. Example:
  1102.  
  1103.     #include <conio.h>
  1104.     #include <graf.h>
  1105.     #include <graphics.h>
  1106.     int i;
  1107.     void main()
  1108.     {
  1109.     vidmode=1;
  1110.     grafon();
  1111.     panel(3000,3000,7000,7000,7,0);
  1112.     panel(4000,4000,5000,4500,9,0);
  1113.     panel(4000,5000,5000,5500,7,1);
  1114.     getch();
  1115.     closegraph();
  1116.     }
  1117.  
  1118.     --------------------------------------------------------------------------
  1119.  
  1120.     void graftri(int x1,int y1,int x2,int y2,int x3,int y3,int color,
  1121.          int fill);
  1122.  
  1123.     Draws a triangle. x1,y1,xc2,y2,x3,y3 are the corners of the triangle.
  1124.     Color and Fill are the color and fillstyle for the triangle. Example:
  1125.  
  1126.     #include <conio.h>
  1127.     #include <graf.h>
  1128.     #include <graphics.h>
  1129.     int i;
  1130.     void main()
  1131.     {
  1132.     vidmode=1;
  1133.     grafon();
  1134.     graftri(1000,9000,5000,1000,9000,9000,13,10);
  1135.     getch();
  1136.     closegraph();
  1137.     }
  1138.  
  1139.     --------------------------------------------------------------------------
  1140.  
  1141.     void grafput(int x, int y, int put, void *p);
  1142.  
  1143.     Puts a bitmap to the screen. x,y is the upper left corner for the bitmap.
  1144.     Put is a standard BGI put type constant just like in the standard BGI
  1145.     routine putimage(). Note that you may also use the extended put types
  1146.     available with BGI256V2.BGI, a popular shareware VESA SVGA BGI driver.
  1147.     Example:
  1148.  
  1149.     #include <conio.h>
  1150.     #include <graf.h>
  1151.     #include <graphics.h>
  1152.     void *p;
  1153.     void main()
  1154.     {
  1155.     vidmode=1;
  1156.     grafon();
  1157.     p=grafload("bitmap1.grf");
  1158.     grafput(0,0,0,p);
  1159.     free(p);
  1160.     getch();
  1161.     closegraph();
  1162.     }
  1163.  
  1164.     --------------------------------------------------------------------------
  1165.  
  1166.     void grafmsg(int x, int y, int i, int fore,int fore2, int bak,
  1167.          int doclick,int dopause, int doprint);
  1168.  
  1169.     Displays a message box. x,y are the upper left corner of the box. If
  1170.     x=-1, box will be centered left to right. If y=-1, box will be centered
  1171.     top to bottom. I is the index of the last string in the message (ie. for
  1172.     a message that uses m[0] thru m[7], i=7). Fore and Fore2 are the text and
  1173.     text shadow colors. Bak is the box color. Uses the global array of
  1174.     strings m[] to hold the text.
  1175.     If doprint=1: the box won't be drawn at all, and the contents will be
  1176.           printed to PRN. Dopause and Doclick are ignored.
  1177.     If doprint=0: If dopause=1: the screen behind the box will be saved, and
  1178.                 the last line of the message box will read
  1179.                 "Press P to print or a mouse button to
  1180.                 continue...". When a mouse button is pressed,
  1181.                 the screen will be restored. If the user
  1182.                 presses P, the text of the box will be
  1183.                 printed on device PRN. If doclick=1, the
  1184.                 speaker will make a click sound when the
  1185.                 mouse is pressed to clear the message box.
  1186.                 If doclick=0, no sound will be made.
  1187.           If dopause=0: the box will be drawn, and grafmsg will then
  1188.                 return. doclick is ignored.
  1189.     Example:
  1190.  
  1191.     #include <string.h>
  1192.     #include <graf.h>
  1193.     #include <graphics.h>
  1194.     #include <mouse.h>
  1195.     void main()
  1196.     {
  1197.     vidmode=1;
  1198.     grafon();
  1199.     resetmouse();
  1200.     strcpy(m[0],"This is a message box");
  1201.     strcpy(m[1],"Text of the message goes here");
  1202.     grafmsg(-1,-1,1,15,0,1,1,1,0);
  1203.     closegraph();
  1204.     }
  1205.  
  1206.     --------------------------------------------------------------------------
  1207.  
  1208.     void grafrect(int x1,int y1,int x2,int y2,int color,int style,
  1209.           int thickness);
  1210.  
  1211.     Draws a rectangle. x1,y1,x2,y2 is the area covered by the rectangle.
  1212.     Color and Style are the color and fill style for the rectangle. Thickness
  1213.     is the line thickness for the edges of the rectangle. Example:
  1214.  
  1215.     #include <conio.h>
  1216.     #include <graf.h>
  1217.     #include <graphics.h>
  1218.     void main()
  1219.     {
  1220.     vidmode=1;
  1221.     grafon();
  1222.     grafrect(1000,1000,3000,2000,12,3,1);
  1223.     getch();
  1224.     closegraph();
  1225.     }
  1226.  
  1227.     --------------------------------------------------------------------------
  1228.  
  1229.     void clsstars();
  1230.  
  1231.     Clears the screen, using a stary background. Example:
  1232.  
  1233.     #include <conio.h>
  1234.     #include <graf.h>
  1235.     #include <graphics.h>
  1236.     void main()
  1237.     {
  1238.     vidmode=1;
  1239.     grafon();
  1240.     clsstars();
  1241.     getch();
  1242.     closegraph();
  1243.     }
  1244.  
  1245.     --------------------------------------------------------------------------
  1246.  
  1247.     void select(int *x, int *y,int doclick);
  1248.  
  1249.     Gets a selection using the mouse. Shows the mouse, waits for a button to
  1250.     be pressed, then hides the mouse and returns the mouse position in
  1251.     virtual coordinates. X,Y return the mouse's position when a button is
  1252.     pressed. If doclick=1, the speaker will make a click sound when the mouse
  1253.     button is pressed. If doclick=0, no click sound will be made. Example:
  1254.  
  1255.     #include <graf.h>
  1256.     #include <graphics.h>
  1257.     #include <mouse.h>
  1258.     #include <stdio.h>
  1259.     int x,y;
  1260.     void main()
  1261.     {
  1262.     vidmode=1;
  1263.     grafon();
  1264.     resetmouse();
  1265.     select(&x,&y,1);
  1266.     closegraph();
  1267.     printf("x=%d    y=%d\n",x,y);
  1268.     }
  1269.  
  1270.     --------------------------------------------------------------------------
  1271.  
  1272.     int popupmenu(int x,int y,int i,int fore,int fore2,int bak,int doclick);
  1273.  
  1274.     Does a popup menu. Menu appears, mouse appears, once an option is
  1275.     selected, mouse disappears, then menu disappears. x,y is the upper left
  1276.     corner of the menu. If x=-1, menu is centered left to right. If y=-1,
  1277.     menu is centered top to bottom.  Uses global string array m[] to hold the
  1278.     title (m[0]) and options (m[1], m[2], etc). I is the index of the last
  1279.     string used (ie for a menu that uses m[0] thru m[2], i=2). Fore and Fore2
  1280.     are the text and text shadow colors. Bak is the menu color. If Doclick=1,
  1281.     the speaker will click when the mouse button is pressed. If Doclick=0,
  1282.     no click will be made. Returns the number of the menu option selected (ie
  1283.     returns 1 if they select the 1st menu option, 2 if they select the second
  1284.     menu option, etc). Example:
  1285.  
  1286.     #include <graf.h>
  1287.     #include <graphics.h>
  1288.     #include <mouse.h>
  1289.     #include <string.h>
  1290.     int i;
  1291.     void main()
  1292.     {
  1293.     vidmode=1;
  1294.     grafon();
  1295.     resetmouse();
  1296.     /* load menu options into array */
  1297.     strcpy(m[0],"Please select...");
  1298.     strcpy(m[1],"Yes");
  1299.     strcpy(m[2],"No");
  1300.     /* call menu routine */
  1301.     i=popupmenu(-1,-1,2,15,0,1,1);
  1302.     if (i==1)
  1303.        saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,"Yes selected");
  1304.     else saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,"No selected");
  1305.     nobutton();
  1306.     do
  1307.       {
  1308.       }
  1309.       while (mousebutton()==0);
  1310.     closegraph();
  1311.     }
  1312.  
  1313.     --------------------------------------------------------------------------
  1314.  
  1315.     void getstr(char *promptstr,char *returnstr,int fore,int fore2,int bak);
  1316.  
  1317.     Gets a string from the user. Draws a dialog box, displays a prompt, then
  1318.     lets the user enter a string. Promptstr is the prompt string. Returnstr
  1319.     returns the string entered by the user. Fore and Fore2 are text and text
  1320.     shadow colors. Bak is dialog box color. Example:
  1321.  
  1322.     #include <stdio.h>
  1323.     #include <graf.h>
  1324.     #include <graphics.h>
  1325.     char s[100];
  1326.     void main()
  1327.     {
  1328.     vidmode=1;
  1329.     grafon();
  1330.     getstr("Enter a string...",s,15,0,1);
  1331.     closegraph();
  1332.     printf("%s\n",s);
  1333.     }
  1334.  
  1335.     --------------------------------------------------------------------------
  1336.  
  1337.     int getnum(char *promptstr,int fore,int fore2,int bak,int doclick);
  1338.  
  1339.     Gets an integer from the user, using a popup numeric keypad. Keypad
  1340.     appears with a prompt, then the mouse appears. Once the user enters
  1341.     a number and selects ok, the mouse disappears, then the keypad
  1342.     disappears. Promptstr is the prompt string. Fore and Fore2 are the text
  1343.     text shadow colors. Bak is the keypad color. If doclick=1, the speaker
  1344.     will click when a mouse button is pressed. If doclick=0, the speaker will
  1345.     not click. Returns the integer the user entered. The keypad has keys 0
  1346.     thru 9, C (clear), and Ok. Example:
  1347.  
  1348.     #include <stdio.h>
  1349.     #include <graf.h>
  1350.     #include <graphics.h>
  1351.     #include <mouse.h>
  1352.     int i;
  1353.     void main()
  1354.     {
  1355.     vidmode=1;
  1356.     grafon();
  1357.     resetmouse();
  1358.     i=getnum("Enter a number...",15,0,1,1);
  1359.     closegraph();
  1360.     printf("%d\n",i);
  1361.     }
  1362.  
  1363.     --------------------------------------------------------------------------
  1364.  
  1365.     void getfile(char *promptstr, char *searchspec, char *returnstr,int fore,
  1366.          int fore2,int bak,int doclick);
  1367.  
  1368.     Gets a filename from the user. Displays a menu listing files. The menu
  1369.     has More and Cancel options as well as filenames. Shows the mouse, and
  1370.     lets the user select from the menu. Returns the filename selected.
  1371.     Returns an empty string (ie "") for cancel. Promptstr is the prompt that
  1372.     appears as the menu title. Searchspec is the file search spec for the
  1373.     list of filenames. Wildcard characters are allowed in the search
  1374.     filespec. Returnstr returns the selected filename. Fore and Fore2 are
  1375.     text and text shadow colors. Bak is menu color. If doclick=1, speaker
  1376.     will click when a mouse button is pressed. If doclick=0 , speaker will
  1377.     not click. Example:
  1378.  
  1379.     #include <stdio.h>
  1380.     #include <graf.h>
  1381.     #include <graphics.h>
  1382.     #include <mouse.h>
  1383.     char s[100];
  1384.     void main()
  1385.     {
  1386.     vidmode=1;
  1387.     grafon();
  1388.     resetmouse();
  1389.     getfile("Select a file...","c:\\*.*",s,15,0,1,1);
  1390.     closegraph();
  1391.     printf("%s\n",s);
  1392.     }
  1393.  
  1394.     --------------------------------------------------------------------------
  1395.  
  1396.     void setborder(int i);
  1397.  
  1398.     Sets the border color. I is the color for the border. Does not work on
  1399.     all hardware. Example:
  1400.  
  1401.     #include <conio.h>
  1402.     #include <graf.h>
  1403.     #include <graphics.h>
  1404.     void main()
  1405.     {
  1406.     vidmode=1;
  1407.     grafon();
  1408.     setborder(1);
  1409.     getch();
  1410.     closegraph();
  1411.     }
  1412.  
  1413.     --------------------------------------------------------------------------
  1414.  
  1415.     int getcol(char *s,int fore,int fore2,int bak,int doclick);
  1416.  
  1417.     Gets a color from the user. Displays a menu of colors. Lets the user
  1418.     select a color with the mouse. Returns the color selected. S is the
  1419.     prompt string for the color menu. Fore and Fore2 are the text and text
  1420.     shadow colors. Bak is the menu color. If doclick=1, speaker
  1421.     will click when a mouse button is pressed. If doclick=0 , speaker will
  1422.     not click. This routine will automaticaly use either a 16 color or 256
  1423.     color menu, depending on the current video mode. Example:
  1424.  
  1425.     #include <stdio.h>
  1426.     #include <graf.h>
  1427.     #include <graphics.h>
  1428.     #include <mouse.h>
  1429.     int i;
  1430.     void main()
  1431.     {
  1432.     vidmode=1;
  1433.     grafon();
  1434.     resetmouse();
  1435.     i=getcol("Select a color...",15,0,1,1);
  1436.     closegraph();
  1437.     printf("%d\n",i);
  1438.     }
  1439.  
  1440.     --------------------------------------------------------------------------
  1441.  
  1442.     int getfill(char *s,int fore,int fore2,int bak,int color,int doclick);
  1443.  
  1444.     Gets a fillstyle from the user. Shows a menu of fill styles. Lets the
  1445.     user select a fillstyle with the mouse. Returns the fillstyle selected.
  1446.     S is the prompt string for the fillstyle menu. Fore and Fore2 are the
  1447.     text and text shadow colors. Bak is the menu color. Color is the color
  1448.     for the fillpatterns in the menu. If doclick=1, speaker will click when a
  1449.     mouse button is pressed. If doclick=0 , speaker will not click. Example:
  1450.  
  1451.     #include <stdio.h>
  1452.     #include <graf.h>
  1453.     #include <graphics.h>
  1454.     #include <mouse.h>
  1455.     int i;
  1456.     void main()
  1457.     {
  1458.     vidmode=1;
  1459.     grafon();
  1460.     resetmouse();
  1461.     i=getfill("Select a fillstyle...",15,0,1,14,1);
  1462.     closegraph();
  1463.     printf("%d\n",i);
  1464.     }
  1465.  
  1466.     --------------------------------------------------------------------------
  1467.  
  1468.     void getarea(int x1,int y1,int *x2,int *y2);
  1469.  
  1470.     Gets an area from the user. Shows the mouse, waits for the user to select
  1471.     the upper left corner of the area. Then does a rubberband box while the
  1472.     user moves to the lower right corner. When the user selects the lower
  1473.     right corner, the rubber band box disappears. The uppper left and lower
  1474.     right coordinates of the area selected are returned in x1,y1,x2,y2.
  1475.     Example:
  1476.  
  1477.     #include <conio.h>
  1478.     #include <graf.h>
  1479.     #include <graphics.h>
  1480.     #include <mouse.h>
  1481.     int x1,y1,x2,y2;
  1482.     void main()
  1483.     {
  1484.     vidmode=1;
  1485.     grafon();
  1486.     resetmouse();
  1487.     saygraf(5000,500,15,2,graffontsize,0,1,1,1,1,1,1,"Select an area...");
  1488.     getarea(x1,y1,x2,y2);
  1489.     fillgraf(x1,y1,x2,y2,14,4);
  1490.     getch();
  1491.     closegraph();
  1492.     }
  1493.  
  1494.     --------------------------------------------------------------------------
  1495.  
  1496.     int getpix(int x,int y);
  1497.  
  1498.     Gets the current color of a pixel. x,y are the pixel's coordinates.
  1499.     Returns the pixel's color. Example:
  1500.  
  1501.     #include <stdio.h>
  1502.     #include <graf.h>
  1503.     #include <graphics.h>
  1504.     int i;
  1505.     void main()
  1506.     {
  1507.     vidmode=1;
  1508.     grafon();
  1509.     i=getpix(5000,5000);
  1510.     closegraph();
  1511.     printf("%d\n",i);
  1512.     }
  1513.  
  1514.     --------------------------------------------------------------------------
  1515.  
  1516.     void fillstars(int x1,int y1,int x2,int y2);
  1517.  
  1518.     Fills an area with a stary pattern. x1,y1,x2,y2 are the area's
  1519.     coordinates. Example:
  1520.  
  1521.     #include <conio.h>
  1522.     #include <graf.h>
  1523.     #include <graphics.h>
  1524.     void main()
  1525.     {
  1526.     vidmode=1;
  1527.     grafon();
  1528.     fillstars(1000,1000,5000,5000);
  1529.     getch();
  1530.     closegraph();
  1531.     }
  1532.  
  1533.     --------------------------------------------------------------------------
  1534.  
  1535.     void grafcircle(int x,int y,int rad,int color,int style,int thickness);
  1536.  
  1537.     Draws a filled circle. x,y is the center of the circle. Rad is the
  1538.     radius. Color and Style are the fill color and fill style to use.
  1539.     Thickness is the line thickness for the edge of the circle. Example:
  1540.  
  1541.     #include <conio.h>
  1542.     #include <graf.h>
  1543.     #include <graphics.h>
  1544.     void main()
  1545.     {
  1546.     vidmode=1;
  1547.     grafon();
  1548.     grafcircle(5000,5000,1000,4,7,1);
  1549.     getch();
  1550.     closegraph();
  1551.     }
  1552.  
  1553.     --------------------------------------------------------------------------
  1554.  
  1555.     void wait4retrace(void);
  1556.  
  1557.     Waits until the beginning of the next vertical retrace. Use this to time
  1558.     your screen updates with the CRT's vertical retrace interval to reduce
  1559.     flicker. Example:
  1560.  
  1561.     #include <graf.h>
  1562.     #include <graphics.h>
  1563.     void main()
  1564.     {
  1565.     int i;
  1566.     vidmode=1;
  1567.     grafon();
  1568.     clsgraf(0,1);
  1569.     for (i=0; i<9000; i++)
  1570.     {
  1571.     waitforretrace();
  1572.     fillgraf(i,4000,i+1000,5000,15,1);
  1573.     waitforretrace();
  1574.     fillgraf(i,4000,i+1000,5000,0,1);
  1575.     }
  1576.     closegraph();
  1577.     }
  1578.  
  1579.     --------------------------------------------------------------------------
  1580.  
  1581.     void fadeout(void);
  1582.  
  1583.     Fades a 256 color palette to black. Example:
  1584.  
  1585.     #include <graf.h>
  1586.     #include <graphics.h>
  1587.     #include <math2.h>
  1588.     #include <stdlib.h>
  1589.     void main()
  1590.     {
  1591.     int i,j,k;
  1592.     randomize();
  1593.     vidmode=2;
  1594.     grafon();
  1595.     clsgraf(0,1);
  1596.     for (i=0; i<9000; i++)
  1597.     {
  1598.     j=dice(9000);
  1599.     k=dice(9000);
  1600.     fillgraf(j,k,j+1000,k+,dice(15),dice(11));
  1601.     }
  1602.     fadeout();
  1603.     closegraph();
  1604.     }
  1605.  
  1606.  
  1607.     --------------------------------------------------------------------------
  1608.  
  1609.     void fadein(struct palrec *pal);
  1610.  
  1611.     Fades in a 256 color palette from black. Example:
  1612.  
  1613.     #include <graf.h>
  1614.     #include <graphics.h>
  1615.     #include <math2.h>
  1616.     #include <stdlib.h>
  1617.     void main()
  1618.     {
  1619.     int i,j,k;
  1620.     struct palrec pal[256],pal2[256];
  1621.     randomize();
  1622.     vidmode=2;
  1623.     grafon();
  1624.     clsgraf(0,1);
  1625.     memset(pal,0,sizeof(pal));
  1626.     getallrgbpalette(pal2);
  1627.     setallrgbpalette(pal);
  1628.     for (i=0; i<9000; i++)
  1629.     {
  1630.     j=dice(9000);
  1631.     k=dice(9000);
  1632.     fillgraf(j,k,j+1000,k+,dice(15),dice(11));
  1633.     }
  1634.     fadein(pal2);
  1635.     closegraph();
  1636.     }
  1637.  
  1638.     --------------------------------------------------------------------------
  1639.  
  1640.     char getdrv(char *s, int fore, int fore2, int bak, int doclick);
  1641.  
  1642.     Lets the user select a drive from a menu. Returns the letter of the
  1643.     selected drive. Returns ' ' (a space) if user cancels. S is the prompt
  1644.     for the menu. Fore is the text color. Fore2 is the text shadow color.
  1645.     Bak is the menu color. Example:
  1646.  
  1647.     #include <graf.h>
  1648.     #include <graphics.h>
  1649.     #include <generic2.h>
  1650.     void main()
  1651.     {
  1652.     char c;
  1653.     vidmode=1;
  1654.     grafon();
  1655.     c=getdrv("Change to drive...");
  1656.     if (c != ' ') chdrv(c);
  1657.     closegraph();
  1658.     }
  1659.  
  1660.     --------------------------------------------------------------------------
  1661.  
  1662.     void refreshon(void);
  1663.  
  1664.     Turns on video refresh. Use with refreshoff() to control video refresh.
  1665.     NOTE: Turning refresh off is like turning down the monitor brightness all
  1666.     the way - I.E. the screen goes black. Example:
  1667.  
  1668.     #include <graf.h>
  1669.     #include <graphics.h>
  1670.     #include <conio.h>
  1671.     void main()
  1672.     {
  1673.     struct palrec pal[256];
  1674.     vidmod=2;
  1675.     grafon();
  1676.     getallrgbpalette2(pal);
  1677.     fadeout();
  1678.     refreshoff();
  1679.     /* draw stuff now. drawing goes faster with refresh off supposedly. */
  1680.     refreshon();
  1681.     fadein(pal);
  1682.     getch();
  1683.     closegraph();
  1684.     }
  1685.  
  1686.     --------------------------------------------------------------------------
  1687.  
  1688.     void refreshoff(void);
  1689.  
  1690.     Turns off video refresh. Use with refreshon() to control video refresh.
  1691.     NOTE: Turning refresh off is like turning down the monitor brightness all
  1692.     the way - I.E. the screen goes black. Example:
  1693.  
  1694.     #include <graf.h>
  1695.     #include <graphics.h>
  1696.     #include <conio.h>
  1697.     void main()
  1698.     {
  1699.     struct palrec pal[256];
  1700.     vidmod=2;
  1701.     grafon();
  1702.     getallrgbpalette2(pal);
  1703.     fadeout();
  1704.     refreshoff();
  1705.     /* draw stuff now. drawing goes faster with refresh off supposedly. */
  1706.     refreshon();
  1707.     fadein(pal);
  1708.     getch();
  1709.     closegraph();
  1710.     }
  1711.  
  1712.     --------------------------------------------------------------------------
  1713.  
  1714.     void getgrafsize(void *p, int *x, int *y);
  1715.  
  1716.     Gets the size of a bitmap. P points to the bitmap. The width is returned
  1717.     in X, the height in Y. The size returned is in hardware coordinates
  1718.     (pixels), not BC40LIB GRAF coordinates. Use mousex2x() and mousey2y() to
  1719.     convert to GRAF coordinates. Example:
  1720.  
  1721.     #include <graf.h>
  1722.     #include <graphics.h>
  1723.     #include <stdlib.h>
  1724.     void main()
  1725.     {
  1726.     int x,y;
  1727.     void *p;
  1728.     vidmode=2;        /* 320x200x256 */
  1729.     grafon();
  1730.     p=grafget(0,0,10000,10000);    /* get entire screen */
  1731.     getgrafsize(p,&x,&y);
  1732.     /* x is now 320. y is now 200. */
  1733.     x=mousex2x(x);
  1734.     y=mousey2y(y);
  1735.     /* x is now 10000. y is now 10000 */
  1736.     free(p);
  1737.     closegraph();
  1738.     }
  1739.  
  1740.     --------------------------------------------------------------------------
  1741.  
  1742.     void grafcopy(int x,int y,void *p,void *p2);
  1743.  
  1744.     Copies a bitmap into another bitmap. P is the source bitmap to copy. P2
  1745.     is the target bitmap to copy into. The copy is done offscreen in memory.
  1746.     The source bitmap is copied into the target bitmap beginning at
  1747.     offset x,y from the upper left corner of the target bitmap. This routine
  1748.     is currently under construction. Do not use it. It doesn't work yet. This
  1749.     description is included to keep you from wondering what it is.
  1750.  
  1751.     --------------------------------------------------------------------------
  1752.  
  1753.     void setallrgbpalette2(struct palrec *pal);
  1754.  
  1755.     Sets the computer's 256 color palette. Pal points to an array[256] of
  1756.     palrec that contains the new values for the computer's palette. Uses
  1757.     port addressing to set the palette. Appears to be slightly faster than
  1758.     setallrgbpalette() which uses a bios call to set the palette. Example:
  1759.  
  1760.     #include <conio.h>
  1761.     #include <graphics.h>
  1762.     #include <graf.h>
  1763.     struct palrec pal[256];
  1764.     void main()
  1765.     {
  1766.     grafmode=2;
  1767.     grafon();
  1768.     loadpal("test.pal",pal);   /* load test.pal from disk into PAL*/
  1769.     setallrgbpalette(pal);     /* set palette to PAL */
  1770.     getch();
  1771.     closegraph();
  1772.     }
  1773.  
  1774.     --------------------------------------------------------------------------
  1775.  
  1776.     void setrgbpalette2(int regnum,int red,int green,int blue);
  1777.  
  1778.     As BC40's setrgbpalette(). Sets a 256 color palette register using a rom
  1779.     bios interrupt call. Appears to be slightly faster than BC40's
  1780.     setrgbpalette() routine. Example:
  1781.  
  1782.     #include <graphics.h>
  1783.     #include <graf.h>
  1784.     #include <conio.h>
  1785.     void main()
  1786.     {
  1787.     int i;
  1788.     grafmode=2;
  1789.     grafon();
  1790.     clsgraf(0,1);                /* clear screen to black */
  1791.     for (i=0; i<256; i++)           /* fade in red */
  1792.     setrgbpalette2(0,i,0,0);
  1793.     getch();
  1794.     closegraph();
  1795.     }
  1796.  
  1797.     --------------------------------------------------------------------------
  1798.  
  1799.     void setrgbpalette3(int regnum,int red,int green,int blue);
  1800.  
  1801.     As BC40's setrgbpalette(). Sets a 256 color palette register using port
  1802.     Addressing. Appears to be slightly faster than setrgbpalette2() which
  1803.     uses a bios call. Example:
  1804.  
  1805.     #include <graphics.h>
  1806.     #include <graf.h>
  1807.     #include <conio.h>
  1808.     void main()
  1809.     {
  1810.     int i;
  1811.     grafmode=2;
  1812.     grafon();
  1813.     clsgraf(0,1);                     /* clear screen to black */
  1814.     for (i=0; i<256; i++)               /* fade in purple */
  1815.     setrgbpalette2(0,i,0,i);
  1816.     getch();
  1817.     closegraph();
  1818.     }
  1819.  
  1820. ==============================================================================
  1821.  
  1822. Joystick.c:
  1823.     This library provides joystick support routines. Variables and routines
  1824.     are as follows:
  1825.  
  1826.     --------------------------------------------------------------------------
  1827.  
  1828.     extern int hasstick;
  1829.  
  1830.     Boolean variable set by detectstick(). Hasstick=1 means a game port is
  1831.     connected. A joystick may or may not be connected to the game port.
  1832.     Detectstick can't tell if there's a joystick, only a game port.
  1833.     Hasstick=0 means no game port found, therefore no joystick. Example:
  1834.  
  1835.     #include <stdio.h>
  1836.     #include <joystick.h>
  1837.     void main()
  1838.     {
  1839.     detectstick();
  1840.     if (hasstick) printf("Game port found\n");
  1841.     else printf("No game port found\n");
  1842.     }
  1843.  
  1844.     --------------------------------------------------------------------------
  1845.  
  1846.     void getstik(int *x, int *y, int *b1, int *b2);
  1847.  
  1848.     Gets the current joystick status. Returns joystick information in x,y,b1,
  1849.     and b2. X and y are numbers returned by the stick that indicate position.
  1850.     The minimum and maximum values returned for x and y depend on computer
  1851.     speed, and will vary from machine to machine. For x, the minimum value is
  1852.     all the way left. For y, the minimum value is all the way forward.
  1853.     Because the minimum and maximum values for x and y vary with machine, you
  1854.     will need to write a joystick calibration routine to determine the
  1855.     minimum and maximum x and y values returned. B1 and B2 return the status
  1856.     of the buttons. B1 is for button #1, and B2 is for button #2. A value of
  1857.     1 indicates pressed, 0 means not pressed. Example:
  1858.  
  1859.     #include <stdio.h>
  1860.     #include <joystick.h>
  1861.     int x,y,b1,b2;
  1862.     void main()
  1863.     {
  1864.     printf("move stick to upper left and press button 1...\n");
  1865.     do
  1866.       {
  1867.       getstik(&x,&y,*b1,&b2);
  1868.       }
  1869.       while (b1==0);
  1870.     printf("minimum x value is %d\n",x);
  1871.     printf("minimum y value is %d\n",y);
  1872.     }
  1873.  
  1874.     --------------------------------------------------------------------------
  1875.  
  1876.     void nostikbutton();
  1877.  
  1878.     Waits until no joystick buttons are being pressed. Example:
  1879.  
  1880.     #include <stdio.h>
  1881.     #include <joystick.h>
  1882.     int x,y,b1,b2;
  1883.     void main()
  1884.     {
  1885.     printf("press joystick button 1...\n");
  1886.     do
  1887.       {
  1888.       getstik(&x,&y,*b1,&b2);
  1889.       }
  1890.       while (b1==0);
  1891.     printf("button 1 pressed\n");
  1892.     nostikbutton();
  1893.     printf("button 1 released\n");
  1894.     }
  1895.  
  1896.     --------------------------------------------------------------------------
  1897.  
  1898.     void detectstick();
  1899.  
  1900.     Checks for existance of a game port. Sets the global variable Hasstick to
  1901.     1 if a game port is found, else sets hasstick to 0. Example:
  1902.  
  1903.     #include <stdio.h>
  1904.     #include <joystick.h>
  1905.     void main()
  1906.     {
  1907.     detectstick();
  1908.     if (hasstick) printf("Game port found\n");
  1909.     else printf("No game port found\n");
  1910.     }
  1911.  
  1912. ==============================================================================
  1913.  
  1914. Keyboard.c:
  1915.     This library provides interrupt driven keyboard input. It can be used for
  1916.     programs such as keyboard driven realtime simulator games. It replaces
  1917.     the keyboard interrupt handler with a routine that updates an array that
  1918.     stores the current state (pressed or not pressed) of the keys. Once the
  1919.     new handler is installed, the kepressed() function can be used to get the
  1920.     current state (pressed or not pressed) of a key. Routines are as follows:
  1921.  
  1922.     --------------------------------------------------------------------------
  1923.  
  1924.     void startkeyboard();
  1925.  
  1926.     Clears keys array, saves old interrupt 9 (keyboard) handler address,
  1927.     installs new interrupt 9 handler. The new handler updates an array that
  1928.     tracks the state (pressed or not pressed) of the keys, and then calls the
  1929.     old int 9 handler. Call once before accessing keys array via keypressed().
  1930.     Example:
  1931.  
  1932.     #include <keyboard.h>
  1933.     #include <stdio.h>
  1934.     void main()
  1935.     {
  1936.     startkeyboard();
  1937.     do
  1938.       {
  1939.       printf("Esc not pressed\n");
  1940.       }
  1941.       while (! keypressed(0));
  1942.     do
  1943.       {
  1944.       printf("Esc is pressed\n");
  1945.       }
  1946.       while (keypressed(0));
  1947.     stopkeyboard();
  1948.     }
  1949.  
  1950.  
  1951.     --------------------------------------------------------------------------
  1952.  
  1953.     int keypressed(int i);
  1954.  
  1955.     Returns the state of a key. I is the scancode of the key. Returns 1 if
  1956.     the key is being pressed, else returns 0. Example:
  1957.  
  1958.     #include <keyboard.h>
  1959.     #include <stdio.h>
  1960.     void main()
  1961.     {
  1962.     startkeyboard();
  1963.     do
  1964.       {
  1965.       printf("Esc not pressed\n");
  1966.       }
  1967.       while (! keypressed(0));
  1968.     do
  1969.       {
  1970.       printf("Esc is pressed\n");
  1971.       }
  1972.       while (keypressed(0));
  1973.     stopkeyboard();
  1974.     }
  1975.  
  1976.  
  1977.     --------------------------------------------------------------------------
  1978.  
  1979.     void stopkeyboard();
  1980.  
  1981.     Restores the old interrupt 9 handler. Call this routine once when you're
  1982.     done accessing keys array. Example:
  1983.  
  1984.     #include <keyboard.h>
  1985.     #include <stdio.h>
  1986.     void main()
  1987.     {
  1988.     startkeyboard();
  1989.     do
  1990.       {
  1991.       printf("Esc not pressed\n");
  1992.       }
  1993.       while (! keypressed(0));
  1994.     do
  1995.       {
  1996.       printf("Esc is pressed\n");
  1997.       }
  1998.       while (keypressed(0));
  1999.     stopkeyboard();
  2000.     }
  2001.  
  2002. ==============================================================================
  2003.  
  2004. Math2.c:
  2005.     This library provides various math routines. Data structures and routines
  2006.     are as follows:
  2007.  
  2008.     --------------------------------------------------------------------------
  2009.  
  2010.     extern float sinof[360],cosof[360];
  2011.  
  2012.     These arrays are lookup tables that hold the values of the sins and
  2013.     cosines of angles from 0 to 359 degrees. For example sinof[0] holds the
  2014.     sin of 0 degrees. Cosof[0] holds the cosine of 0 degrees. They must be
  2015.     initialized by a call to inittrigtables(). After that you may access them
  2016.     instead of calling sin() and cos(). Accessing the lookup tables runs MUCH
  2017.     faster than calling sin() or cos(). Example:
  2018.  
  2019.     #include <math2.h>
  2020.     #include <stdio.h>
  2021.     int i;
  2022.     void main()
  2023.     {
  2024.     inittrigtables();
  2025.     for (i=0; i<360; i++)
  2026.     printf("i=%d  sin(i)=%f  cos(i)=%f\n",i,sinof[i],cosof[i]);
  2027.     }
  2028.  
  2029.     --------------------------------------------------------------------------
  2030.  
  2031.     int round(float f);
  2032.  
  2033.     Returns the rounded off value of a number. The number is rounded to the
  2034.     nearest integer. Example:
  2035.  
  2036.     #include <math2.h>
  2037.     #include <stdio.h>
  2038.     int i;
  2039.     void main()
  2040.     {
  2041.     i=round(3.141);
  2042.     printf("Round(3.141)=%d\n",i);
  2043.     }
  2044.  
  2045.     --------------------------------------------------------------------------
  2046.  
  2047.     int headingto(long x1, long y1, long x2, long y2);
  2048.  
  2049.     Returns the compass heading (0 to 359 degrees) from point x1,y1 to point
  2050.     x2,y2. The points are points on a right cartiesan plane coordinate
  2051.     system. Example:
  2052.  
  2053.     #include <math2.h>
  2054.     #include <stdio.h>
  2055.     int i;
  2056.     void main()
  2057.     {
  2058.     i=headingto(1,1,2,2);   /* i is 45 degrees */
  2059.     printf("heading from 1,1 to 2,2 is %d degrees\n",i);
  2060.     }
  2061.  
  2062.     --------------------------------------------------------------------------
  2063.  
  2064.     int markvalue(long x1, long y1, long z1, long x2, long y2, long z2);
  2065.  
  2066.     Returns the spherical coordinate system second angle (rho - angle of
  2067.     inclination) from the point x1,y1,z1 to the point x2,y2,z2. The points
  2068.     are in right cartesian coordinates. For the value returned, 0 is
  2069.     horizontal, 90 is up, -90 is down 180/-180 is upsidedown & opposite
  2070.     direction. Example:
  2071.  
  2072.     #include <math2.h>
  2073.     #include <stdio.h>
  2074.     int i;
  2075.     void main()
  2076.     {
  2077.     i=markvalue(1,1,1,2,2,2);   /* i is 45 degrees */
  2078.     printf("markvalue from 1,1,1 to 2,2,2 is %d degrees\n",i);
  2079.     }
  2080.  
  2081.     --------------------------------------------------------------------------
  2082.  
  2083.     long dist3d(long x1, long y1, long z1, long x2, long y2, long z2);
  2084.  
  2085.     Returns the 3 dimentional distance from point x1,y1,z1 to point x2,y2,z2.
  2086.     the points are in right cartesian coodinates. Example:
  2087.  
  2088.     #include <math2.h>
  2089.     #include <stdio.h>
  2090.     long l;
  2091.     void main()
  2092.     {
  2093.     l=dist3d(1,1,1,20,20,20);
  2094.     printf("distance from 1,1,1 to 20,20,20 is %d\n",l);
  2095.     }
  2096.  
  2097.     --------------------------------------------------------------------------
  2098.  
  2099.     void i2s(long i,char *s);
  2100.  
  2101.     Converts an integer to a string. I is the integer to convert. S is the
  2102.     string to return the result in. Example:
  2103.  
  2104.     #include <math2.h>
  2105.     #include <stdio.h>
  2106.     int i;
  2107.     char s[100];
  2108.     void main()
  2109.     {
  2110.     i=45;
  2111.     i2s(i,s);
  2112.     printf("i = %s\n",s);
  2113.     }
  2114.  
  2115.     --------------------------------------------------------------------------
  2116.  
  2117.     void l2s(long i,char *s);
  2118.  
  2119.     Converts a long integer to a string. I is the integer to convert. S is the
  2120.     string to return the result in. Example:
  2121.  
  2122.     #include <math2.h>
  2123.     #include <stdio.h>
  2124.     int i;
  2125.     char s[100];
  2126.     void main()
  2127.     {
  2128.     i=45;
  2129.     i2s(i,s);
  2130.     printf("i = %s\n",s);
  2131.     }
  2132.  
  2133.     --------------------------------------------------------------------------
  2134.  
  2135.     void f2s(float f,char *s);
  2136.  
  2137.     Converts a float to a string. F is the float to convert. S is the
  2138.     string to return the result in. The result will have 20 digits. Example:
  2139.  
  2140.     #include <math2.h>
  2141.     #include <stdio.h>
  2142.     float i;
  2143.     char s[100];
  2144.     void main()
  2145.     {
  2146.     i=1.0;
  2147.     f2s(i,s);
  2148.     printf("i = %s\n",s);   /* prints "i = 1.0000000000000000000"   */
  2149.     }
  2150.  
  2151.     --------------------------------------------------------------------------
  2152.  
  2153.     void f2s2(float f,char *s);
  2154.  
  2155.     Converts a float to a string. F is the float to convert. S is the
  2156.     string to return the result in. The result will have 2 decimal places.
  2157.     Example:
  2158.  
  2159.     #include <math2.h>
  2160.     #include <stdio.h>
  2161.     float i;
  2162.     char s[100];
  2163.     void main()
  2164.     {
  2165.     i=1.0;
  2166.     f2s(i,s);
  2167.     printf("i = %s\n",s);   /* prints "i = 1.00"   */
  2168.     }
  2169.  
  2170.     --------------------------------------------------------------------------
  2171.  
  2172.     int s2i(char *s);
  2173.  
  2174.     Converts a string to an integer. Returns the integer value of string S.
  2175.     Example:
  2176.  
  2177.     #include <math2.h>
  2178.     #include <stdio.h>
  2179.     #include <string.h>
  2180.     int i;
  2181.     char s[100];
  2182.     void main()
  2183.     {
  2184.     strcpy(s,"100");
  2185.     i=s2i(s);
  2186.     printf("s = %d\n",i);
  2187.     }
  2188.  
  2189.     --------------------------------------------------------------------------
  2190.  
  2191.     long s2l(char *s);
  2192.  
  2193.     Converts a string to a long integer. Returns the integer value of string
  2194.     S. Example:
  2195.  
  2196.     #include <math2.h>
  2197.     #include <stdio.h>
  2198.     #include <string.h>
  2199.     long i;
  2200.     char s[100];
  2201.     void main()
  2202.     {
  2203.     strcpy(s,"100000");
  2204.     i=s2l(s);
  2205.     printf("s = %d\n",i);
  2206.     }
  2207.  
  2208.     --------------------------------------------------------------------------
  2209.  
  2210.     int isin(int x, int y, int x1, int y1, int x2, int y2);
  2211.  
  2212.     Returns 1 if point x,y is in the area x1,y1,x2,y2. Otherwise returns 0.
  2213.     Useful for seeing if the user clicked in an area, etc. Example:
  2214.  
  2215.     #include <math2.h>
  2216.     #include <graf.h>
  2217.     #include <graphics.h>
  2218.     #include <mouse.h>
  2219.     int x,y;
  2220.     void main()
  2221.     {
  2222.     vidmode=1;
  2223.     grafon();
  2224.     resetmouse();
  2225.     grafrect(1000,1000,2000,2000,15,0,1);
  2226.     saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,
  2227.                          "Click in rectangle to quit");
  2228.     do
  2229.       {
  2230.       select(x,y,1);
  2231.       }
  2232.       while (! isin(x,y,1000,1000,2000,2000));
  2233.     closegraph();
  2234.     }
  2235.  
  2236.     --------------------------------------------------------------------------
  2237.  
  2238.     int dice(int i);
  2239.  
  2240.     Returns the roll of a I sided die. Ie: dice(6) returns the roll of a 6
  2241.     sided die, and dice(100) retruns the roll of a 100 sided die. You must
  2242.     call the standard routine randomize() once at program start to initialize
  2243.     the random number generator before you can call dice(). Example:
  2244.  
  2245.     #include <stdlib.h>
  2246.     #include <math2.h>
  2247.     #include <stdio.h>
  2248.     void main()
  2249.     {
  2250.     randomize();
  2251.     printf("%d\n",dice(6));   /* prints random number 1 to 6 */
  2252.     }
  2253.  
  2254.     --------------------------------------------------------------------------
  2255.  
  2256.     void ulim(int *i, int j);
  2257.  
  2258.     Upper limits i to a value no greater than j. IE: if i>j, i=j. Example:
  2259.  
  2260.     #include <math2.h>
  2261.     #include <stdio.h>
  2262.     int i;
  2263.     void main()
  2264.     {
  2265.     i=10;
  2266.     ulim(&i,5);
  2267.     printf("%d\n",i);   /* prints 5 */
  2268.     i=10;
  2269.     ulim(&i,20);
  2270.     printf("%d\n",i);   /* prints 10 */
  2271.     }
  2272.  
  2273.     --------------------------------------------------------------------------
  2274.  
  2275.     void normalize(int *i);
  2276.  
  2277.     Converts a degree value i to its equivalent value in the range 0 to 359
  2278.     degrees. Example:
  2279.  
  2280.     #include <math2.h>
  2281.     #include <stdio.h>
  2282.     int i;
  2283.     void main()
  2284.     {
  2285.     i=35;
  2286.     normalize(&i);
  2287.     printf("%d\n",i);   /* prints 35 */
  2288.     i=-45;
  2289.     normalize(&i);
  2290.     printf("%d\n",i);   /* prints 315 */
  2291.     i=360;
  2292.     normalize(&i);
  2293.     printf("%d\n",i);   /* prints 0 */
  2294.     }
  2295.  
  2296.     --------------------------------------------------------------------------
  2297.  
  2298.     void llim(int *i, int j);
  2299.  
  2300.     Lower limits i to a value no less than j. IE: if i<j i=j. Example:
  2301.  
  2302.     #include <math2.h>
  2303.     #include <stdio.h>
  2304.     int i;
  2305.     void main()
  2306.     {
  2307.     i=10;
  2308.     llim(&i,5);
  2309.     printf("%d\n",i);   /* prints 10 */
  2310.     i=10;
  2311.     llim(&i,20);
  2312.     printf("%d\n",i);   /* prints 20 */
  2313.     }
  2314.  
  2315.     --------------------------------------------------------------------------
  2316.  
  2317.     void inittrigtables();
  2318.  
  2319.     Initializes the sinof[] and cosof[] lookup table arrays. Call once before
  2320.     using the sinof[] and cosof[] lookup table arrays. Example:
  2321.  
  2322.     #include <math2.h>
  2323.     #include <stdio.h>
  2324.     int i;
  2325.     void main()
  2326.     {
  2327.     inittrigtables();
  2328.     for (i=0; i<360; i++)
  2329.     printf("i=%d  sin(i)=%f  cos(i)=%f\n",i,sinof[i],cosof[i]);
  2330.     }
  2331.  
  2332.     --------------------------------------------------------------------------
  2333.  
  2334.     long dist2d(long x1, long y1, long x2, long y2);
  2335.  
  2336.     Returns the 2 dimentional distance from point x1,y1 to point x2,y2.
  2337.     the points are in right cartesian coodinates. Example:
  2338.  
  2339.     #include <math2.h>
  2340.     #include <stdio.h>
  2341.     long l;
  2342.     void main()
  2343.     {
  2344.     l=dist2d(1,1,20,20);
  2345.     printf("distance from 1,1 to 20,20 is %d\n",l);
  2346.     }
  2347.  
  2348. ==============================================================================
  2349.  
  2350. Mouse.c:
  2351.     This library provides routines for using a Microsoft compatable mouse.
  2352.     Data structures and routines are as follows:
  2353.  
  2354.     --------------------------------------------------------------------------
  2355.  
  2356.     extern int hasmouse;
  2357.  
  2358.     Global boolean. If hasmouse=1, then they have a mouse. If hasmouse=0 they
  2359.     don't. This variable is set by the resetmouse() routine. Example:
  2360.  
  2361.     #include <stdio.h>
  2362.     #include <mouse.h>
  2363.     void main()
  2364.     {
  2365.     resetmouse();
  2366.     if (hasmouse) printf("mouse found\n");
  2367.     else printf("mouse not found\n");
  2368.     }
  2369.  
  2370.     --------------------------------------------------------------------------
  2371.  
  2372.     void resetmouse();
  2373.  
  2374.     Resets the mouse. Call once at program start before using the mouse.
  2375.     Sets the hasmouse variable. Example:
  2376.  
  2377.     #include <stdio.h>
  2378.     #include <mouse.h>
  2379.     void main()
  2380.     {
  2381.     resetmouse();
  2382.     if (hasmouse) printf("mouse found\n");
  2383.     else printf("mouse not found\n");
  2384.     }
  2385.  
  2386.     --------------------------------------------------------------------------
  2387.  
  2388.     int mousebutton();
  2389.  
  2390.     Returns the current mouse button state. The values returned are:
  2391.     0=no buttons pressed.
  2392.     1=left button pressed.
  2393.     2=right button pressed.
  2394.     3=left and right buttons pressed.
  2395.     4=middle button pressed.
  2396.     5=middle and left buttons pressed.
  2397.     6=middle and right buttons pressed.
  2398.     7=all three buttons pressed.
  2399.     Example:
  2400.  
  2401.     #include <stdio.h>
  2402.     #include <mouse.h>
  2403.     int i;
  2404.     void main()
  2405.     {
  2406.     resetmouse();
  2407.     do
  2408.       {
  2409.       i=mousebutton();
  2410.       if (i==1) printf("left button pressed\n");
  2411.       }
  2412.       while (i != 2);
  2413.     }
  2414.  
  2415.     --------------------------------------------------------------------------
  2416.  
  2417.     void nobutton();
  2418.  
  2419.     Waits until no mouse buttons are being pressed. Example:
  2420.  
  2421.     #include <stdio.h>
  2422.     #include <mouse.h>
  2423.     void main()
  2424.     {
  2425.     resetmouse();
  2426.     printf("press and hold left mouse button\n");
  2427.     do
  2428.       {
  2429.       }
  2430.       while (mousebutton() != 1);
  2431.     printf("release all mouse buttons\n");
  2432.     nobutton();
  2433.     }
  2434.  
  2435.     --------------------------------------------------------------------------
  2436.  
  2437.     void showmouse();
  2438.  
  2439.     Makes the mouse cursor appear on the screen. Example:
  2440.  
  2441.     #include <stdio.h>
  2442.     #include <mouse.h>
  2443.     void main()
  2444.     {
  2445.     resetmouse();
  2446.     showmouse();
  2447.     do
  2448.       {
  2449.       }
  2450.       while (! mousebutton());
  2451.     hidemouse();
  2452.     }
  2453.  
  2454.     --------------------------------------------------------------------------
  2455.  
  2456.     void hidemouse();
  2457.  
  2458.     Makes the mouse cursor disappear. Example:
  2459.  
  2460.     #include <stdio.h>
  2461.     #include <mouse.h>
  2462.     void main()
  2463.     {
  2464.     resetmouse();
  2465.     showmouse();
  2466.     do
  2467.       {
  2468.       }
  2469.       while (! mousebutton());
  2470.     hidemouse();
  2471.     nobutton();
  2472.     do
  2473.       {
  2474.       }
  2475.       while (! mousebutton());
  2476.     showmouse();
  2477.     nobutton();
  2478.     do
  2479.       {
  2480.       }
  2481.       while (! mousebutton());
  2482.     hidemouse();
  2483.     }
  2484.  
  2485.     --------------------------------------------------------------------------
  2486.  
  2487.     void getmouse(int *x,int *y,int *b);
  2488.  
  2489.     Gets the current state of the mouse. x,y is its position on screen in
  2490.     hardware video coordinates. B is the button state. Values for B are the
  2491.     same as in the mousebutton() routine. Example:
  2492.  
  2493.     #include <stdio.h>
  2494.     #include <mouse.h>
  2495.     int x,y,b;
  2496.     void main()
  2497.     {
  2498.     resetmouse();
  2499.     showmouse();
  2500.     do
  2501.       {
  2502.       getmouse(&x,&y,&b);
  2503.       }
  2504.       while (b==0);
  2505.     hidemouse();
  2506.     }
  2507.  
  2508.     --------------------------------------------------------------------------
  2509.  
  2510.     void putmouse(int x,int y);
  2511.  
  2512.     Moves the mouse to point x,y (video hardware coordinates). Example:
  2513.  
  2514.     #include <stdio.h>
  2515.     #include <mouse.h>
  2516.     int x,y,b;
  2517.     void main()
  2518.     {
  2519.     resetmouse();
  2520.     showmouse();                     /* show mouse */
  2521.     do                               /* wait for click */
  2522.       {
  2523.       getmouse(&x,&y,&b);
  2524.       }
  2525.       while (b==0);
  2526.     hidemouse();                    /* hide mouse */
  2527.     putmouse(0,0);         /* move mouse to upper left corner of screen */
  2528.     showmouse();                   /* show mouse */
  2529.     nobutton();                  /* wait for no mouse buttons */
  2530.     do                              /* wait for click */
  2531.       {
  2532.       getmouse(&x,&y,&b);
  2533.       }
  2534.       while (b==0);
  2535.     hidemouse();                      /* hide mouse */
  2536.     }
  2537.  
  2538. ==============================================================================
  2539.  
  2540. Timer.c:
  2541.     This library provides routines for accurate timing delays. The routines
  2542.     run off the DOS system clock. This gives you delays that are the same
  2543.     on different PCs. These routines work well for timing screen updates to
  2544.     soundcard music. Routines are as follows:
  2545.  
  2546.     --------------------------------------------------------------------------
  2547.  
  2548.     void starttimer();
  2549.  
  2550.     Initializes the timer to zero. Call this routine to begin timing. Example:
  2551.  
  2552.     #include <timer.h>
  2553.     #include <stdio.h>
  2554.     void main()
  2555.     {
  2556.     int i;
  2557.     long l;
  2558.     starttimer();
  2559.     for (i=0; i<1000; i++)
  2560.     {
  2561.     }
  2562.     l=elapsedtime();
  2563.     printf("%d\n",l);    /* print # of millisecs to run the loop */
  2564.     }
  2565.  
  2566.     --------------------------------------------------------------------------
  2567.  
  2568.     long elapsedtime(void);
  2569.  
  2570.     Returns the elapsed time (in milliseconds) since starttimer() was called.
  2571.     Example:
  2572.  
  2573.     #include <timer.h>
  2574.     #include <stdio.h>
  2575.     void main()
  2576.     {
  2577.     int i;
  2578.     long l;
  2579.     starttimer();
  2580.     for (i=0; i<1000; i++)
  2581.     {
  2582.     }
  2583.     l=elapsedtime();
  2584.     printf("%d\n",l);    /* print # of millisecs to run the loop */
  2585.     }
  2586.  
  2587. ==============================================================================
  2588.  
  2589. Help.c:
  2590.     This library provides you with a help file viewer. The viewer runs in
  2591.     graphics, and has search and print capabilites. The viewer can display
  2592.     any ascii file. The help library contains one routine:
  2593.  
  2594.     --------------------------------------------------------------------------
  2595.  
  2596.     void showhelp(char *s2);
  2597.  
  2598.     Shows an ascii file. S2 is the name of the file to show. Example:
  2599.  
  2600.     #include <graf.h>
  2601.     #include <mouse.h>
  2602.     #include <graphics.h>
  2603.     void main()
  2604.     {
  2605.     vidmode=1;
  2606.     grafon();
  2607.     resetmouse();
  2608.     showhelp("c:\\autoexec.bat");
  2609.     closegraph();
  2610.     }
  2611.  
  2612. ==============================================================================
  2613.  
  2614. Getfile.c:
  2615.     This library provides a file selection dialog box. The library consists
  2616.     of one routine getfile() which shows a dialog box and lets the user select
  2617.     a file.
  2618.  
  2619.     --------------------------------------------------------------------------
  2620.  
  2621.     void getfile(char *promptstr, char *searchspec, char *returnstr,
  2622.           int forecolor,int forecolor2,int bakcolor,int doaclick);
  2623.  
  2624.     Shows a dialog box that lets the user select a file. Promptstr is the
  2625.     prompt to display (such as "Load file..."). Searchspec is the filespec
  2626.     used for showing files (such as "*.*" or "*.dat" etc). Returnstr is the
  2627.     string that the name of the selected file is returned in. Forecolor is
  2628.     the text color, forecolor2 is the text shadow color, and bakcolor is the
  2629.     box color. If doaclick=1, a click will be made when the user clicks on
  2630.     a selection. No click will be made if doclick=0. Returns the complete
  2631.     filename (drive, directory, filename, and extension). Saves and restores
  2632.     the screen behind the box. Returns "" if user cancels. User can change
  2633.     drives, directories, and the searchspec. User can select a file, enter
  2634.     a filename, or cancel. Shows alpabetized listings of files and subdirs.
  2635.     User can scroll and page through subdir and file lists. Sorts lists in
  2636.     memory for speed. Can handle up to 100 subdirs per directory, and 1000
  2637.     files per directory. Example:
  2638.  
  2639.     #include <graf.h>
  2640.     #include <graphics.h>
  2641.     #include <getfile.h>
  2642.     #include <edit.h>
  2643.     #include <string.h>
  2644.     #include <mouse.h>
  2645.     void main()
  2646.     {
  2647.     char s[100];
  2648.     vidmode=1;
  2649.     grafon();
  2650.     resetmouse();
  2651.     getfile("Select file to edit...","*.*",s,15,0,7,1);
  2652.     if (strcmp(s,"") !=0) editfile(s,15,0,7,1);
  2653.     closegraph();
  2654.     }
  2655.  
  2656. ==============================================================================
  2657.  
  2658.  
  2659.  
  2660.