home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / d / dots151.zip / GRAPHSRC.ZIP / BENCH.C next >
C/C++ Source or Header  |  1990-03-16  |  31KB  |  1,090 lines

  1. /*
  2.     bench - integer mode graphics demonstration and benchmark      
  3.  
  4.     bugs...
  5.  
  6. screen measurements: 191 mm wide by 158 mm high on Z-150
  7.                      8.25 in wide by 5.375 in high on IBM
  8. */
  9. #pragma ex+
  10.  
  11. #include <stdio.h>
  12. #include "g.h"
  13.  
  14.  
  15. char buf[80];
  16. int no_characters=0;    /* nonzero if calls to character functions are
  17.                             to be avoided (presumably because they aren't
  18.                             yet implemented)              */
  19.  
  20. long int t1, t2, t3, min_rate, max_rate, overhead;
  21. long tics();
  22. int i, j, k;
  23. int q, x0, y0, x1, y1, x2, y2, delx, dely, del1, del2;
  24. int w0, w1, w2, z2;
  25. int starting_screen = 0;
  26. double intensity;
  27. double d1, d2, d3, minimum_rate, maximum_rate;
  28. char *preamble[]=
  29. {"We, the people of the United States, in order to form a more perfect\n",
  30. "Union, establish justice, insure domestic tranquillity, provide for the\n",
  31. "common defense, promote the general welfare, and secure the blessings\n",
  32. "of liberty to ourselves and our posterity, do ordain and establish this\n",
  33. "Constitution for the United States of America.\n\n\n",
  34. 0};
  35.  
  36. main(argc, argv) int argc; char **argv;
  37. {    double f;
  38.     initialize_parameters(argc, argv);
  39.     init_graphics();
  40.     if(starting_screen)
  41.         {switch(starting_screen)
  42.             {
  43.             case 1: goto SCR_1;
  44.             case 2: goto SCR_2;
  45.             case 3: 
  46.             case 4: 
  47.             case 5: 
  48.             case 6: 
  49.             case 7: goto SCR_3;
  50.             case 8: goto SCR_8;
  51.             case 9: goto SCR_9;
  52.             case 10: goto SCR_10;
  53.             case 11: goto SCR_11;
  54.             case 12: goto SCR_12;
  55.             case 13: goto SCR_13;
  56.             case 14: goto SCR_14;
  57.             case 15: goto SCR_15;
  58.             case 16: goto SCR_16;
  59.             case 17: goto SCR_17;
  60.             case 18: goto SCR_18;
  61.             case 19: goto SCR_19;
  62.             case 20: goto SCR_20;
  63.             }
  64.         }
  65.                         /*
  66.                                 initial information screen
  67.                         */
  68. SCR_1:
  69.     if(!no_characters)
  70.         {gotoxy(0, char_height);
  71.         sprintf(buf, "1: Interface version %s \nfor the %s\n\n",
  72.             interface_version, machine);
  73.         (*draw_text)(buf);
  74.         sprintf(buf, "screen width %d pixels\nheight %d pixels\n",
  75.             pixels_wide, pixels_high);
  76.         (*draw_text)(buf);
  77.         sprintf(buf, "screen width %d characters\nheight %d rows\n",
  78.             char_columns, char_rows);
  79.         (*draw_text)(buf);
  80.         sprintf(buf, "%d colors\n", max_color+1);
  81.         (*draw_text)(buf);
  82.         (*draw_text)("\nThis text is in the default colors,\n");
  83.         (*draw_text)("which should be white on black.\n");
  84. #ifdef JKHJJ
  85.         print_prim_attr(&prim_attr);
  86. #endif
  87.         wait(); clear_graphics();
  88.         }
  89.                         /*
  90.                                 display text at various intensities
  91.                         */
  92. SCR_2:
  93.     if(!no_characters)
  94.         {set_intensity(1.);                        /* white characters */
  95.         set_background_intensity(0.);            /* black background */
  96.         gotoxy(0, char_height);
  97.         (*draw_text)("2: text intensities\n\n            requested  reported ");
  98.         y1=3*char_height;
  99.         for (intensity=0.; intensity<=1.; intensity+=1./13.)
  100.             {set_intensity(intensity);
  101.             gotoxy(0, y1+=char_height); (*draw_text)("fg intensity  ");
  102.             sprintf(buf, "%5.3f     %5.3f", intensity, inquire_intensity());
  103.             set_intensity(1.);
  104.             set_background_intensity(0.);
  105.             (*draw_text)(buf);
  106.             }
  107.         x1 = .5*pixels_wide; y1 = 3*char_height;
  108.         for (f = 0.; f < 1.; f += .0625)
  109.             {i = f*(max_color+1);
  110.             set_color(i);
  111.             gotoxy(x1, y1+=char_height);
  112.             sprintf(buf, "color %2d  ", i);
  113.             (*draw_text)(buf);
  114.             set_intensity(1.);
  115.             if(i == 0) (*draw_text)("white");
  116.             if(i == max_color) (*draw_text)("black");
  117.             }
  118.  
  119.         wait(); clear_graphics();
  120.         }
  121.  
  122.                         /*
  123.                                 draw barber-pole patterns in top 
  124.                                 right & bottom left corners
  125.                         */
  126. SCR_3:
  127.     set_intensity(.4);
  128.     box(0, 0, pixels_wide-1, pixels_high-1);
  129.     set_intensity(1.);
  130.     set_background_intensity(0.);
  131.     if(no_characters)
  132.         {puts("\n character routine demo omitted ");
  133.         for(i=1; i<1000; i++) for(j=1; j<100; j++) ;
  134.         set_intensity(1.);
  135.         }
  136.     else
  137.         char_placement();
  138.     wait(); clear_graphics();
  139.  
  140.                         /*
  141.                             diamonds
  142.                         */
  143. SCR_8:
  144.     set_intensity(1.);
  145.     set_background_intensity(0.);
  146.     if(!no_characters)
  147.         {gotoxy(1, pixels_high-2*char_height);
  148.         (*draw_text)("8: lines end ");
  149.         gotoxy(1, pixels_high-1*char_height);
  150.         (*draw_text)("accurately?");
  151.         }
  152.     set_intensity(.7);
  153.     dely=pixels_high/45;
  154.     w0=(pixels_wide-1)/4;
  155.     y1=((pixels_high/2.)/dely)*dely;
  156.     y2=0;
  157.     while(y2<pixels_high)    {(*draw_line)(0, y1, w0-1, y2); y2+=dely;}
  158.     while(y2>0)                {y2-=dely; (*draw_line)(2*w0, y1, w0+1, y2);}
  159.     delx=pixels_wide/70;
  160.     x2=pixels_wide/2; x1=((pixels_wide/4.)/delx)*delx+x2; y2=pixels_high-1;
  161.     while(x2<pixels_wide)    {(*draw_line)(x1, 0, x2, y1); x2+=delx;}
  162.     while(x2>pixels_wide/2)    {x2-=delx; (*draw_line)(x1, y2, x2, y1+2);}
  163.     wait(); clear_graphics();
  164.  
  165.                         /*
  166.                             displaying the available colors
  167.                         */
  168. SCR_9:
  169.     if(max_color>1)
  170.         {show_colors();
  171.         wait(); clear_graphics();
  172.         }
  173.  
  174.     if(erasing)
  175.         {
  176.  
  177.                         /*
  178.                             drawing & erasing rectangles
  179.                         */
  180. SCR_10:
  181.         rectangles();
  182.         wait(); clear_graphics();
  183.  
  184.                         /*
  185.                             creating & erasing rectangles of different
  186.                             intensities
  187.                         */
  188. SCR_11:
  189.         set_intensity(1.);
  190.         set_background_intensity(0.);
  191.         if(!no_characters)
  192.             {gotoxy(0, pixels_high-1*char_height);
  193.             (*draw_text)("11: drawing and erasing algorithms match?");
  194.             }
  195.         x1=0; x2=.6*pixels_wide;
  196.         for (intensity=.938; intensity>0.; intensity-=.125)
  197.             {if(!no_characters)
  198.                 {gotoxy(0, (int)(.7*pixels_high+2.*char_height));
  199.                 set_intensity(1.);
  200.                 set_background_intensity(0.);
  201.                 sprintf(buf, "intensity %5.3f", intensity);
  202.                 (*draw_text)(buf);
  203.                 }
  204.             set_intensity(intensity);
  205.             rectangle(.4, x1);
  206.             x1=x2-x1;
  207.             }
  208.         wait(); clear_graphics();
  209.         }
  210.  
  211.                         /*
  212.                             timed squares
  213.                         */
  214. SCR_12:
  215.     set_intensity(1.);
  216.     set_background_intensity(0.);
  217.     if(!no_characters)
  218.         {gotoxy(pixels_wide-char_width*11, pixels_high-1);
  219.         (*draw_text)("12: timing");
  220.         }
  221.     timed_squares();
  222.     d1=t1; d2=t2; d3=t3;
  223.     del1=d2-d1; del2=d3-d2;
  224.     if(!erasing) {del1=2*del1; del2=2*del2; clear_graphics();}
  225.     if(!no_characters)
  226.         {gotoxy(0, char_height);
  227.         if(d2 > d1)
  228.             {sprintf(buf, "large square: %3.0f tics, or %3.0f lines/sec\n",
  229.             d2 - d1, 32000./del1);
  230.             (*draw_text)(buf);
  231.             }
  232.         if(d3 > d2)
  233.             {sprintf(buf, "small square: %3.0f tics, or %3.0f lines/sec\n\n",
  234.             d3 - d2, 32000./del2);
  235.             (*draw_text)(buf);
  236.             }
  237.         }
  238.     else
  239.         {if(d1 > d2)
  240.             printf(buf, "large square: %3.0f tics, or %3.0f lines/sec\n",
  241.             d2 - d1, 32000./del1);
  242.         if(d2 > d1)
  243.             printf(buf, "small square: %3.0f tics, or %3.0f lines/sec\n\n",
  244.             d3 - d2, 32000./del2);
  245.         }
  246.     if(d2 > d1 && d3 > d2 && del2 > del1)
  247.         {maximum_rate=(32000.*9)/(10*(del2)-(del1));
  248.         minimum_rate=(32000.*maximum_rate)/(2*maximum_rate*(del1)-16000.);
  249.         overhead=(100*minimum_rate)/maximum_rate;
  250. /*        sprintf(buf, "maximum drawing speed = %4.0f lines/sec  \n", maximum_rate);
  251.             (*draw_text)(buf); */
  252.         sprintf(buf, "minimum drawing speed = %4.0f lines/sec  \n", minimum_rate);
  253.             (*draw_text)(buf);
  254.         sprintf(buf, "(for which %ld%% is overhead independent of line length) \n",
  255.             overhead);
  256.             (*draw_text)(buf);
  257.         }
  258.  
  259.     wait(); clear_graphics();
  260.  
  261.                         /*
  262.                             draw stripes of negative and positive width 
  263.                             and bow tie of horizontal lines                    
  264.                         */    
  265. SCR_13:
  266.     set_intensity(1.);
  267.     set_background_intensity(0.);
  268.     if(!no_characters)
  269.         {gotoxy(0, pixels_high-1*char_height);
  270.         (*draw_text)("13: accurate horizontal lines?");
  271.         }
  272.     set_intensity(.7);
  273.     for(x1=20, k=-13; k<19; x1+=abs(k)+9, k++)
  274.         {i=x1;
  275.         for(y1=0; y1<39 && i+k<pixels_wide; i++, y1++)
  276.             (*draw_line)(i, y1, i+k, y1);
  277.         }
  278.     x1=0; x2=pixels_high/3;
  279.     for(y1=40; y1<pixels_high && x1<pixels_wide ; y1++)
  280.         {(*draw_line)(x1, y1, x2, y1);
  281.         x2++;
  282.         x1+=2;
  283.         }
  284.     wait(); clear_graphics();
  285.     if(erasing)
  286.         {
  287.         set_intensity(1.);
  288.         set_background_intensity(0.);
  289.         if(!no_characters)
  290.             {gotoxy(0, pixels_high-1*char_height);
  291.             (*draw_text)("13: erasing horizontal lines?");
  292.             }
  293.         y2 = pixels_high - 2*char_height - 1;
  294.         solid_square(.7, 0, 0, pixels_wide - 1, y2);
  295.         set_intensity(.7);
  296.         for(x1=20, k=-13; k<19; x1+=abs(k)+9, k++)
  297.             {i=x1;
  298.             for(y1=0; y1<39 && i+k<pixels_wide; i++, y1++)
  299.                 (*erase_line)(i, y1, i+k, y1);
  300.             }
  301.         x1=0; x2=pixels_high/3;
  302.         for(y1=40; y1<y2 && x1<pixels_wide ; y1++)
  303.             {(*erase_line)(x1, y1, x2, y1);
  304.             x2++;
  305.             x1+=2;
  306.             }
  307.         wait(); clear_graphics();
  308.         }
  309.     if(flipping)
  310.         {
  311.         set_intensity(1.);
  312.         set_background_intensity(0.);
  313.         if(!no_characters)
  314.             {gotoxy(0, pixels_high-1*char_height);
  315.             (*draw_text)("13: flipping horizontal lines?");
  316.             }
  317.         fan();
  318.         for(x1=20, k=-13; k<19; x1+=abs(k)+9, k++)
  319.             {i=x1;
  320.             for(y1=0; y1<39 && i+k<pixels_wide; i++, y1++)
  321.                 (*flip_line)(i, y1, i+k, y1);
  322.             }
  323.         x1=0; x2=pixels_high/3;
  324.         for(y1=40; y1<y2 && x1<pixels_wide ; y1++)
  325.             {(*flip_line)(x1, y1, x2, y1);
  326.             x2++;
  327.             x1+=2;
  328.             }
  329.         wait(); 
  330.         for(x1=20, k=-13; k<19; x1+=abs(k)+9, k++)
  331.             {i=x1;
  332.             for(y1=0; y1<39 && i+k<pixels_wide; i++, y1++)
  333.                 (*flip_line)(i, y1, i+k, y1);
  334.             }
  335.         x1=0; x2=pixels_high/3;
  336.         for(y1=40; y1<y2 && x1<pixels_wide ; y1++)
  337.             {(*flip_line)(x1, y1, x2, y1);
  338.             x2++;
  339.             x1+=2;
  340.             }
  341.         wait();
  342.  
  343.  
  344.         set_intensity(1.);
  345.         set_background_intensity(0.);
  346.         if(!no_characters)
  347.             {gotoxy(0, pixels_high-1*char_height);
  348.             (*draw_text)("13: flipping lines?           ");
  349.             }
  350.         x1 = pixels_wide/2; y1 = 0;
  351.         x2 = pixels_wide/2, y2 = pixels_high-1;
  352.         for ( ; x1 && y2; x1--)
  353.             {flip_box(x1, y1, x2, y2);
  354.             flip_box(x1--, y1++, x2++, y2--);
  355.             }
  356.         flip_star();
  357.         wait(); 
  358.         flip_star();
  359.  
  360.         wait(); clear_graphics();
  361.         }
  362.  
  363.                         /*
  364.                             draw bow tie of vertical lines
  365.                         */
  366. SCR_14:
  367.     set_intensity(1.);
  368.     set_background_intensity(0.);
  369.     if(!no_characters)
  370.         {gotoxy(0, pixels_high-1*char_height);
  371.         (*draw_text)("14: accurate vertical lines?");
  372.         }
  373.     x1=20;
  374.     set_intensity(.5);
  375.     for(y1=0, y2=pixels_high/5 ; y1<(pixels_high*7)/8 ; x1++, y2++, y1+=2)
  376.         (*draw_line)(x1, y1, x1, y2);
  377.     k=-10;
  378.     for(x1=35 ; x1+20<pixels_wide ; x1+=abs(k)+9)
  379.         {x2=x1;
  380.         for(y1=11 ; y1<25 ; y1++)
  381.             {(*draw_line)(x2, y1, x2, y1+k);
  382.             x2++;
  383.             }
  384.         k++;
  385.         }
  386.     wait(); clear_graphics();
  387.  
  388.                         /*
  389.                             right triangle (near-vertical lines)
  390.                         */
  391. SCR_15:
  392.     set_intensity(1.);
  393.     set_background_intensity(0.);
  394.     if(!no_characters)
  395.         {gotoxy(0, pixels_high-3*char_height);
  396.         (*draw_text)("15: centered step in near-vertical\n");
  397.         (*draw_text)("and near-horizontal lines?");
  398.         }
  399.     j=0;
  400.     set_intensity(.7);
  401.     for (i=3; i<100; i=i+3)
  402.         {(*draw_line)(i, 0, i-1, j);
  403.         (*draw_line)(0, i, j, i-1); j=j+1;
  404.         }
  405.     wait(); clear_graphics();
  406.  
  407.                         /*
  408.                             this should draw a vertical line
  409.                         */
  410. SCR_16:
  411.     if(!no_characters)
  412.         {gotoxy(0, char_height);
  413.         (*draw_text)("16: display of zero-length horizontal lines");
  414.         }
  415.     for (i=50;i<100; i++) (*draw_line)(pixels_wide/2, i, pixels_wide/2, i);
  416.     wait(); clear_graphics();
  417.  
  418.                         /*
  419.                             color bars
  420.                         */
  421. SCR_17:
  422.     if(!no_characters) gotoxy(0, char_height);
  423.     (*draw_text)("17: color & intensity bars \n");
  424.     x1=pixels_wide-1;
  425.     y2=char_height;
  426.     for (i=0; i<=max_color && y2<pixels_high; i++)
  427.         {set_color(i);
  428.         for (j=0; j<pixels_high/(max_color+1)/2 && j<7; j++) 
  429.             {(*draw_line)(0, y2, x1, y2); y2++;
  430.             }
  431.         y2 += 3;
  432.         }
  433.     gotoxy(3*char_width, 6*char_height); (*draw_text)("text");
  434.  
  435.                         /*
  436.                             intensity bars
  437.                         */
  438.     x1=0; x2=pixels_wide/3;
  439.     y1=pixels_high-1;
  440.     for (intensity=0.; intensity<=1.; intensity+=3./(pixels_high-y2))
  441.         {set_intensity(intensity);
  442.         (*draw_line)(x1, y1, x2, y1); y1--;
  443.         }
  444.     wait();
  445.     if(erasing)
  446.         {
  447.                         /*
  448.                             erasing color bars
  449.                         */
  450. /* an 'A' on row r, column c  has lower left corner on raster (y value)
  451.             y =     r*char_height + y_offset 
  452.     at pixel
  453.             x =     c*char_width + x_offset            */
  454. SCR_18:
  455.         if(!no_characters)
  456.             {gotoxy(0, char_height);
  457.             (*draw_text)("18: erasing                                  ");
  458.             }
  459.         y1=char_height;
  460.         x1=12*char_width;
  461.         x2=pixels_wide*7/10;
  462.         if(!no_characters) gotoxy(x1, char_height);
  463.         for (i=0; i<=max_color && x1<pixels_wide; i++)
  464.             {set_intensity(1.);
  465.             set_background_intensity(0.);
  466.             if(!no_characters)
  467.                 {sprintf(buf, "%3d", i); (*draw_text)(buf);
  468.                 }
  469.             set_color(i);
  470.             x1 += 3*char_width;
  471.             (*erase_line)(x1-3, y1, x1-3*char_width-3, y2);
  472.             (*erase_line)(x1-2, y1, x1-3*char_width-2, y2);
  473.             (*erase_line)(x1-1, y1, x1-3*char_width-1, y2);
  474.             }
  475.         wait(); clear_graphics();
  476.         }
  477. SCR_19:
  478.     if(!no_characters)
  479.         {gotoxy(0, pixels_high - 1);
  480.         set_color(0);
  481.         set_background_color(max_color);
  482.         (*draw_text)("19: text colors                              ");
  483.         x1 = y1 = 0;
  484.         gotoxy(0, y1 += char_height);
  485.         (*draw_text)("fore  back");
  486.         gotoxy(0, y1 += char_height);
  487.         (*draw_text)("    ");
  488.         for (i = 0; i <= max_color && x1 < pixels_wide; i++)
  489.             {sprintf(buf, " %2d ", i);
  490.             (*draw_text)(buf);
  491.             }
  492.         for (j = 0; j <= max_color && y1 < pixels_high; j++)
  493.             {gotoxy(0, y1 += char_height);
  494.             set_color(0);
  495.             set_background_color(max_color);
  496.             sprintf(buf, " %2d ", j);
  497.             (*draw_text)(buf);
  498.             set_color(j);
  499.     
  500.             for (x1 = i = 0; i <= max_color && x1 < pixels_wide; i++)
  501.                 {set_background_color(i);
  502.                 (*draw_text)(" jrv");
  503.                 x1 += 4*char_width;
  504.                 }
  505.             }
  506.  
  507.         wait(); clear_graphics();
  508.         }
  509.  
  510. SCR_20:
  511.     if(!no_characters)
  512.         {gotoxy(0, pixels_high - 1);
  513.         set_color(0);
  514.         set_background_color(max_color);
  515.         (*draw_text)("20: bars                                     ");
  516.         for (i = 0; i <= max_color && i < 8; i++)
  517.             {set_color(i);
  518.             x1 = 0;
  519.             x2 = pixels_wide/2 - 1;
  520.             y2 = pixels_high - 2.*char_height;
  521.             for (y1 = char_height; y1 < y2; y1++)
  522.                 (*draw_line)(x1, y1, x2, y1);
  523.             }
  524. /*        for (i = 0; i <= max_color && i < 8; i ++)
  525.             {set_color(i);
  526.             x1 = 0;
  527.             x2 = pixels_wide/2 - 1;
  528.             y2 = pixels_high - 2.*char_height;
  529.             x1 = x2; x2 = pixels_wide - 1;
  530.             bar(x1, char_height, x2, y2); 
  531.             }
  532. */
  533.         wait(); clear_graphics();
  534.         }
  535.  
  536.     finish_graphics();
  537. }
  538.  
  539. fan()
  540. {    int x1, x2, y1, y2;
  541.  
  542.     set_intensity(.7);
  543.     x1 = pixels_high & (~31); 
  544.     x2 = 0;
  545.     y2 = pixels_high - 2*char_height - 1;
  546.     while(x1 < pixels_wide)
  547.         {
  548.         while(x1&32)
  549.             {
  550.             if(x1 >= pixels_wide) break;        
  551.             (*draw_line)(x1++, 0, x2++, y2);
  552.             }
  553.         x1 += 32;
  554.         }
  555. }
  556.  
  557. box(x1, y1, x2, y2) int x1, y1, x2, y2;
  558. {    (*draw_line)(x1, y1, x1, y2); 
  559.     (*draw_line)(x1, y2, x2, y2); 
  560.     (*draw_line)(x2, y2, x2, y1); 
  561.     (*draw_line)(x2, y1, x1, y1);
  562.     }
  563.  
  564. flip_box(x1, y1, x2, y2) int x1, y1, x2, y2;
  565. {
  566.     (*flip_line)(x1, y1, x2, y1);
  567.     (*flip_line)(x2, y1, x2, y2);
  568.     (*flip_line)(x2, y2, x1, y2);
  569.     (*flip_line)(x1, y2, x1, y1);
  570. }
  571.  
  572. flip_star()
  573. {    int x1, x2, y1, y2, i;
  574.  
  575.     x2=pixels_wide*best_height-1; x1=x2/2;
  576.     y2=(pixels_high - char_height*2)*best_width-1; y1=y2/2;
  577.     for (i=0; i<20; i++) {(*flip_line)(x1, y1, 0, (int)((i*y2)/20));}
  578.     for (i=0; i<20; i++) {(*flip_line)(x1, y1, (int)((i*x2)/20), y2);}
  579.     for (i=20; i>0; i--) {(*flip_line)(x1, y1, x2, (int)((i*y2)/20));}
  580.     for (i=20; i>0; i--) {(*flip_line)(x1, y1, (int)((i*x2)/20), 0);}
  581. }
  582.  
  583. char s1[]="6: vertical clipping ";
  584. char s2[]="7: horizontal clipping ";
  585.  
  586. char_placement()
  587. {    int i, n;
  588.     char **sv;
  589.  
  590.     switch(starting_screen)
  591.         {
  592.         case 0:
  593.         case 3: goto CHAR_SCR_3;
  594.         case 4: goto CHAR_SCR_4;
  595.         case 5: goto CHAR_SCR_5;
  596.         case 6: goto CHAR_SCR_6;
  597.         case 7: goto CHAR_SCR_7;
  598.         }
  599.                         /*
  600.                             display scattered characters
  601.                         */
  602. CHAR_SCR_3:
  603.     gotoxy(0, char_height);
  604.     set_intensity(1.);
  605.     set_background_intensity(0.);
  606.     (*draw_text)(" 3: character size \n and placement?");
  607.     gotoxy(char_width, 8*char_height);
  608.     sprintf(buf, "screen height:width ratio %5.3f:%5.3f\n",
  609.         best_height, best_width);
  610.     (*draw_text)(buf);
  611.     q=0; 
  612.     for(i=0; i<64; i++)
  613.         {n=(q>>3)+(q&7); 
  614.         gotoxy(
  615.             ((q&7)+pixels_wide/char_width-8)*char_width,
  616.             ((q>>3)+1)*char_height);
  617.         (*draw_char)('a'+n);
  618.         gotoxy(
  619.             (q&7)*char_width,
  620.             (pixels_high-1+((q>>3)-7)*char_height));
  621. /*            ((q>>3)+pixels_high/char_height-7)*char_height); */
  622.         (*draw_char)('a'+n);
  623.         q=(q+17)%64;
  624.         }
  625.     gotoxy(char_width, 5*char_height);
  626.     set_intensity(1.);
  627.     x2=pixels_wide-1; x1=x2-8*char_width;
  628.     y1=0; y2=y1+char_height*8;
  629.     box(x1, y1, x2, y2);          /* upper right corner */
  630.     x1=0; x2=x1+char_width*8;
  631.     y2=pixels_high-1; y1=y2-8*char_height; 
  632.     box(x1, y1, x2, y2);          /* lower left corner */
  633.     wait(); clear_graphics();
  634.  
  635.                         /*
  636.                             time the writing of characters
  637.                         */
  638. CHAR_SCR_4:
  639.     gotoxy(0, char_height);
  640.     (*draw_text)("4: text display speed");
  641.     t1=tics(); n=0;
  642.     do
  643.         {
  644.         gotoxy(0,(pixels_high-char_height*7)/2);
  645.         set_intensity(.5);
  646.         for (sv=preamble; *sv; sv++) {n+=strlen(*sv); (*draw_text)(*sv);}
  647.         t2 = tics();
  648.         } while((t2 - t1) < 100 && n < 5000);
  649.     set_intensity(1.);
  650.     set_background_intensity(0.);
  651.     if(t2!=t1)
  652.         {sprintf(buf, "          displayed %3.0f char/sec", (100.*n)/(t2-t1));
  653.         (*draw_text)(buf);
  654.         }
  655.     else (*draw_text)("(timing disabled)");
  656.     wait(); clear_graphics();
  657.  
  658.                         /*
  659.                             time the writing of characters
  660.                         */
  661. CHAR_SCR_45:
  662.     gotoxy(0, char_height);
  663.     (*draw_text)("4: text display speed");
  664.     t1=tics(); n=0;
  665.     do
  666.         {
  667.         gotoxy(0,(pixels_high-char_height*7)/2);
  668.         set_intensity(0.);
  669.         set_background_intensity(.5);
  670.         for (sv=preamble; *sv; sv++) {n+=strlen(*sv); (*draw_text)(*sv);}
  671.         t2 = tics();
  672.         } while((t2 - t1) < 100 && n < 5000);
  673.     set_intensity(1.);
  674.     set_background_intensity(0.);
  675.     if(t2!=t1)
  676.         {sprintf(buf, "          displayed %3.0f char/sec", (100.*n)/(t2-t1));
  677.         (*draw_text)(buf);
  678.         }
  679.     else (*draw_text)("(timing disabled)");
  680.     wait(); clear_graphics();
  681.  
  682.                         /*
  683.                             check placement of char
  684.                         */
  685. CHAR_SCR_5:
  686. /*
  687.     x0=5;
  688.     for (y0=5; x0<pixels_wide; y0++, x0+=5*char_width)
  689.         {gotoxy(x0, y0); sprintf(buf,"y=%d", y0); (*draw_text)(buf);
  690.         }
  691. */
  692.     n=(char_rows-4)/2;
  693.     if(n>char_columns/5) n=char_columns/5;
  694.     x0=x1=pixels_wide/2-n*char_width;
  695.     y0=y1=2*char_height;
  696.     for (i=n; i; i--)
  697.         {x2=x1; y2=y1;
  698.         for (j=n; j; j--)
  699.             {gotoxy(x2, y2); (*draw_char)('/');
  700.             x2+=2*char_width; y2++;
  701.             }
  702.         x1++; y1+=2*char_height;
  703.         }
  704.     set_intensity(.4);
  705.     x2=2*n*char_width; y2=2*n*char_height;  /* line lengths */
  706.     n++;  /* # lines in each direction */
  707.     x1=x0=x0-char_width/2; y1=y0=y0-(char_height*3)/2;  /* top left corner */
  708.     for (i=n; i; i--)
  709.         {(*draw_line)(x1, y1, x1+x2, y1+n);
  710.         x1++; y1+=2*char_height;
  711.         }
  712.     for (i=n; i; i--)
  713.         {(*draw_line)(x0, y0, x0+n, y0+y2);
  714.         x0+=2*char_width; y0++;
  715.         }
  716.     set_intensity(1.); gotoxy(0, pixels_high - char_height);
  717.     set_background_intensity(0.);
  718.     (*draw_text)("5: Accuracy of \n   character placement?");
  719.     wait(); clear_graphics();
  720.  
  721.                         /*
  722.                             check vertical clipping
  723.                         */
  724. CHAR_SCR_6:
  725.     set_intensity(.4);
  726.     box(0, 0, pixels_wide-1, pixels_high-1);
  727.     set_intensity(1.);
  728.     set_background_intensity(0.);
  729.     gotoxy((pixels_wide-char_width*strlen(s1))/2, pixels_high/2);
  730.     (*draw_text)(s1);
  731.     i=0;
  732.     for (y2=pixels_wide/char_width; y2>2*char_height; y2-=char_height)
  733.         {x1=12; y1=y2;
  734.         while(x1<pixels_wide)
  735.             {gotoxy(x1,char_height/2+y1); (*draw_char)('a'+i);
  736.             gotoxy(x1,pixels_high+char_height/2-y1); (*draw_char)('A'+i);
  737.             x1+=char_width; y1--;
  738.             }
  739.         i++;
  740.         }
  741.     wait(); clear_graphics();
  742.  
  743.                         /*
  744.                             check horizontal clipping
  745.                         */
  746. CHAR_SCR_7:
  747.     set_intensity(.4);
  748.     box(0, 0, pixels_wide-1, pixels_high-1);
  749.     set_intensity(1.);
  750.     set_background_intensity(0.);
  751.     gotoxy((pixels_wide-char_width*strlen(s2))/2, pixels_high/2);
  752.     (*draw_text)(s2);
  753.     i=0;
  754.     for (x2=2*pixels_high/char_height; x2>char_width; x2-=char_width)
  755.         {x1=x2; y1=2*char_height;
  756.         while(y1<pixels_high)
  757.             {gotoxy(x1-char_width/2,y1); (*draw_char)('a'+i);
  758.             gotoxy(pixels_wide-x1-char_width/2,y1); (*draw_char)('A'+i);
  759.             x1--; y1+=char_height;
  760.             }
  761.         i++;
  762.         }
  763. }
  764.  
  765. rectangle(size, move) double size; int move;
  766. {    int x1, y1, x2, y2, i;
  767.  
  768.     x2=size*pixels_wide*best_height-1; x1=x2/2;
  769.     y2=size*pixels_high*best_width-1; y1=y2/2;
  770.     for (i=0; i<20; i++) {(*draw_line)(move+x1, y1, move+0, (i*y2)/20);}
  771.     for (i=0; i<20; i++) {(*draw_line)(move+x1, y1, move+(i*x2)/20, y2);}
  772.     for (i=20; i>0; i--) {(*draw_line)(move+x1, y1, move+x2, (i*y2)/20);}
  773.     for (i=20; i>0; i--) {(*draw_line)(move+x1, y1, move+(i*x2)/20, 0);}
  774.     for (i=0; i<20; i++) {(*erase_line)(move+x1, y1, move+0, (i*y2)/20);}
  775.     for (i=0; i<20; i++) {(*erase_line)(move+x1, y1, move+(i*x2)/20, y2);}
  776.     for (i=20; i>0; i--) {(*erase_line)(move+x1, y1, move+x2, (i*y2)/20);}
  777.     for (i=20; i>0; i--) {(*erase_line)(move+x1, y1, move+(i*x2)/20, 0);}
  778. }
  779.  
  780. rectangles()
  781. {    int x1, x2, y1, y2, w1, w2, dx, dy;
  782.  
  783.                         /*
  784.                             drawing a rectangle
  785.                         */
  786.     set_intensity(1.);
  787.     set_background_intensity(0.);
  788.     if(!no_characters)
  789.         {gotoxy(0, pixels_high-2*char_height);
  790.         (*draw_text)("10: lines in different");
  791.         gotoxy(0, pixels_high-1*char_height);
  792.         (*draw_text)("directions symmetric?");
  793.         }
  794.     set_intensity(.6);
  795.     dx=pixels_wide/40; dy=pixels_high/30;
  796.     x1=pixels_wide/4; y1=pixels_high/4;
  797.     w1=w2=0;
  798.     while(w2<pixels_high/2)    {(*draw_line)(x1, y1, w1, w2); w2+=dy;} y2=w2;
  799.     while(w1<pixels_wide/2)    {(*draw_line)(x1, y1, w1, w2); w1+=dx;}
  800.     while(w2>0)             {(*draw_line)(x1, y1, w1, w2); w2-=dy;}
  801.     while(w1>0)             {(*draw_line)(x1, y1, w1, w2); w1-=dx;}
  802.  
  803.                         /*
  804.                             erasing a rectangle
  805.                         */
  806.     if(erasing)
  807.         {set_intensity(1.);
  808.         set_background_intensity(0.);
  809.         x1=pixels_wide/2; x2=pixels_wide-1;
  810.  
  811.         y1 = 0; 
  812.         dy = pixels_high/30;
  813.         y2 = pixels_high/2 + dy - 1; y2 -= y2%dy;
  814.         dx = pixels_wide/16;
  815.         dy = pixels_high/16;
  816.         solid_square(1.0, x1, y1, x2, y2);
  817.         if(max_color > 1)
  818.             {solid_square(.75, x1+=dx, y1+=dy, x2-=dx, y2-=dy);
  819.             solid_square(.50, x1+=dx, y1+=dy, x2-=dx, y2-=dy);
  820.             solid_square(.25, x1+=dx, y1+=dy, x2-=dx, y2-=dy);
  821.             }
  822. /*        for(y1=0; y1<y2; y1++) draw_line(x1, y1, x2, y1); */
  823.         dx=pixels_wide/40; dy=pixels_high/30;
  824.         x1=pixels_wide/4*3; y1=pixels_high/4;
  825.         x2=pixels_wide-1; y2=0;
  826.         x1=x2-pixels_wide/4;
  827.         while(y2<pixels_high/2)    {(*erase_line)(x1, y1, x2, y2); y2+=dy;}
  828.         while(x2>pixels_wide/2)    {(*erase_line)(x1, y1, x2, y2); x2-=dx;}
  829.         while(y2>0)                {(*erase_line)(x1, y1, x2, y2); y2-=dy;}
  830.         while(x2<pixels_wide-1)    {(*erase_line)(x1, y1, x2, y2); x2+=dx;}
  831.         }
  832. }
  833.  
  834. solid_square(gray, x1, y1, x2, y2) double gray; int x1, y1, x2, y2;
  835. {    int y;
  836.     set_intensity(gray);
  837.     if(y2 < y1) {y = y1; y1 = y2; y2 = y;}
  838.     for (y = y1; y <= y2; y++)
  839.         (*draw_line)(x1, y, x2, y);
  840. }
  841.  
  842. timed_squares()
  843. {    int x1, x2, y1, y2;
  844.     long i;
  845.  
  846.     t1=tics();
  847.     x2=pixels_wide*best_height-1; x1=x2/2;
  848.     y2=pixels_high*best_width-1; y1=y2/2;
  849.     for (i=0; i<40; i++) {(*draw_line)(x1, y1, 0, (int)((i*y2)/40));}
  850.     for (i=0; i<40; i++) {(*draw_line)(x1, y1, (int)((i*x2)/40), y2);}
  851.     for (i=40; i>0; i--) {(*draw_line)(x1, y1, x2, (int)((i*y2)/40));}
  852.     for (i=40; i>0; i--) {(*draw_line)(x1, y1, (int)((i*x2)/40), 0);}
  853.     if(erasing)
  854.         {for (i=0; i<40; i++) {(*erase_line)(x1, y1, 0, (int)((i*y2)/40));}
  855.         for (i=0; i<40; i++) {(*erase_line)(x1, y1, (int)((i*x2)/40), y2);}
  856.         for (i=40; i>0; i--) {(*erase_line)(x1, y1, x2, (int)((i*y2)/40));}
  857.         for (i=40; i>0; i--) {(*erase_line)(x1, y1, (int)((i*x2)/40), 0);}
  858.         }
  859.     t2=tics();
  860.     x2=x2/10; x1=x2/2;
  861.     y2=y2/10; y1=y2/2;
  862.     for (i=0; i<40; i++) {(*draw_line)(x1, y1, 0, (int)((i*y2)/40));}
  863.     for (i=0; i<40; i++) {(*draw_line)(x1, y1, (int)((i*x2)/40), y2);}
  864.     for (i=40; i>0; i--) {(*draw_line)(x1, y1, x2, (int)((i*y2)/40));}
  865.     for (i=40; i>0; i--) {(*draw_line)(x1, y1, (int)((i*x2)/40), 0);}
  866.     if(erasing)
  867.         {for (i=0; i<40; i++) {(*erase_line)(x1, y1, 0, (int)((i*y2)/40));}
  868.         for (i=0; i<40; i++) {(*erase_line)(x1, y1, (int)((i*x2)/40), y2);}
  869.         for (i=40; i>0; i--) {(*erase_line)(x1, y1, x2, (int)((i*y2)/40));}
  870.         for (i=40; i>0; i--) {(*erase_line)(x1, y1, (int)((i*x2)/40), 0);}
  871.         }
  872.     t3=tics();
  873. }
  874.  
  875.                         /*
  876.                             displaying the available colors
  877.                         */
  878. show_colors()
  879. {    int nc, delx, dely, x1, y1, x2, y2, i;
  880.     if(!no_characters)
  881.         {gotoxy(pixels_wide/2-10*char_width, (pixels_high+char_height)/2);
  882.         sprintf(buf, "9: all %d colors displayed?", max_color+1);
  883.         (*draw_text)(buf);
  884.         }
  885.     nc=max_color+1;
  886.     delx=.8*pixels_wide/max_color/2;
  887.     dely=.8*pixels_high/max_color/2;
  888.     x2=pixels_wide/2; x1=x2-max_color*delx;
  889.     y1=pixels_high/2; y2=y1-max_color*dely;
  890.     for(i=0; i<=max_color; i++)
  891.         {set_color(i);
  892.         (*draw_line)(0, y1, x1, y1);
  893.         (*draw_line)(x1, y1, x2, y2);
  894.         (*draw_line)(x2, y2, x2, 0);
  895.         (*draw_line)(x1, pixels_high-1-y1, x2, pixels_high-y2);
  896.         (*draw_line)(0, pixels_high-1-y1, x1, pixels_high-1-y1);
  897.         (*draw_line)(x2, pixels_high-y2, x2, pixels_high-1);
  898.         y1 -= dely; x1 += delx; x2 += delx; y2 += dely;
  899.         }
  900. }
  901.  
  902. wait()
  903. {    char c;
  904. #ifdef __TURBOC__
  905.     c=getch();
  906. #else
  907.     c=ci();
  908. #endif
  909.     if((c=='q')|(c=='x')) {finish_graphics(); exit();}
  910. }
  911.  
  912. #ifdef JKHJJ
  913. typedef struct PRIM_ATTR
  914.     {int    color_count;               /* # colors                          */
  915.     int     intensity_count;           /* # intensities                     */
  916.     int     intensities_in_hardware;   /* nonzero if supported in hardware  */
  917.     int     hardware_linestyles;       /* # linestyles in hardware          */
  918.     int     software_linestyles;       /* # linestyles in software          */
  919.     int     linewidth_count;           /* # linewidths                      */
  920.     int     linewidths_in_hardware;    /* nonzero if supported in hardware  */
  921.     int     linewidth_minimum;         /*                                   */
  922.     int     linewidth_maximum;         /*                                   */
  923.     int     hardware_pens;             /*                                   */
  924.     int     software_pens;             /*                                   */
  925.     int     charfont_count;            /* # fonts                           */
  926.     int     charsize_count;            /* # character sizes                 */
  927.     int     charsize_in_hardware;      /* nonzero if supported in hardware  */
  928.     int     charsize_minimum;          /*                                   */
  929.     int     charsize_maximum;          /*                                   */
  930.     int     hardware_markers;          /* # markers in hardware             */
  931.     int     software_markers;          /* # markers in software             */
  932.     int     pick_id_count;             /* # pick IDs in hardware            */
  933.     };
  934.  
  935. /* print_prim_attr - print primitive attribute structure */
  936. print_prim_attr(pa) PRIM_ATTR *pa;
  937. {    sprintf(buf, "Primitive attributes...\n");
  938.     (*draw_text)(buf);
  939.     sprintf(buf, "color_count=               %d \n", pa->color_count);
  940.     (*draw_text)(buf);
  941.     sprintf(buf, "intensity_count=           %d \n", pa->intensity_count);
  942.     (*draw_text)(buf);
  943.     sprintf(buf, "intensities_in_hardware=   %d \n", pa->intensities_in_hardware);
  944.     (*draw_text)(buf);
  945.     sprintf(buf, "hardware_linestyles=       %d \n", pa->hardware_linestyles);
  946.     (*draw_text)(buf);
  947.     sprintf(buf, "software_linestyles=       %d \n", pa->software_linestyles);
  948.     (*draw_text)(buf);
  949.     sprintf(buf, "linewidth_count=           %d \n", pa->linewidth_count);
  950.     (*draw_text)(buf);
  951.     sprintf(buf, "linewidths_in_hardware=    %d \n", pa->linewidths_in_hardware);
  952.     (*draw_text)(buf);
  953.     sprintf(buf, "linewidth_minimum=         %d \n", pa->linewidth_minimum);
  954.     (*draw_text)(buf);
  955.     sprintf(buf, "linewidth_maximum=         %d \n", pa->linewidth_maximum);
  956.     (*draw_text)(buf);
  957.     sprintf(buf, "hardware_pens=             %d \n", pa->hardware_pens);
  958.     (*draw_text)(buf);
  959.     sprintf(buf, "software_pens=             %d \n", pa->software_pens);
  960.     (*draw_text)(buf);
  961.     sprintf(buf, "charfont_count=            %d \n", pa->charfont_count);
  962.     (*draw_text)(buf);
  963.     sprintf(buf, "charsize_count=            %d \n", pa->charsize_count);
  964.     (*draw_text)(buf);
  965.     sprintf(buf, "charsize_in_hardware=      %d \n", pa->charsize_in_hardware);
  966.     (*draw_text)(buf);
  967.     sprintf(buf, "charsize_minimum=          %d \n", pa->charsize_minimum);
  968.     (*draw_text)(buf);
  969.     sprintf(buf, "charsize_maximum=          %d \n", pa->charsize_maximum);
  970.     (*draw_text)(buf);
  971.     sprintf(buf, "hardware_markers=          %d \n", pa->hardware_markers);
  972.     (*draw_text)(buf);
  973.     sprintf(buf, "software_markers=          %d \n", pa->software_markers);
  974.     (*draw_text)(buf);
  975.     sprintf(buf, "pick_id_count=             %d \n", pa->pick_id_count);
  976.     (*draw_text)(buf);
  977. }
  978.  
  979. #endif
  980.  
  981. getint(s) char *s;
  982. {    int x, i;
  983.     char buffer[128], c;
  984.  
  985.     puts(s); gets(buffer);
  986.     x=0; i=0;
  987.     while(c=buffer[i++]) x=x*10+c-'0';
  988.     return x;
  989. }
  990.  
  991. /*                            dummy routines        */
  992. /*
  993. pixel_insert(i, j) int i, j;
  994. {    printf("inserting pixel at address %d with mask %d \n", i, j);
  995.     wait();
  996. }
  997. byte_insert(i, j) int i, j;
  998. {    printf("inserting byte %d at address %d \n", j, i);
  999.     wait();
  1000. }
  1001. */
  1002. /*
  1003.     tics - report hundreths of a second since midnight
  1004. */
  1005. long tics()
  1006. {
  1007.  
  1008. #ifdef __TURBOC__
  1009. #include <sys\timeb.h>
  1010.     struct timeb TimeBuf;
  1011.     ftime(&TimeBuf);
  1012.     return 100L*TimeBuf.time + TimeBuf.millitm/10;
  1013. #else
  1014.     return 0L;
  1015.     int hr, min, sec, hun;
  1016.     _timer(&hr, &min, &sec, &hun);
  1017.     return (( (long) hr*60+min)*60+sec)*100+hun;
  1018. #endif
  1019. }
  1020.  
  1021. /* #ifndef __TURBOC__
  1022. /* _timer()
  1023. /* {
  1024. /* #asm
  1025. /*     push bp
  1026. /*     mov    ah,2ch
  1027. /*     int    21h
  1028. /*     pop bp
  1029. /*     mov    bx,[bp+4]
  1030. /*     mov    [bx],ch        ;hours
  1031. /*     mov    byte [bx+1],0
  1032. /*     mov    bx,[bp+6]
  1033. /*     mov    [bx],cl        ;minutes
  1034. /*     mov    byte [bx+1],0
  1035. /*     mov    bx,[bp+8]
  1036. /*     mov    [bx],dh        ;seconds
  1037. /*     mov    byte [bx+1],0
  1038. /*     mov    bx,[bp+10]
  1039. /*     mov    [bx],dl        ;hundreths
  1040. /*     mov    byte [bx+1],0
  1041. /* #endasm
  1042. /* }
  1043. /* #endif
  1044. /* */
  1045.  
  1046. #define FIRST_OPTION 1  /* first "dash option", where 0 is program name */
  1047. initialize_parameters(argc, argv) int argc; char **argv;
  1048. {    int i;
  1049. /*    file; */
  1050.  
  1051.     if(argc>1 && strcmp(argv[1], "?")==0) help();
  1052.     argc--; argv++;
  1053.     while(argc>0)
  1054.         {/* printf("read_data: parsing \"%s\" \n", *argv); */
  1055.         i=get_parameter(argc, argv);
  1056.         argv=argv+i; argc=argc-i;
  1057.         }
  1058. }
  1059.  
  1060. /* get_parameter - process one command line option
  1061.         (return # parameters used) */
  1062. get_parameter(argc, argv) int argc; char **argv;
  1063. {    if(streq(*argv, "-c")) {no_characters=1; return 1;}
  1064.     else if(streq(*argv, "-e")) {erasing=0; return 1;}
  1065.     else if(streq(*argv, "-n")) {starting_screen = atoi(argv[1]); return 2;}
  1066.     else gripe(argv);
  1067. }
  1068.  
  1069. int streq(a, b) char *a, *b;
  1070. {    while(*a)
  1071.         {if(*a!=*b)return 0;
  1072.         a++; b++;
  1073.         }
  1074.     return 1;
  1075. }
  1076.  
  1077. gripe(argv) char **argv;
  1078. {    puts(*argv); puts(" isn\'t a legal argument \n");
  1079.     help();
  1080. }
  1081.  
  1082. help()
  1083. {    printf("sample usage...\nbench  [options]\n");
  1084.     printf("options are:\n");
  1085.     printf("-c   omit calls to character functions \n");
  1086.     printf("-e   omit calls to erasing routine \n");
  1087.     printf("-n <num>  start on specific screen\n");
  1088.     exit();
  1089. }
  1090.