home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.update.uu.se
/
ftp.update.uu.se.2014.03.zip
/
ftp.update.uu.se
/
pub
/
rainbow
/
msdos
/
decus
/
RB101
/
pdcoregr.arc
/
BENCH.C
next >
Wrap
C/C++ Source or Header
|
1985-10-16
|
11KB
|
362 lines
/* bench - integer mode graphics demonstration and benchmark
bugs...
screen measurements: 191 mm wide by 158 mm high on Z-150
index multiple draw/erase by colors rather than intensities.
illustrate draw/erase on grid to show independent erasure.
*/
#include <stdio.h>
#include <g.h>
int no_characters=0; /* nonzero if calls to character functions are
to be avoided (presumably because they aren't
yet implemented) */
long int t1,t2,t3,min_rate,max_rate,overhead;
long tics();
main(argc,argv) int argc; char **argv;
{ int i,j,k;
int q,x1,y1,x2,y2;
int w0,w1,w2,z2;
double intensity;
double d1,d2,d3,minimum_rate,maximum_rate;
initialize_parameters(argc,argv);
init_graphics();
/* draw barber-pole patterns in top right & bottom left corners */
set_intensity(.4);
box(0,0,pixels_wide-1,pixels_high-1);
if(no_characters)
{puts("\n character routine demo omitted ");
for(i=1; i<1000; i++) for(j=1; j<100; j++) ;
set_intensity(1.);
}
else
{gotoxy(0,1);
puts(" character size \n and placement?");
q=0;
for(i=0; i<144; i++)
{gotoxy(q%12+char_columns-12,q/12);
putchar('a'+q/12+q%12);
gotoxy(q%12,q/12+char_rows-12);
putchar('a'+q/12+q%12);
q=(q+17)%144;
}
x2=char_columns*char_width+x_offset-1; x1=x2-12*char_width+1;
y1=y_offset-char_height+1; y2=y1+char_height*12-1;
set_intensity(1.);
box(x1,y1,x2,y2);
x1=x_offset; x2=x1+char_width*12-1;
y2=(char_rows-1)*char_height+y_offset; y1=y2-12*char_height+1;
box(x1,y1,x2,y2);
wait();
}
clear_graphics();
/* diamonds */
if(!no_characters) gotoxy(0,char_rows-2);
puts("lines end ");
if(!no_characters) gotoxy(0,char_rows-1);
puts("accurately?");
w0=(pixels_wide-1)/4;
y2=0;
while(y2<pixels_high) {(*draw_line)(0,pixels_high/2,w0-1,y2); y2+=5;}
while(y2>0) {y2-=5; (*draw_line)(2*w0,pixels_high/2,w0+1,y2);}
x2=pixels_wide/2; x1=pixels_wide*3/4; y1=pixels_high/2; y2=pixels_high-1;
while(x2<pixels_wide) {(*draw_line)(x1,0,x2,y1); x2+=5;}
while(x2>pixels_wide/2) {x2-=5; (*draw_line)(x1,y2,x2,y1+2);}
wait(); clear_graphics();
/* drawing & erasing rectangles */
rectangles();
wait(); clear_graphics();
/* creating & erasing rectangles of different intensities */
if(!no_characters) gotoxy(0,char_rows-1);
puts("drawing and erasing algorithms match?");
for (intensity=.938; intensity>0.; intensity-=.125)
{if(!no_characters) gotoxy(0,10);
set_intensity(1.);
printf("intensity %5.3f",intensity);
set_intensity(intensity);
rectangle(.3);
}
clear_graphics();
set_intensity(1.);
/* timed squares */
if(!no_characters) gotoxy(char_columns-7,char_rows-1);
puts("timing");
timed_squares();
if(!no_characters) gotoxy(0,0);
d1=t1; d2=t2; d3=t3;
printf("large square: %3.0f tics, or %3.0f lines/sec\n",
d2-d1,32000./(d2-d1));
printf("small square: %3.0f tics, or %3.0f lines/sec\n\n",
d3-d2,32000./(d3-d2));
maximum_rate=(32000.*9)/(10*(d3-d2)-(d2-d1));
minimum_rate=(32000.*maximum_rate)/(2*maximum_rate*(d2-d1)-16000.);
overhead=(100*minimum_rate)/maximum_rate;
/* printf("maximum drawing speed = %4.0f lines/sec \n",maximum_rate); */
printf("minimum drawing speed = %4.0f lines/sec \n",minimum_rate);
printf("(for which %D%% is overhead independent of line length) \n",
overhead);
wait(); clear_graphics();
/* draw stripes of negative and positive width
and bow tie of horizontal lines */
if(!no_characters) gotoxy(0,char_rows-1);
puts("accurate horizontal lines?");
for(x1=20,k=-13; k<19; x1+=abs(k)+9,k++)
{i=x1;
for(y1=0; y1<39 && i+k<pixels_wide; i++,y1++)
(*draw_line)(i,y1,i+k,y1);
}
x1=0; x2=pixels_high/3;
for(y1=40; y1<pixels_high && x1<pixels_wide ; y1++)
{(*draw_line)(x1,y1,x2,y1);
x2++;
x1+=2;
}
wait(); clear_graphics();
/* draw bow tie of vertical lines */
if(!no_characters) gotoxy(0,char_rows-1);
puts("accurate vertical lines?");
x1=20;
for(y1=0,y2=pixels_high/5 ; y1<(pixels_high*7)/8 ; x1++,y2++,y1+=2)
(*draw_line)(x1,y1,x1,y2);
k=-10;
for(x1=35 ; x1+20<pixels_wide ; x1+=abs(k)+9)
{x2=x1;
for(y1=11 ; y1<25 ; y1++)
{(*draw_line)(x2,y1,x2,y1+k);
x2++;
}
k++;
}
wait(); clear_graphics();
/* right triangle (near-vertical lines) */
if(!no_characters) gotoxy(0,char_rows-1);
puts("centered step in near-vertical lines?");
j=0;
for (i=pixels_wide-100; i<pixels_wide; i=i+3)
{(*draw_line)(i,0,i-1,j); j=j+1;
}
wait();
clear_graphics();
/* this should draw a vertical line */
if(!no_characters) gotoxy(0,0);
puts("display of zero-length horizontal lines");
for (i=50;i<100; i++) (*draw_line)(pixels_wide/2,i,pixels_wide/2,i);
wait();
clear_graphics();
/* draw lines with user selecting colors */
/* if(!no_characters) gotoxy(0,0);
puts("enter color code for each new line (0-7), CR to stop\n");
for (i=20; i<199; i++)
{j=getchar()-'0';
if((j<0)|(j>7)) break;
set_color(j);
(*draw_line)(0,i,50,i);
}
clear_graphics();
*/
/* color bars */
if(!no_characters) gotoxy(0,0);
puts("color bars intensity bars \n");
y2=10;
x1=pixels_wide/2;
for (i=0; i<=max_color; i++)
{set_color(i);
for (j=0; j<10; j++) {(*draw_line)(0,y2,x1,y2); y2++;}
}
y2=10;
for (i=0; i<=max_color; i++)
{set_color(i);
for (j=0; j<10; j++) {(*erase_line)(x1/2,y2,x1*4/3,y2); y2++;}
}
/* intensity bars */
y2=10;
for (intensity=0.; intensity<=1.; intensity+=.01)
{set_intensity(intensity);
(*draw_line)(x1+2,y2,pixels_wide-1,y2); y2++;
}
wait(); clear_graphics();
finish_graphics();
}
box(x1,y1,x2,y2) int x1,y1,x2,y2;
{(*draw_line)(x1,y1,x1,y2); (*draw_line)(x1,y2,x2,y2);
(*draw_line)(x2,y2,x2,y1); (*draw_line)(x2,y1,x1,y1);
}
rectangle(size) double size;
{ int x1,y1,x2,y2,i;
x2=size*pixels_wide*best_height-1; x1=x2/2;
y2=size*pixels_high*best_width-1; y1=y2/2;
for (i=0; i<40; i++) {(*draw_line)(x1,y1,0,(i*y2)/40);}
for (i=0; i<40; i++) {(*draw_line)(x1,y1,(i*x2)/40,y2);}
for (i=40; i>0; i--) {(*draw_line)(x1,y1,x2,(i*y2)/40);}
for (i=40; i>0; i--) {(*draw_line)(x1,y1,(i*x2)/40,0);}
for (i=0; i<40; i++) {(*erase_line)(x1,y1,0,(i*y2)/40);}
for (i=0; i<40; i++) {(*erase_line)(x1,y1,(i*x2)/40,y2);}
for (i=40; i>0; i--) {(*erase_line)(x1,y1,x2,(i*y2)/40);}
for (i=40; i>0; i--) {(*erase_line)(x1,y1,(i*x2)/40,0);}
}
rectangles()
{ int x1,x2,y1,y2,w1,w2;
/* drawing a rectangle */
if(!no_characters) gotoxy(0,char_rows-1);
puts("lines in different \ndirections symmetric?");
x1=pixels_wide/4; y1=pixels_high/4;
w1=w2=0;
while(w2<pixels_high/2) {(*draw_line)(x1,y1,w1,w2); w2+=5;} y2=w2;
while(w1<pixels_wide/2) {(*draw_line)(x1,y1,w1,w2); w1+=5;}
while(w2>0) {(*draw_line)(x1,y1,w1,w2); w2-=5;}
while(w1>0) {(*draw_line)(x1,y1,w1,w2); w1-=5;}
/* erasing a rectangle */
set_intensity(1.);
x1=pixels_wide/2; x2=pixels_wide-1;
for(y1=0; y1<y2; y1++) draw_line(x1,y1,x2,y1);
x1=pixels_wide/4*3; y1=pixels_high/4;
x2=pixels_wide-1; y2=0;
while(y2<pixels_high/2) {(*erase_line)(x1,y1,x2,y2); y2+=5;}
while(x2>pixels_wide/2) {(*erase_line)(x1,y1,x2,y2); x2-=5;}
while(y2>0) {(*erase_line)(x1,y1,x2,y2); y2-=5;}
while(x2<pixels_wide-1) {(*erase_line)(x1,y1,x2,y2); x2+=5;}
}
timed_squares()
{ int i,x1,x2,y1,y2;
t1=tics();
x2=pixels_wide*best_height-1; x1=x2/2;
y2=pixels_high*best_width-1; y1=y2/2;
for (i=0; i<40; i++) {(*draw_line)(x1,y1,0,(i*y2)/40);}
for (i=0; i<40; i++) {(*draw_line)(x1,y1,(i*x2)/40,y2);}
for (i=40; i>0; i--) {(*draw_line)(x1,y1,x2,(i*y2)/40);}
for (i=40; i>0; i--) {(*draw_line)(x1,y1,(i*x2)/40,0);}
for (i=0; i<40; i++) {(*erase_line)(x1,y1,0,(i*y2)/40);}
for (i=0; i<40; i++) {(*erase_line)(x1,y1,(i*x2)/40,y2);}
for (i=40; i>0; i--) {(*erase_line)(x1,y1,x2,(i*y2)/40);}
for (i=40; i>0; i--) {(*erase_line)(x1,y1,(i*x2)/40,0);}
t2=tics();
x2=x2/10; x1=x2/2;
y2=y2/10; y1=y2/2;
for (i=0; i<40; i++) {(*draw_line)(x1,y1,0,(i*y2)/40);}
for (i=0; i<40; i++) {(*draw_line)(x1,y1,(i*x2)/40,y2);}
for (i=40; i>0; i--) {(*draw_line)(x1,y1,x2,(i*y2)/40);}
for (i=40; i>0; i--) {(*draw_line)(x1,y1,(i*x2)/40,0);}
for (i=0; i<40; i++) {(*erase_line)(x1,y1,0,(i*y2)/40);}
for (i=0; i<40; i++) {(*erase_line)(x1,y1,(i*x2)/40,y2);}
for (i=40; i>0; i--) {(*erase_line)(x1,y1,x2,(i*y2)/40);}
for (i=40; i>0; i--) {(*erase_line)(x1,y1,(i*x2)/40,0);}
t3=tics();
}
wait()
{ char c;
c=getchar();
if((c=='q')|(c=='x')) {finish_graphics(); exit();}
}
getint(s) char *s;
{ int x,i;
char buffer[128],c;
puts(s); gets(buffer);
x=0; i=0;
while(c=buffer[i++]) x=x*10+c-'0';
return x;
}
/* dummy routines */
/*
mode(x) int x;
{
}
pixel_insert(i,j) int i,j;
{ printf("inserting pixel at address %d with mask %d \n",i,j);
wait();
}
byte_insert(i,j) int i,j;
{ printf("inserting byte %d at address %d \n",j,i);
wait();
}
*/
/*
tics - report hundreths of a second since midnight
*/
long tics() /* seconds since last call */
{ int hr,min,sec,hun;
_timer(&hr,&min,&sec,&hun);
return (( (long) hr*60+min)*60+sec)*100+hun;
}
_timer()
{
#asm
mov ah,2ch
int 21h
mov bx,[bp+4]
mov [bx],ch ;hours
mov byte [bx+1],0
mov bx,[bp+6]
mov [bx],cl ;minutes
mov byte [bx+1],0
mov bx,[bp+8]
mov [bx],dh ;seconds
mov byte [bx+1],0
mov bx,[bp+10]
mov [bx],dl ;hundreths
mov byte [bx+1],0
#endasm
}
#define FIRST_OPTION 1 /* first "dash option", where 0 is program name */
initialize_parameters(argc,argv) int argc; char **argv;
{ int i;
/* file; */
if(argc>1 && strcmp(argv[1],"?")==0)
{printf("sample usage...\nbench [options]\n");
printf("options are:\n");
printf("-c omit calls to character functions \n");
exit();
}
/* file=fopen(argv[1],"r");
if(file==-1){puts("file %s not found\n",argv[1]); exit();}
*/
argc=argc-FIRST_OPTION; argv=argv+FIRST_OPTION;
while(argc>0)
{/* printf("read_data: parsing \"%s\" \n",*argv); */
i=get_parameter(argc,argv);
argv=argv+i; argc=argc-i;
}
}
/* get_parameter - process one command line option
(return # parameters used) */
get_parameter(argc,argv) int argc; char **argv;
{ if(streq(*argv,"-c")) {no_characters=1; return 1;}
else gripe(argv);
}
int streq(a,b) char *a,*b;
{ while(*a)
{if(*a!=*b)return 0;
a++; b++;
}
return 1;
}
gripe(argv) char **argv;
{ puts(*argv); puts(" isn\'t a legal argument \n");
exit();
}