home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 14 / CD_ASCQ_14_0694.iso / maj / 4524 / svgademo.c < prev    next >
C/C++ Source or Header  |  1994-05-09  |  15KB  |  612 lines

  1. /****************************************************************************
  2.      
  3.       'SVGACC' A Super Vga Graphics Library for use with Microsoft and
  4.       Borland C/C++
  5.       Copyright 1993-1994 by Stephen L. Balkum and Daniel A. Sill
  6.  
  7.       GIF and 'Graphics Intechange Format' are trademarks (tm) of
  8.       Compuserve, Incorporated, an H&R Block Company.
  9.  
  10.     **************** UNREGISTERD SHAREWARE VERSION ***********************
  11.     * FOR EVUALATION ONLY. NOT FOR RESALE IN ANY FORM. SOFTWARE WRITTEN  *
  12.     * USING THIS UNREGISTERED SHAREWARE GRAPHICS LIBRARY MAY NOT BY SOLD *
  13.     * OR USED FOR ANY PURPOSE OTHER THAN THE EVUALTION OF THIS LIBRARY.  *
  14.     **********************************************************************
  15.  
  16.     **************** NO WARRANTIES AND NO LIABILITY **********************
  17.     * Stephen L. Balkum and Daniel A. Sill provide no warranties, either *
  18.     * expressed or implied, of merchantability, or fitness, for a        *
  19.     * particular use or purpose of this SOFTWARE and documentation.      *
  20.     * In no event shall Stephen L. Balkum or Daniel A. Sill be held      *
  21.     * liable for any damages resulting from the use or misuse of the     * 
  22.     * SOFTWARE and documentation.                                        *
  23.     **********************************************************************
  24.  
  25.     ************** U.S. GOVERNMENT RESTRICTED RIGHTS *********************
  26.     * Use, duplication, or disclosure of the SOFTWARE and documentation  *
  27.     * by the U.S. Government is subject to the restictions as set forth  *
  28.     * in subparagraph (c)(1)(ii) of the Rights in Technical Data and     *
  29.     * Computer Software cluse at DFARS 252.227-7013.                     *
  30.     * Contractor/manufacturer is Stephen L. Balkum and Daniel A. Sill,   *
  31.     * P.O. Box 7704, Austin, Texas 78713-7704                            *
  32.     **********************************************************************
  33.  
  34.     **********************************************************************
  35.     * By using this SOFTWARE or documentation, you agree to the above    *
  36.     * terms and conditions.                                              *
  37.     **********************************************************************
  38.  
  39.  ***************************************************************************/
  40.     
  41.  
  42. #include <stdio.h>
  43. #include <conio.h>
  44. #include <stdlib.h>
  45. #include <string.h>
  46. #include <math.h>
  47. #include <dos.h>
  48.  
  49. #include "svgacc.h"
  50.  
  51. #include "svgademo.h"
  52.  
  53.  
  54. void main(void) {
  55.  
  56.     int startvideomode;
  57.     int i, max, ky;
  58.     int mjv, mnv, tp;
  59.     int cpu, videomemory;
  60.     int mouse, joystick;
  61.     int res;
  62.     int offset, colr;
  63.     float mypi;
  64.     char dummy;
  65.     char buf[TITLEN];
  66.     char *dumptr;
  67.     
  68.     
  69.     /*
  70.      * Save the starting videomode and set it to mode 3.
  71.      */
  72.     startvideomode = videomodeget();
  73.     restext();
  74.     screenclear();
  75.     
  76.     /*
  77.      * Move the DOS cursor to the top left to start the program and say hello
  78.      */
  79.     screengoto(11,0);
  80.     printf("/*SVGACC.LIB/* A SuperVGA Graphics Library for use with\n");
  81.     screengoto(23,1);
  82.     printf("Microsoft and Borland C/C++\n");
  83.     screengoto(9,2);
  84.     printf("Copyright 1993-1994 by Stephen L. Balkum and Daniel A. Sill\n");
  85.     screengoto(23,11);
  86.     printf("Demonstration/Example Program\n");
  87.     screengoto(0,22);
  88.     printf("press a key to begin the demo...\n");
  89.     getkey();
  90.  
  91.     screenclear();
  92.    
  93.     /*
  94.      * Let's id the processor first as the library requires a 386 or better.
  95.      */
  96.     screengoto(0,0);
  97.     cpu = whichcpu();
  98.     if (cpu < 386) {
  99.         printf("Sorry, this library requires an 80386 or better processor.\n");
  100.         printf("Processor is identified as an 80%d.\n", cpu);
  101.         printf("Demo program will be terminated.\n\n");
  102.         printf("press a key...\n");
  103.         getkey();
  104.         videomodeset(startvideomode);
  105.         exit(0);
  106.     }
  107.  
  108.  
  109.     /*
  110.      * Let's id the video card/chip as the library requires a SuperVGA adapter.
  111.      */
  112.     switch(whichvga()) {
  113.         case ACUMOS:
  114.             sprintf(buf,"Acumos AVGA2/3 SuperVGA");
  115.             break;
  116.         case ATI:
  117.             sprintf(buf,"ATI Technologies 18/28/38/68800 SuperVGA");
  118.             break;
  119.         case AHEADA:
  120.             sprintf(buf,"Ahead V5000 Ver A SuperVGA");
  121.             break;
  122.         case AHEADB:
  123.             sprintf(buf,"Ahead V5000 Ver B SuperVGA");
  124.             break;
  125.         case CHIPSTECH:
  126.             sprintf(buf,"Chips and Technologies 82C450/1/2/3/5/6/7 SuperVGA");
  127.             break;
  128.         case CIRRUS:
  129.             sprintf(buf,"Cirrus Logic CL-GD 5xx,6xx,28xx,54xx,62xx SuperVGA");
  130.             break;
  131.         case EVEREX:
  132.             sprintf(buf,"Everex EV236/6xx Micro Enhancer SuperVGA");
  133.             break;
  134.         case GENOA:
  135.             sprintf(buf,"Genoa 61/62/63/64/6600 SuperVGA");
  136.             break;
  137.         case NCR:
  138.             sprintf(buf,"NCR 77C21/22/22E/22E+ SuperVGA");
  139.             break;
  140.         case OAKTECH:
  141.             sprintf(buf,"Oak Technologies OTI-037/67/77/87C SuperVGA");
  142.             break;
  143.         case PARADISE:
  144.             sprintf(buf,"Paradise/Western Digital PVGA1A,WD90C00/1x/2x/3x SuperVGA");
  145.             break;
  146.         case REALTEK:
  147.             sprintf(buf,"Realtek RT3106 SuperVGA");
  148.             break;
  149.         case TRIDENT:
  150.             sprintf(buf,"Trident 8800CS,8900B/C/CL/CX,90x0 SuperVGA");
  151.             break;
  152.         case TSENG3:
  153.             sprintf(buf,"Tseng Labs ET3000-AX/BX/BP SuperVGA");
  154.             break;
  155.         case TSENG4:
  156.             sprintf(buf,"Tseng Labs ET4000/W32/W32I SuperVGA");
  157.             break;
  158.         case VESA:
  159.             sprintf(buf,"VESA compatible SuperVGA");
  160.             break;
  161.         case VIDEO7:
  162.             sprintf(buf,"Video 7 HT-208/16 SuperVGA");
  163.             break;
  164.         case AVANCE:
  165.             sprintf(buf,"Avance Logic AL2101 SuperVGA");
  166.             break;
  167.         case MXIC:
  168.             sprintf(buf,"MXIC MX68000/10 SuperVGA");
  169.             break;
  170.         case PRIMUS:
  171.             sprintf(buf,"Primus P2000 SuperVGA");
  172.             break;
  173.         default:
  174.             printf("Microprocessor is identified as an 80%d.\n", cpu);
  175.             printf("Sorry, unable to identify video card or it is not a SuperVGA video adapter.\n");
  176.             printf("Demo program will be terminated.\n\n");
  177.             printf("press a key...\n");
  178.             getkey();
  179.             videomodeset(startvideomode);
  180.             exit(0);
  181.     }
  182.     printf("Microprocessor is identified as an 80%d.\n", cpu);
  183.     
  184.     fontsystem();
  185.     printf("Video card/chip is identified as %s.\n",&buf);
  186.    
  187.     /*
  188.      * Let's see the how much memory is installed on the super vga adapter.
  189.      */
  190.     videomemory = whichmem();
  191.     if (videomemory < 1) {
  192.         printf("Sorry, unable to identify the amount of installed video memory.\n");
  193.         printf("Demo program will be terminated.\n\n");
  194.         printf("press a key...\n");
  195.         getkey();
  196.         videomodeset(startvideomode);
  197.         exit(0);
  198.     } else
  199.         printf("Installed video memory identified as %dkb.\n", videomemory);
  200.        
  201.     /*
  202.      * Let's tell the user what the highest resolution that the video card
  203.      * and its installed memory card is capable of. The monitor must be able
  204.      * to support those modes too !
  205.      */
  206.     printf("Video card and installed memory is capable of the following resolutions:\n");
  207.     if (videomemory > 2047) {
  208.         printf("    320x200 in 256 colors\n");
  209.         printf("    640x400 in 256 colors\n");
  210.         printf("    640x480 in 256 colors\n");
  211.         printf("    800x600 in 256 colors\n");
  212.         printf("    1024x768 in 256 colors\n");
  213.         printf("    1280x1024 in 256 colors\n");
  214.         max = 5;
  215.     } else if (videomemory > 1023) {
  216.         printf("    320x200 in 256 colors\n");
  217.         printf("    640x400 in 256 colors\n");
  218.         printf("    640x480 in 256 colors\n");
  219.         printf("    800x600 in 256 colors\n");
  220.         printf("    1024x768 in 256 colors\n");
  221.         max = 4;
  222.     } else if (videomemory > 511) {
  223.         printf("    320x200 in 256 colors\n");
  224.         printf("    640x400 in 256 colors\n");
  225.         printf("    640x480 in 256 colors\n");
  226.         printf("    800x600 in 256 colors\n");
  227.         max = 3;
  228.     } else {
  229.         printf("    320x200 in 256 colors\n");
  230.         printf("    640x400 in 256 colors\n");
  231.         max = 1;
  232.     }
  233.     printf("\nPlease keep in mind that not all monitors support all resolutions. If You\n");
  234.     printf("know your monitor will not work properly at very high resolution(ie 1024x768\n");
  235.     printf("or 1280x1024) then do NOT attempt to run the demo in that resolution.\n\n");
  236.  
  237.     /*
  238.      * Let's look for a mouse. if we find one, tell all about it
  239.      */
  240.     mouse = whichmouse();
  241.     if (mouse > 0) {
  242.         mouseinfo(&mjv, &mnv, &tp, &i);
  243.         switch (tp) {
  244.             case 1:
  245.                 sprintf(buf,"bus mouse");
  246.                 break;
  247.             case 2:
  248.                 sprintf(buf,"serial mouse");
  249.                 break;
  250.             case 3:
  251.                 sprintf(buf,"Inport mouse");
  252.                 break;
  253.             case 4:
  254.                 sprintf(buf,"PS/2 mouuse");
  255.                 break;
  256.             case 5:
  257.                 sprintf(buf,"HP mouse");
  258.                 break;
  259.             default:
  260.                 sprintf(buf,"unknown type");
  261.         }
  262.         printf("Microsoft compatible %s detected with %d buttons on IRQ %d.\n", &buf, mouse, i);
  263.         printf("Software driver version is %d.%d (Microsoft equivalent version).\n\n", mjv, mnv);
  264.  
  265.     } else
  266.         printf("No Microsoft compatible mouse detected.\n\n");
  267.  
  268.     /*
  269.      * Let's look for joysticks
  270.      */
  271.     joystick = whichjoystick();
  272.     switch (joystick) {
  273.         case -1:
  274.             printf("No joystick port detected or no joystick BIOS support present.\n\n");
  275.             break;
  276.         case 0:
  277.             printf("No joystick detected\n\n");
  278.             break;
  279.         case 1:
  280.             printf("Joystick A is present and available.\n\n");
  281.             break;
  282.         case 2:
  283.             printf("Joystick B is present and available.\n\n");
  284.             break;
  285.         case 3:
  286.             printf("Both Joystick A and Joystick B are present and available.\n\n");
  287.             break;
  288.     }
  289.     printf("press a key...\n");
  290.     getkey();
  291.  
  292.  
  293.     /*
  294.      * Let's get down to business
  295.      */
  296.     res = 1;
  297.     endit = 0;
  298.     ky=0;
  299.     
  300.     /*
  301.      * Init alternate color palettes
  302.      */
  303.  
  304.     res320();
  305.     palget(orgpal, 0, 255);
  306.     palcopy(orgpal,pal,0,255);
  307.     palcopy(orgpal,pal2,0,255);
  308.     mypi=(float)(8 * atan(1) / 240);
  309.     offset = 16;
  310.     for (colr=0;colr<240;colr++,offset++) {
  311.         pal[offset].r = (char)(32.0 + sin((colr + 0) * mypi) * 31.0);
  312.         pal[offset].g = (char)(32.0 + sin((colr + 80) * mypi) * 31.0);
  313.         pal[offset].b = (char)(32.0 + sin((colr + 160) * mypi) * 31.0);
  314.         pal2[offset].r = (char)(32.0 + sin((colr + 10) * mypi) * 31.0);
  315.         pal2[offset].g = (char)(32.0 + sin((colr + 30) * mypi) * 31.0);
  316.         pal2[offset].b = (char)(32.0 + sin((colr + 50) * mypi) * 31.0);
  317.     }
  318.     restext();
  319.  
  320.     /*
  321.      * Here is the main selector loop
  322.      */
  323.     while (endit == 0) {
  324.         screenclear();
  325.         switch (res) {
  326.             case 1: 
  327.                 sprintf(buf,"320x200x256");
  328.                 break;
  329.             case 2:
  330.                 sprintf(buf,"640x400x256");
  331.                 break;
  332.             case 3:
  333.                 sprintf(buf,"640x480x256");
  334.                 break;
  335.             case 4:
  336.                 sprintf(buf,"800x600x256");
  337.                 break;
  338.             case 5:
  339.                 sprintf(buf,"1024x768x256");
  340.             case 6:
  341.                 sprintf(buf,"1280x1024x256");
  342.         }
  343.         printf("Please select the demo you would like to see in the %s resolution:\n\n",&buf);
  344.         printf("(0)  Exit This Program\n\n");
  345.         printf("(1)  Demo #1  The Primitive Drawing Routines\n");
  346.         printf("(2)  Demo #2  The Clipping Capabilities\n");
  347.         printf("(3)  Demo #3  The Fill Routines\n");
  348.         printf("(4)  Demo #4  The Palette Routines\n");
  349.         printf("(5)  Demo #5  The Block Routines\n");
  350.         printf("(6)  Demo #6  The Text Routines\n");
  351.         printf("(7)  Demo #7  The Scrolling Routines\n");
  352.         printf("(8)  Demo #8  The GIF (tm) Routines\n");
  353.         printf("(9)  Demo #9  The Mouse Routines\n");
  354.         printf("(10) Demo #10 The Joystick Routines\n");
  355.         printf("(11) Demo #11 The Two Dimensional Routines\n");
  356.         printf("(12) Demo #12 The Three Dimensional Routines\n");
  357.         printf("(13) The Grand Tour of All Demos\n");
  358.         printf("(14) Use 320x200 in 256 colors\n");
  359.         printf("(15) Use 640x400 in 256 colors\n");
  360.         max = 15;
  361.         if (videomemory > 511) {
  362.             printf("(16) Use 640x480 in 256 colors\n");
  363.             printf("(17) Use 800x600 in 256 colors\n");
  364.             max = 17;
  365.         } 
  366.         if (videomemory > 1023) {
  367.             printf("(18) Use 1024x768 in 256 colors\n");
  368.             max = 18;
  369.         }
  370.         if (videomemory > 2047) {
  371.             printf("(19) Use 1280x1024 in 256 colors\n");
  372.             max = 19;
  373.         }
  374.  
  375.         printf("\nYour Choice: ");
  376.         for (i=0;i<3;i++) {
  377.             dummy = (char)getch();
  378.             switch (dummy) {
  379.                 case 13:
  380.                     if (i == 0)
  381.                         i--;
  382.                     else {
  383.                         buf[i]='\0';
  384.                         i=2;
  385.                     }
  386.                     break;
  387.                 case 8:
  388.                     i--;
  389.                     if (i > (-1)) {
  390.                         printf("\b \b");
  391.                         i--;
  392.                     }
  393.                     break;
  394.                 default:
  395.                     if ((dummy < '0') || (dummy > '9'))
  396.                         i--;
  397.                     else if (i < 2) {
  398.                         printf("%c",dummy);
  399.                         buf[i] = dummy;
  400.                     } else
  401.                         buf[i] = '\0';
  402.  
  403.             }
  404.         }
  405.         ky=(int)strtol(buf,&dumptr,10);
  406.  
  407.         if (ky > max)
  408.             ky = 99;
  409.     
  410.         if((ky > 0) && (ky < 14))
  411.             switch (res) {
  412.                 case 1:
  413.                     res320();
  414.                     break;
  415.                 case 2:
  416.                     res640l();
  417.                     break;
  418.                 case 3:
  419.                     res640();
  420.                     break;
  421.                 case 4:
  422.                     res800();
  423.                     break;
  424.                 case 5:
  425.                     res1024();
  426.                     break;
  427.                 case 6:
  428.                     res1280();
  429.                     break;
  430.             }
  431.         
  432.         switch (ky) {
  433.             case 0:
  434.                 endit = 1;
  435.                 break;
  436.             case 1:
  437.                 doprims();
  438.                 break;
  439.             case 2:
  440.                 doclip();
  441.                 break;
  442.             case 3:
  443.                 dofill();
  444.                 break;
  445.             case 4:
  446.                 dopal();
  447.                 break;
  448.             case 5:
  449.                 doblock();
  450.                 break;
  451.             case 6:
  452.                 dotext();
  453.                 break;
  454.             case 7:
  455.                 doscroll();
  456.                 break;
  457.             case 8:
  458.                 dogif();
  459.                 break;
  460.             case 9:
  461.                 domouse();
  462.                 break;
  463.             case 10:
  464.                 dojoystick();
  465.                 break;
  466.             case 11:
  467.                 do2d();
  468.                 break;
  469.             case 12:
  470.                 do3d();
  471.                 break;
  472.             case 13:
  473.                 doall();
  474.                 break;
  475.             case 14:
  476.                 res = 1;
  477.                 break;
  478.             case 15:
  479.                 res = 2;
  480.                 break;
  481.             case 16:
  482.                 res = 3;
  483.                 break;
  484.             case 17:
  485.                 res = 4;
  486.                 break;
  487.             case 18:
  488.                 res = 5;
  489.                 break;
  490.             default:
  491.                 ;
  492.  
  493.         }
  494.         
  495.         restext();
  496.         
  497.     }
  498.  
  499.     videomodeset(startvideomode);
  500.  
  501. }
  502.  
  503. /**********               
  504.  * GETKEY *
  505.  **********/
  506.  
  507. char getkey(void)
  508. {
  509.     char ret;
  510.     beep();
  511.     ret = (char)getch();
  512.     if ( (ret == 'Q') || (ret == 'q') )
  513.         endit = 1;
  514.     if (ret == 'Q')
  515.         ret = 'q';
  516.     if (ret == 'S')
  517.         ret = 's';
  518.     
  519.     return(ret);
  520. }
  521.  
  522.  
  523. /*********
  524.  * DOALL *
  525.  *********/
  526.  
  527. void doall(void)
  528. {
  529.     if(doprims()=='q')
  530.         return;
  531.     if(doclip()=='q')
  532.         return;
  533.     if(dofill()=='q')
  534.         return;
  535.     if(dopal()=='q')
  536.         return;
  537.     if(doblock()=='q')
  538.         return;
  539.     if(dotext()=='q')
  540.         return;
  541.     if(doscroll()=='q')
  542.         return;
  543.     if(dogif()=='q')
  544.         return;
  545.     if(domouse()=='q')
  546.         return;
  547.     if(dojoystick()=='q')
  548.         return;
  549.     if(do2d()=='q')
  550.         return;
  551.     if(do3d()=='q')
  552.         return;
  553.  
  554.     return;
  555.  
  556. }
  557.  
  558.  
  559. /***************
  560.  * SCREENCLEAR *
  561.  ***************/
  562.  
  563. void screenclear(void)
  564. {
  565.     union REGS regs;
  566.  
  567.     regs.h.ah = 0x07;
  568.     regs.h.al = 0x00;
  569.     regs.h.ch = 0;
  570.     regs.h.cl = 0;
  571.     regs.h.dh = 24;
  572.     regs.h.dl = 79;
  573.     regs.h.bh = 7;
  574.     int86(0x10, ®s, ®s);
  575.     screengoto(1,1);
  576. }
  577.  
  578.  
  579. /**************
  580.  * SCREENGOTO *
  581.  **************/
  582.  
  583. void screengoto(int x, int y)
  584. {
  585.     union REGS regs;
  586.  
  587.     regs.h.ah = 0x02;
  588.     regs.h.bh = 0;
  589.     regs.h.dh = (unsigned char)y;
  590.     regs.h.dl = (unsigned char)x;
  591.     int86(0x10, ®s, ®s);
  592. }
  593.  
  594. /********
  595.  * BEEP *
  596.  ********/
  597.  
  598. void beep(void)
  599. {
  600.  
  601.     int cont;
  602.  
  603.     outp(0x43,0xB6);
  604.     outp(0x42,0xA9);
  605.     outp(0x42,0x06);
  606.     cont = inp(0x61);
  607.     outp(0x61,cont | 0x03);
  608.     sdelay(4);
  609.     outp(0x61,cont);
  610.  
  611. }
  612.