home *** CD-ROM | disk | FTP | other *** search
/ Zodiac Super OZ / MEDIADEPOT.ISO / FILES / 13 / VSA256.ZIP / VSA_DEMO.C < prev    next >
C/C++ Source or Header  |  1996-06-02  |  28KB  |  789 lines

  1. /*..........................................................................*/
  2. /*                               VSA_DEMO.C              5-29-96            */
  3. /*                                                                          */
  4. /*  This is the "C" source code for the VSA_DEMO.EXE program.  This program */
  5. /*  demonstrates the usage of the VSA256 Graphics Library, Version 4.0.     */
  6. /*  functions.                                                              */
  7. /*                                                                          */
  8. /*            Note: Set STACK SIZE to approx 10000 bytes.                   */
  9. /*            Note: For BORLAND compilers, use -Fs flag (SS = DS)!          */
  10. /*                                                                          */
  11. /*         Copyright Spyro Gumas, 1992 - 1996.  All Rights Reserved.        */
  12. /*..........................................................................*/
  13.  
  14. #include<dos.h>
  15. #include<stdio.h>
  16. #include<stdlib.h>
  17. #include<math.h>
  18. #include<limits.h>
  19. #include<bios.h>
  20. #include<conio.h>
  21. #include<time.h>
  22.  
  23. #include <vsa.h>            /* Required to support VSA256 Graphics Library  */
  24. #include <vsa_font.h>       /* Required to support VSA256 Graphics Library  */
  25. #include <tiff.h>           /* Required to support TIFF256 Graphics Library */
  26.  
  27. #ifndef _MSC_VER
  28. /*.....                  This is for Borland C Only !                  .....*/
  29. extern unsigned _stklen = 10000;
  30. #endif
  31.  
  32. void cube(int,int,int);
  33. void cubes(int,int,int);
  34. void rainbow_lut(void);
  35. void shaded_lut(void);
  36. void color_bar(int,int);
  37. void banner(int,int);
  38. void image(int,int);
  39. void obj_3d(int,int);
  40. void cube_3d(int,int);
  41. int  any_key(void);
  42. void delay(unsigned);
  43. void color_effect(void);
  44. void vsa_get_input(char *);
  45. void vsa_setup(void);
  46. void blueberry(void);
  47. void flipper(void);
  48. void pgram(int,int,int,int,int,int,int,int);
  49.  
  50. float SIN_LUT[1024];
  51.  
  52. void main()
  53. {
  54.     int i,k,l,ty,tx,c1,c2,vmode;
  55.     unsigned xx,yy,a,b,c,d,m,n,oldm,oldn,image_size;
  56.     char your_name[80];
  57.     unsigned char *pict1;
  58.     float x_scale,y_scale;
  59. /*..........................................................................*/
  60. /* If demo locks up during color cycling, or color mods crash for whatever  */
  61. /* reason, set the global parameter VSA_ATI_COLOR = 1.                      */
  62. /*..........................................................................*/
  63. //    VSA_ATI_COLOR = 1;
  64. /*..........................................................................*/
  65. /*                      Initialize sin look up table.                       */
  66. /*  Index 'i' goes from 0 to 1023 and is equivalent to 0 to 360 degrees.    */
  67. /*..........................................................................*/
  68.     for(i=0;i<1024;i++)
  69.         SIN_LUT[i] = sin(i*6.28/1024.0);
  70.  
  71.     vsa_setup();
  72.     vsa_get_svga_mode(&vmode);
  73.     rainbow_lut();
  74. /*..........................................................................*/
  75. /*                          Draw a BlueBerry Name.                          */
  76. /*..........................................................................*/
  77.     blueberry();
  78. /*..........................................................................*/
  79. /*             Do a quicky Page Flipping Demo in --- 640x480 mode.          */
  80. /*..........................................................................*/
  81.     flipper();
  82. /*..........................................................................*/
  83. /*        Now switch back to user specified vmode and do rest of demo.      */
  84. /*..........................................................................*/
  85.     vsa_init(vmode);
  86.     rainbow_lut();
  87.     xx = XResolution;
  88.     yy = YResolution;
  89.     x_scale = XResolution/640.0;
  90.     y_scale = YResolution/480.0;
  91.     vsa_set_text_scale(x_scale,y_scale);
  92.     vsa_set_color(0);
  93.     vsa_move_to(0,0);
  94.     vsa_rect_fill(xx-1,yy-1);
  95. /*..........................................................................*/
  96. /*                          Draw a frame                                    */
  97. /*..........................................................................*/
  98.     vsa_set_color(1);
  99.     vsa_move_to(0,0);
  100.     vsa_rect(xx-1,yy-1);
  101.     c1 = 30;
  102.     c2 = 20;
  103.     vsa_shaded_triangle(0,0,c1,10,10,c2,10,yy-11,c2);
  104.     vsa_shaded_triangle(0,0,c1,0,yy-1,c1,10,yy-11,c2);
  105.     vsa_shaded_triangle(0,0,c1,xx-1,0,c1,xx-11,10,c2);
  106.     vsa_shaded_triangle(0,0,c1,10,10,c2,xx-11,10,c2);
  107.     vsa_shaded_triangle(0,yy-1,c1,10,yy-11,c2,xx-11,yy-11,c2);
  108.     vsa_shaded_triangle(0,yy-1,c1,xx-1,yy-1,c1,xx-11,yy-11,c2);
  109.     vsa_shaded_triangle(xx-1,0,c1,xx-1,yy-1,c1,xx-11,10,c2);
  110.     vsa_shaded_triangle(xx-1,yy-1,c1,xx-11,yy-11,c2,xx-11,10,c2);
  111. /*..........................................................................*/
  112. /*             Draw color look up table at bottom of screen.                */
  113. /*..........................................................................*/
  114.     a = .125*xx;
  115.     b = .83*yy;
  116.     color_bar(a,b);
  117. /*..........................................................................*/
  118. /*            Draw "random" cubes enclosed by rectangle                     */
  119. /*..........................................................................*/
  120.     a = .6*xx;
  121.     b = .4*yy;
  122.     c = .88*xx;
  123.     d = .72*yy;
  124.     tx = (a+(c-a)/2) - 12*XCharSize;
  125.     ty = d + 0.01*yy;
  126.     vsa_write_string(tx,ty,250,"Lines using `vsa_line_to'");
  127.     vsa_write_string(tx,ty+YCharSize,64,"Clipping: `vsa_set_viewport'");
  128.     vsa_move_to(a,b);
  129.     vsa_set_color(180);
  130.     vsa_rect(c,d);
  131.     vsa_move_to(a+1,b+1);
  132.     vsa_set_color(20);
  133.     vsa_rect_fill(c-1,d-1);
  134.     vsa_set_viewport(a+1,b+1,c-1,d-1);
  135.     srand(1);
  136.     cubes(a,b,1);
  137. /*..........................................................................*/
  138. /*                          Draw a banner                                   */
  139. /*..........................................................................*/
  140.     vsa_set_viewport(0,0,xx,yy);
  141.     a = .55*xx;
  142.     b = .06*yy;
  143.     banner(a,b);
  144. /*..........................................................................*/
  145. /*                    Draw 2D sine-cosine image                             */
  146. /*..........................................................................*/
  147.     a = .08*xx;
  148.     b = .15*yy;
  149.     image(a,b);
  150. /*..........................................................................*/
  151. /*                    Draw a 3-D shaded object                              */
  152. /*..........................................................................*/
  153.     a = .08*xx;
  154.     b = .5*yy;
  155.     obj_3d(a,b);
  156. /*..........................................................................*/
  157. /*                    Draw a 3-D shaded Cube                                */
  158. /*..........................................................................*/
  159.     a = .5*xx;
  160.     b = .35*yy;
  161.     cube_3d(a,b);
  162. /*..........................................................................*/
  163. /*                        Using Text Cursor Mode 1.                         */
  164. /*..........................................................................*/
  165.     ty = .05*yy;
  166.     tx = .05*xx;
  167.     vsa_set_text_cursor_mode(1);
  168.     vsa_write_string(tx,ty,250,"Please Enter Your Name: ");
  169.     vsa_get_input(your_name);
  170.     vsa_set_text_cursor(tx,ty+YCharSize);
  171.     vsa_set_text_color(200);
  172.     vsa_write_string_alt("Hello ");
  173.     vsa_write_string_alt(your_name);
  174.     vsa_write_string_alt(", Hit any key to bail.");
  175. /*..........................................................................*/
  176. /* NOTE: TIFF256 requires Large MEM Model if you uncomment following lines! */
  177. /*..........................................................................*/
  178. /*.....
  179.     printf("Input Full file name for TIFF file to be saved: ");
  180.     scanf("%s",filename);
  181.     tf_save_file(0,YResolution-1,XResolution-1,0,filename);
  182. .....*/
  183. /*..........................................................................*/
  184. /*    Now do moving clipped cubes effect until someone presses a key.       */
  185. /*..........................................................................*/
  186.     k = 0;
  187.     l = 256;
  188.     a = .6*xx;
  189.     b = .4*yy;
  190.     c = .88*xx;
  191.     d = .72*yy;
  192.     oldm = a;
  193.     oldn = b;
  194.     vsa_set_viewport(a+1,b+1,c-1,d-1);
  195.     while(!any_key())
  196.         {
  197.             m = a + xx*0.1*SIN_LUT[k];
  198.             n = b + yy*0.1*SIN_LUT[l];
  199.             vsa_wait_vsync();
  200.             cubes(oldm,oldn,0);                          /* Clear last cube drawn */
  201.             cubes(m,n,1);                                /* Draw New cubes        */
  202.             k+=4;
  203.             l+=4;
  204.             k=k & 0x3ff;
  205.             l=l & 0x3ff;
  206.             oldm = m;
  207.             oldn = n;
  208.         }
  209.     ty = YResolution/2;
  210.     tx = XResolution/2;
  211. /*..........................................................................*/
  212. /*    Now do sliding blue color effect until someone presses a key.         */
  213. /*..........................................................................*/
  214.     color_effect();
  215. /*..........................................................................*/
  216. /*    Now BitBLT in SPRITE mode with vsa_get_image and vsa_put_image        */
  217. /*..........................................................................*/
  218.     vsa_set_viewport(0,0,xx-1,yy-1);
  219.     i = 0;
  220.     k = 0;
  221.     l = 256;
  222.     a = .495*xx;
  223.     b = .295*yy;
  224.     c = .09*xx;
  225.     d = .12*yy;
  226.     image_size = vsa_image_size(a,b,a+c,b+d);
  227.     if((pict1 = (unsigned char *)malloc(image_size)) == NULL)
  228.         {
  229.             vsa_write_string(0,0,31,"Error allocating memory for IMAGE");
  230.             getch();
  231.             goto BAIL;
  232.         }
  233.     vsa_get_image(a,b,a+c,b+d,pict1);
  234.     vsa_set_color(255);
  235.     vsa_move_to(a,b);
  236.     vsa_rect(a+c,b+d);
  237.     while(!any_key())
  238.         {
  239.             m = xx/2 - c/2 + (i)*0.3*SIN_LUT[k];
  240.             n = yy/2 - d/2 + (i)*0.3*SIN_LUT[l];
  241.             vsa_put_image(m,n,pict1,6);
  242.             k-=4;
  243.             l-=4;
  244.             k=k & 0x3ff;
  245.             l=l & 0x3ff;
  246.             i++;
  247.         }
  248.     free(pict1);
  249.     vsa_set_color(20);
  250.     vsa_move_to(tx-15*XCharSize,ty-2*YCharSize);
  251.     vsa_rect_fill(tx+15*XCharSize,ty+3*YCharSize);
  252.     vsa_set_color(31);
  253.     vsa_move_to(tx-15*XCharSize,ty-2*YCharSize);
  254.     vsa_rect(tx+15*XCharSize,ty+3*YCharSize);
  255.     vsa_write_string(tx-14*XCharSize,ty-YCharSize,200,"BitBlt Using: vsa_image_size");
  256.     vsa_write_string(tx-14*XCharSize,ty          ,200," (Sprites!)   vsa_get_image ");
  257.     vsa_write_string(tx-14*XCharSize,ty+YCharSize,200,"              vsa_put_image ");
  258. /*..........................................................................*/
  259. /*  Now do sliding blue color effect (again) until someone presses a key.   */
  260. /*..........................................................................*/
  261.     color_effect();
  262. /*..........................................................................*/
  263. /*           Restore text video mode and print information.                 */
  264. /*..........................................................................*/
  265. BAIL:
  266.     vsa_set_viewport(0,0,xx-1,yy-1);
  267.     vsa_about();
  268.     getch();
  269.     vsa_init(0x3);
  270.     return;
  271. }
  272.  
  273. void cube(int x,int y,int size)
  274. {
  275.     int sizeb;
  276.     sizeb = size/2;
  277.     vsa_move_to(x,y);
  278.     vsa_rect(x+size,y+size);
  279.     vsa_move_to(x+sizeb,y+sizeb);
  280.     vsa_rect(x+sizeb+size,y+sizeb+size);
  281.     vsa_move_to(x,y);
  282.     vsa_line_to(x+sizeb,y+sizeb);
  283.     vsa_move_to(x+size,y);
  284.     vsa_line_to(x+sizeb+size,y+sizeb);
  285.     vsa_move_to(x+size,y+size);
  286.     vsa_line_to(x+sizeb+size,y+sizeb+size);
  287.     vsa_move_to(x,y+size);
  288.     vsa_line_to(x+sizeb,y+sizeb+size);
  289.     return;
  290. }
  291.  
  292. void cubes(int m,int n,int draw)
  293. {
  294.     int i,x,y,size;
  295.     float xfact,yfact,sfact;
  296.     srand(1);
  297.     vsa_set_color(20);
  298.     xfact = .23*XResolution/(float)RAND_MAX;
  299.     yfact = .23*YResolution/(float)RAND_MAX;
  300.     sfact = .05*xfact/.23;
  301.     for(i=0;i<16;i++)
  302.         {
  303.             x = m+5+xfact*rand();
  304.             y = n+5+yfact*rand();
  305.             size = sfact*rand();
  306.             if(draw)
  307.                 vsa_set_color(i);
  308.             cube(x,y,size);
  309.         }
  310.     return;
  311. }
  312.  
  313. void rainbow_lut()
  314. {
  315.     int i,start,count;
  316.     unsigned char color_array[768];
  317.     for(i=0;i<224;i++)
  318.         {
  319.             color_array[3*i+2]=0;
  320.             color_array[3*i+1]=0;
  321.             color_array[3*i]=0;
  322.         }
  323. /*................................ RED .....................................*/
  324.     for(i=0;i<56;i++)
  325.         {
  326.                 color_array[3*i] = 63*sin((i*6.28)/112.0);
  327.         }
  328. /*............................... BLUE .....................................*/
  329.     for(i=20;i<146;i++)
  330.         {
  331.                 color_array[3*i+2] = 63*sin(((i-20)*6.28)/252.0);
  332.         }
  333. /*............................... GREEN ....................................*/
  334.     for(i=90;i<216;i++)
  335.         {
  336.                 color_array[3*i+1] = 63*sin(((i-90)*6.28)/252.0);
  337.         }
  338. /*................................ RED .....................................*/
  339.     for(i=140;i<224;i++)
  340.         {
  341.                 color_array[3*i]   = 63*sin(((i-140)*6.28)/280.0);
  342.         }
  343.     start = 32;
  344.     count = 224;
  345.     vsa_write_color_block(start,count,color_array);
  346.     return;
  347. }
  348.  
  349.  
  350. /*.............................. SHADED_LUT.C ............. 2-25-96 ........*/
  351. /*  This routine generates a lookup table holding 8 primary colors with 32  */
  352. /*  shades of "gray" for each.                                              */
  353. /*                                                                          */
  354. /*           COLOR   |   INDEX RANGE                                        */
  355. /*           -----------------------                                        */
  356. /*            Gray   |     0-31                                             */
  357. /*            Red    |    32-63                                             */
  358. /*            Orange |    64-95                                             */
  359. /*            Yellow |    96-127                                            */
  360. /*            Green  |   128-159                                            */
  361. /*            Auqa   |   160-191                                            */
  362. /*            Blue   |   192-223                                            */
  363. /*            Purple |   224-255                                            */
  364. /*..........................................................................*/
  365. void shaded_lut(void)
  366. {
  367.     int i,j;
  368.     unsigned char color_array[768];
  369.     float r[8]={1.0,1.0,0.917,1.0,0.0,0.0,0.0,1.0};
  370.     float g[8]={1.0,0.0,0.436,1.0,1.0,1.0,0.0,0.0};
  371.     float b[8]={1.0,0.0,0.000,0.0,0.0,1.0,1.0,1.0};
  372.     float k;
  373.     for(j=0;j<8;j++)
  374.         {
  375.             for(i=0;i<32;i++)
  376.                 {
  377.                     if(i < 12) k = pow((i/31.0),1.0);
  378.                     else       k = pow((11/31.0),1.0) + 0.645*pow(((i-9.0)/(31.0-9.0)),3.0);
  379.                     color_array[3*i+96*j+0]= (int)(k*63*r[j] + 0.5);
  380.                     color_array[3*i+96*j+1]= (int)(k*63*g[j] + 0.5);
  381.                     color_array[3*i+96*j+2]= (int)(k*63*b[j] + 0.5);
  382.                     i=i;
  383.                 }
  384.         }
  385.     vsa_write_color_block(0,256,color_array);
  386.     return;
  387. }                                   /*.....       End shaded_lut       .....*/
  388.  
  389. void color_bar(x0,y0)
  390. int x0,y0;
  391. {
  392.     int i,ty,tx;
  393.     unsigned xx,yy,a,b;
  394.     float c;
  395.     xx = XResolution;
  396.     yy = YResolution;
  397. /*..........................................................................*/
  398. /*     Draw outline for color bar.                                          */
  399. /*..........................................................................*/
  400.     vsa_set_color(15);
  401.     vsa_move_to(x0-1,y0-1);
  402.     a = .75*xx;
  403.     b = .065*yy;
  404.     vsa_rect(x0+a+1,y0+b+1);
  405.     c = (float)a/256;
  406.     for(i=0;i<256;i++)
  407.         {
  408.             vsa_set_color((unsigned char)i);
  409.             vsa_move_to(x0+(unsigned)(i*c),y0);
  410.             vsa_rect_fill(x0+(unsigned)(c+i*c),y0+b);
  411.         }
  412.     ty = (y0+b+1) + 0.01*YResolution;
  413.     tx = (x0+a/2) - 31*XCharSize;
  414.     vsa_write_string(tx,ty,63,"Color Look Up Table Manipulation using");
  415.     vsa_write_string(tx+38*XCharSize,ty,63," `vsa_write_color_block'");
  416.     vsa_write_string(tx,ty+YCharSize,63,"'vsa_read_color_register' and");
  417.     vsa_write_string(tx+31*XCharSize,ty+YCharSize,63,"`vsa_write_color_register'.");
  418.     return;
  419. }
  420.  
  421. void banner(int x,int y)
  422. {
  423.     int ty,tx,c1,c2;
  424.     unsigned xx,yy,a,b;
  425.     xx = XResolution;
  426.     yy = YResolution;
  427.     a = .40*xx;
  428.     b = .17*yy;
  429.     c1 = 100;
  430.     c2 = 65;
  431.     vsa_move_to(x-2,y-2);
  432.     vsa_set_color(220);
  433.     vsa_rect_fill(x+a+2,y+b+2);
  434.     vsa_shaded_triangle(x,y,c1,x+a,y,c1,x+a,y+b,c2);
  435.     vsa_shaded_triangle(x,y,c1,x,y+b,c2,x+a,y+b,c2);
  436.     tx = (x+5) + 0.08*a;
  437.     ty = (y+6) + 0.15*b;
  438.     vsa_write_string(tx,ty,200,"VSA256 GRAPHICS LIBRARY");
  439.     vsa_write_string(tx,ty+YCharSize,200,"for C Programmers");
  440.     vsa_write_string(tx+18*XCharSize,ty+YCharSize,255,"V4.0");
  441.     vsa_write_string(tx,ty+2*YCharSize,200,"Copyright Spyro Gumas 92-96");
  442.     ty = (y+b) + 0.01*YResolution;
  443.     tx = (x+(a+5)/2) - 16*XCharSize;
  444.     vsa_write_string(tx,ty,2            ,"Text using 'vsa_set_text_scale'  ");
  445.     vsa_write_string(tx,ty+YCharSize,2  ,"           'vsa_write_string'    ");
  446.     vsa_write_string(tx,ty+2*YCharSize,2,"           'vsa_write_string_alt'");
  447.     return;
  448. }
  449.  
  450. void image(int x,int y)
  451. {
  452.     int i,j,ty,tx;
  453.     long ii,jj,z1,z2;
  454.     unsigned char array[1024];
  455.     unsigned xx,yy,a,b;
  456.     xx = XResolution;
  457.     yy = YResolution;
  458.     a = .4*xx;
  459.     b = .26*yy;
  460.     z1 = 2*1024L/a;
  461.     z2 = 1024L/b;
  462.     vsa_move_to(x-2,y-2);
  463.     vsa_set_color(250);
  464.     vsa_rect(x+a+1,y+b+1);
  465.     for(j=0;j<b;j++)
  466.         {
  467.             for(i=0;i<a;i++)
  468.                 {
  469.                     ii = (i*z1) & 0x000003ff;
  470.                     jj = (j*z2+256) & 0x000003ff;
  471.                     array[i] = 144+112.0*(SIN_LUT[ii]*SIN_LUT[jj]);
  472.                 }
  473.             vsa_raster_line(x,x+a-1,y+j,array);
  474.         }
  475.     ty = (y+b+1) + 0.01*YResolution;
  476.     tx = (x+a/2) - 17*XCharSize;
  477.     vsa_write_string(tx,ty,100,"2D Images Using `vsa_raster_line'");
  478.     return;
  479. }
  480.  
  481. void obj_3d(int x,int y)
  482. {
  483.     int rim1,rim2,tip1,tip2,ty,tx;
  484.     unsigned xx,yy,a,b;
  485.     xx = XResolution;
  486.     yy = YResolution;
  487.     a = .4*xx;
  488.     b = .2*yy;
  489.     vsa_move_to(x-2,y-2);
  490.     vsa_set_color(255);
  491.     vsa_rect(x+a+1,y+b+1);
  492.     vsa_move_to(x,y);
  493.     vsa_set_color(38);
  494.     vsa_rect_fill(x+a,y+b);
  495.     rim1 = 145;
  496.     tip1 = 255;
  497.     tip2 = 32;
  498.     rim2 = 155;
  499. vsa_shaded_triangle((int)(.35*a+x),(int)(.8*b+y),rim1,(int)(.25*a+x),(int)(.8*b+y),rim1,(int)(.9*a+x),(int)(.1*b+y),tip1);
  500. vsa_shaded_triangle((int)(.25*a+x),(int)(.8*b+y),rim1,(int)(.15*a+x),(int)(.6*b+y),rim1,(int)(.9*a+x),(int)(.1*b+y),tip1);
  501. vsa_shaded_triangle((int)(.15*a+x),(int)(.6*b+y),rim1,(int)(.15*a+x),(int)(.4*b+y),rim1,(int)(.9*a+x),(int)(.1*b+y),tip1);
  502. vsa_shaded_triangle((int)(.15*a+x),(int)(.4*b+y),rim1,(int)(.25*a+x),(int)(.2*b+y),rim1,(int)(.9*a+x),(int)(.1*b+y),tip1);
  503. vsa_shaded_triangle((int)(.25*a+x),(int)(.2*b+y),rim1,(int)(.35*a+x),(int)(.2*b+y),rim1,(int)(.9*a+x),(int)(.1*b+y),tip1);
  504. vsa_set_color(32);
  505. vsa_move_to((int)(.3*a+x),(int)(.5*b+y));
  506. vsa_line_to((int)(.9*a+x),(int)(.1*b+y));
  507. vsa_shaded_triangle((int)(.35*a+x),(int)(.2*b+y),rim1,(int)(.45*a+x),(int)(.4*b+y),rim1,(int)(.9*a+x),(int)(.1*b+y),tip1);
  508. vsa_shaded_triangle((int)(.45*a+x),(int)(.4*b+y),rim1,(int)(.45*a+x),(int)(.6*b+y),rim1,(int)(.9*a+x),(int)(.1*b+y),tip1);
  509. vsa_shaded_triangle((int)(.45*a+x),(int)(.6*b+y),rim1,(int)(.35*a+x),(int)(.8*b+y),rim1,(int)(.9*a+x),(int)(.1*b+y),tip1);
  510.  
  511. vsa_shaded_triangle((int)(.80*a+x),(int)(.75*b+y),rim2,(int)(.75*a+x),(int)(.9*b+y),rim2,(int)(.9*a+x),(int)(.1*b+y),tip2);
  512. vsa_shaded_triangle((int)(.75*a+x),(int)(.9*b+y),rim2,(int)(.65*a+x),(int)(.9*b+y),rim2,(int)(.9*a+x),(int)(.1*b+y),tip2);
  513. vsa_shaded_triangle((int)(.65*a+x),(int)(.9*b+y),rim2,(int)(.60*a+x),(int)(.75*b+y),rim2,(int)(.9*a+x),(int)(.1*b+y),tip2);
  514. vsa_shaded_triangle((int)(.60*a+x),(int)(.75*b+y),rim2,(int)(.60*a+x),(int)(.65*b+y),rim2,(int)(.9*a+x),(int)(.1*b+y),tip2);
  515. vsa_shaded_triangle((int)(.60*a+x),(int)(.65*b+y),rim2,(int)(.65*a+x),(int)(.5*b+y),rim2,(int)(.9*a+x),(int)(.1*b+y),tip2);
  516. vsa_set_color(32);
  517. vsa_move_to((int)(.7*a+x),(int)(.7*b+y));
  518. vsa_line_to((int)(.9*a+x),(int)(.1*b+y));
  519. vsa_shaded_triangle((int)(.65*a+x),(int)(.5*b+y),rim2,(int)(.75*a+x),(int)(.5*b+y),rim2,(int)(.9*a+x),(int)(.1*b+y),tip2);
  520. vsa_shaded_triangle((int)(.75*a+x),(int)(.5*b+y),rim2,(int)(.80*a+x),(int)(.65*b+y),rim2,(int)(.9*a+x),(int)(.1*b+y),tip2);
  521. vsa_shaded_triangle((int)(.80*a+x),(int)(.65*b+y),rim2,(int)(.80*a+x),(int)(.75*b+y),rim2,(int)(.9*a+x),(int)(.1*b+y),tip2);
  522.  
  523.     ty = (y+b+1) + 0.01*YResolution;
  524.     tx = (x+a/2) - 19*XCharSize;
  525.     vsa_write_string(tx,ty,14,"3D Objects Using `vsa_shaded_triangle'");
  526.     return;
  527. }
  528.  
  529. void cube_3d(int a,int b)
  530. {
  531.     int dy,dx,dd;
  532.     dx = .045*XResolution;
  533.     dy = .06*YResolution;
  534.     dd = .5*dx;
  535.     vsa_shaded_triangle(a,b,75,a+dx,b,91,a+dx,b+dy,75);
  536.     vsa_shaded_triangle(a,b,75,a,b+dy,49,a+dx,b+dy,75);
  537.     a+= 0.05*dx;
  538.     b-= 0.2*dy;
  539.     vsa_shaded_triangle(a,b,75,a+dx,b,91,a+3*dd,b-dd,75);
  540.     vsa_shaded_triangle(a,b,75,a+dd,b-dd,49,a+3*dd,b-dd,75);
  541.     a+= 0.15*dx;
  542.     b+= 0.15*dy;
  543.     vsa_shaded_triangle(a+dx,b+dy,75,a+dx,b,91,a+3*dd,b-dd,75);
  544.     vsa_shaded_triangle(a+dx,b+dy,75,a+3*dd,b+dy-dd,49,a+3*dd,b-dd,75);
  545.     vsa_write_string((int)(a-0.3*dx),(int)(b+1.2*dy),240,"Sprites");
  546.     return;
  547. }
  548.  
  549. void color_effect(void)
  550. {
  551.     int i;
  552.     unsigned char save_color_array[768],j,jj;
  553.     unsigned char red[256],green[256],blue[256];
  554.     vsa_read_color_block(251,5,save_color_array);
  555.     for(j=0;j<5;j++)
  556.         {
  557.             red[j+251]   = save_color_array[3*j];
  558.             green[j+251] = save_color_array[3*j+1];
  559.             blue[j+251]  = save_color_array[3*j+2];
  560.         }
  561.     while(1)
  562.         for(i=32;i<256;i++)
  563.             {
  564.                 vsa_wait_vsync();
  565.                 j = (unsigned char) i;
  566.                 vsa_read_color_register(j,&red[j],&green[j],&blue[j]);
  567.                 vsa_write_color_register(j,0,0,63);
  568.                 if(j <= 36)
  569.                     jj = (unsigned char)(j-37);
  570.                 else
  571.                     jj = (unsigned char)(j-5);
  572.                 vsa_write_color_register(jj,red[jj],green[jj],blue[jj]);
  573.                 if(any_key())
  574.                     return;
  575.             }
  576. }
  577.  
  578. int any_key(void)
  579. {
  580.     int result=0;
  581. #ifdef _MSC_VER
  582. /*.....             For Microsoft C, Use this line.                    .....*/
  583.     if(_bios_keybrd(_KEYBRD_READY))
  584.         result = _bios_keybrd(_KEYBRD_READ);
  585. #else
  586. /*.....             For Borland C, Use this line instead.              .....*/
  587.     if(bioskey(1))
  588.         result = bioskey(0);
  589. #endif
  590.     return result;
  591. }
  592.  
  593. /*.......................... VSA_GET_INPUT .................... 6-25-94 ....*/
  594. /*  This routine reads the keyboard input and echos it to the screen until  */
  595. /* a carriage return is entered. Then the whole text string is returned     */
  596. /* via 'text'.                                                              */
  597. /*..........................................................................*/
  598. void vsa_get_input(char *text)
  599. {
  600.     int i,x,y;
  601.     char key;
  602.     vsa_get_text_cursor(&x,&y);
  603.     i=0;
  604.     text[0] = 0;
  605.     while((key = getch()) != 13)               /*  Do until a return is hit.  */
  606.         {
  607.             if(key != 8)
  608.                 {                                    /*  If not a back space        */
  609.                     text[i] = key;                     /*  add key entry to string.   */
  610.                     text[i+1] = 0;
  611.                     vsa_write_string(x,y,255,text);    /*  Echo the updated string.   */
  612.                     i++;
  613.                 }
  614.             else
  615.                 {                                    /*  If a back space            */
  616.                     if(i > 0) i --;                    /*  delete last key entry.     */
  617.                     text[i] = 92;
  618.                     vsa_write_string(x,y,255,text);    /*  Echo the updated string.   */
  619.                     text[i] = 0;
  620.                 }
  621.         }
  622.     return;
  623. }
  624.  
  625. /*.............................. VSA_SETUP .................... 6-6-95 .....*/
  626. /*  This routine goes through the video mode set up stuff.                  */
  627. /*..........................................................................*/
  628. void vsa_setup(void)
  629. {
  630.     int i,vmode;
  631. /*..........................................................................*/
  632. /*               Initialize video mode and VSA256 environment.              */
  633. /*               Valid modes are: 100h, 101h, 103h, and 105h.               */
  634. /*..........................................................................*/
  635.     printf("\n");
  636.     printf("\n");
  637.     printf("VESA standard Video Modes  =>   Mode | Resolution\n");
  638.     printf("              (256 color)       -----|-----------\n");
  639.     printf("                                100  |  640 x 400\n");
  640.     printf("                                101  |  640 x 480\n");
  641.     printf("                                103  |  800 x 600\n");
  642.     printf("                                105  | 1024 x 768\n");
  643.     printf("                                107  | 1280 x 1024\n");
  644.     printf("Input Mode: ");
  645.     scanf("%x",&vmode);
  646.     if((i = vsa_init(vmode)) != 0)
  647.         {
  648.             printf("Error Initializing Requested Video Mode!\n");
  649.             if(i==1) printf("  - Did You Load Correct VESA Driver (TSR) ??\n");
  650.             if(i==2) printf("  - VESA BIOS Extensions (Driver) Not Loaded !!\n");
  651.             if(i==3) printf("  - Requested Video Mode Not Supported by this Card!\n");
  652.             if(i==4) printf("  - Mode Not an SVGA Mode Supported by this Card!\n");
  653.             if(i==5) printf("  - VESA Driver Not Returning Mode Information!\n");
  654.             exit(0);
  655.         }
  656.     return;
  657. }
  658.  
  659. void blueberry(void)
  660. {
  661.     float a,b,sx,sy;
  662.     int i,x,y,xoff,yoff,color;
  663.     x = .03*XResolution;
  664.     y = .03*YResolution;
  665.     sx = 13.0*XResolution/1024.0;
  666.     sy = 20.0*YResolution/768.0;
  667.     vsa_get_text_scale(&a,&b);
  668.     vsa_set_text_scale(sx,sy);
  669.     for(i=0;i<30;i++)
  670.         {
  671.             color = 80+50*sin((3.14*i)/30.0)*sin((3.14*i)/30.0);
  672.             vsa_write_string(x+i,y,color,"Blueberry");
  673.             vsa_write_string(x+i,y+YResolution/2,color,"Graphics");
  674.         }
  675.     xoff = x + 8*XCharSize;
  676.     yoff = y + YResolution/2+YCharSize/4;
  677.     vsa_set_text_scale(a,b);
  678.     vsa_write_string(xoff+XCharSize,yoff,100,"TM");
  679.     getch();
  680.     vsa_set_color(0);
  681.     vsa_move_to(0,0);
  682.     vsa_rect_fill(XResolution-1,YResolution-1);
  683.     return ;
  684. }
  685.  
  686. void flipper()
  687. {
  688.     int p[16],y,page,flip;
  689.     float i;
  690.     vsa_init(0x101);
  691.     shaded_lut();
  692.     page = 0;
  693.     y = 0;
  694.     flip = 0;
  695.     i = 0.0;
  696.  
  697.     vsa_set_draw_page(1);
  698.     vsa_set_color(0);
  699.     vsa_move_to(0,0);
  700.     vsa_rect_fill(XResolution-1,YResolution-1);
  701.     vsa_set_draw_page(0);
  702.     vsa_set_color(0);
  703.     vsa_move_to(0,0);
  704.     vsa_rect_fill(XResolution-1,YResolution-1);
  705.  
  706.     while(1)
  707.         {
  708.             if(any_key())      /*...  Hit any key to switch to page flipping mode */
  709.                 if(flip == 1)    /*...  Hit any key (again) to quit demo.           */
  710.                     break;
  711.                 else
  712.                     flip = 1;
  713.  
  714.             if(flip)           /*...  Do page flipping when enabled.              */
  715.                 vsa_set_draw_page(page);
  716.             vsa_set_color(0);
  717.             vsa_move_to(290,0);
  718.             vsa_rect_fill(450,479);
  719.             vsa_move_to(0,0);
  720.             vsa_rect_fill(500,10+2*YCharSize);
  721.  
  722.             if(flip)           /*...  Self explanatory messages.                  */
  723.                 {
  724.                     vsa_write_string(10,10,127,"Ahhhhh, Much Better (Page Flipping that is).");
  725.                     vsa_write_string(10,10+YCharSize,127,"Hit any key to quit");
  726.                     vsa_write_string(10,400,159,"Using the new `vsa_set_draw_page' and .");
  727.                     vsa_write_string(10,400+YCharSize,159,"              `vsa_set_view_page' functions.");
  728.                 }
  729.             else
  730.                 {
  731.                     vsa_write_string(10,10,63,"Page Flipping is OFF (Yuk!).");
  732.                     vsa_write_string(10,10+YCharSize,63,"Hit any key to switch");
  733.                 }
  734.  
  735.             p[0] = 350;
  736.             p[1] = 100 + y;
  737.             p[2] = 450;
  738.             p[4] = 390;
  739.             p[5] = 140 + y;
  740.             p[6] = 290;
  741.             p[9] = 225;
  742.             p[11] = 185;
  743.             p[13] = 325 + y;
  744.             p[15] = 285 + y;
  745.  
  746.             vsa_set_color(222);          /*... Draw blue vector stuff.            */
  747.             vsa_move_to(p[6],p[9]);
  748.             vsa_line_to(p[6],p[13]);
  749.             vsa_line_to(p[4],p[13]);
  750.             vsa_line_to(p[2],p[15]);
  751.             vsa_line_to(p[0],p[15]);
  752.             vsa_line_to(p[0],p[1]);
  753.             vsa_move_to(p[0],p[15]);
  754.             vsa_line_to(p[6],p[13]);
  755.             vsa_move_to(p[4],p[9]);
  756.             vsa_line_to(p[4],p[13]);
  757.             vsa_move_to(p[2],p[11]);
  758.             vsa_line_to(p[2],p[15]);
  759.  
  760.             vsa_set_color(7);            /*... Draw gray intersecting plane.      */
  761.             pgram(200,175,600,175,450,275,50,275);
  762.  
  763.             vsa_set_color(255);          /*... Draw Solid Box sections.           */
  764.             pgram(p[0],p[1],p[2],p[1],p[4],p[5],p[6],p[5]);
  765.             vsa_set_color(244);
  766.             vsa_move_to(p[6],p[5]);
  767.             vsa_rect_fill(p[4],p[9]);
  768.             vsa_set_color(240);
  769.             pgram(p[4],p[9],p[4],p[5],p[2],p[1],p[2],p[11]);
  770.  
  771.             y = (int)(40.0*sin(6.28*i/100.0) + 0.5);   /* slide boxes up and down */
  772.             i += 1.0;
  773.  
  774.             if(flip)                      /*...  Do page flipping when enabled.   */
  775.                 vsa_set_view_page(page);
  776.                 page = 1-page;              /*...  page = 0 or 1.                   */
  777.  
  778.         }
  779.     vsa_init(0x3);
  780.     return;
  781. }
  782.  
  783. void pgram(int x0,int y0,int x1,int y1,int x2,int y2,int x3,int y3)
  784. {
  785.     vsa_triangle_fill(x0,y0,x1,y1,x2,y2);
  786.     vsa_triangle_fill(x0,y0,x3,y3,x2,y2);
  787.     return;
  788. }
  789.