home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / b / bbl-v-1.zip / BBL-TEST.C < prev    next >
C/C++ Source or Header  |  1992-08-23  |  5KB  |  233 lines

  1. /*  Turbo C program to test use of BBL device driver
  2.     Written by H. D. Todd, Wesleyan University
  3.     August, 1992
  4. */
  5.  
  6. #include    <stdio.h>
  7. #include    <conio.h>
  8. #include    <dos.h>
  9. #include    <time.h>
  10.  
  11. FILE *out;
  12. void pause(void);
  13. void mode(int m);
  14. void hpos(int col);
  15. void vpos(int row);
  16.  
  17. int main(void)
  18.  
  19. {    int i,j,Elapsed;
  20.     struct time TimeOn,TimeOff;
  21.  
  22.     printf("Program to test BBL device driver\n");
  23.     printf("When paused, press any key to continue\n\n");
  24.     if ( (out=fopen("BBL-DRVR","wt")) == NULL) {
  25.         fprintf(stderr, "Cannot open output file.\n");
  26.         return 1;
  27.     }
  28.     printf("First, just write in the three modes\n");
  29.     pause();
  30.  
  31.  
  32. // mode 0 test
  33.     clrscr();
  34.     printf("Three lines in mode 0 ...");
  35.     pause();
  36.     clrscr();
  37.     mode(0);
  38.     fputs("Hello,\nWorld\nfrom BBL",out);
  39.     pause();
  40.     
  41. // mode 1 test
  42.     clrscr();
  43.     printf("One line, 5 chars in mode 1 ...");
  44.     pause();
  45.     clrscr();
  46.     mode(1);
  47.     fputs("Hello",out);
  48.     pause();
  49.  
  50. // mode 2 test
  51.     clrscr();
  52.     printf("One line, 3 chars in mode 2 ...");
  53.     pause();
  54.     clrscr();
  55.     mode(2);
  56.     fputs("BBL",out);
  57.     pause();
  58.  
  59. // mode 0 wrap
  60.     clrscr();
  61.     printf("One long string, wraps to three lines in mode 1");
  62.     pause();
  63.     clrscr();
  64.     mode(0);
  65.     fputs("This line should wrap",out);
  66.     pause();
  67.     
  68. // wrap in mode 1  --- scrolls
  69.     clrscr();
  70.     printf("One string (pause in middle) scrolls in mode 1");
  71.     pause();
  72.     clrscr();
  73.     mode(1);
  74.     fputs("Wrap ",out);
  75.     pause();
  76.     fputs("Scrol",out);
  77.     pause();
  78.  
  79. // wrap in mode 2 --- scrolls
  80.     clrscr();
  81.     printf("One string (pause in middle) scrolls in mode 2");
  82.     pause();
  83.     clrscr();
  84.     mode(2);
  85.     fputs("Wrp",out);
  86.     pause();
  87.     fputs("Scl",out);
  88.     pause();
  89.  
  90. // backspace in mode 0
  91.     clrscr();
  92.     printf("Test backspace in mode 0");
  93.     pause();
  94.     clrscr();
  95.     mode(0);
  96.     fputs("01234", out);     fflush(out);
  97.     delay(200);
  98.     fputs("\b5",out);    fflush(out);
  99.     delay(200);
  100.     fputs("\b\b6",out);    fflush(out);
  101.     delay(200);
  102.     fputs("\b\b7",out);    fflush(out);
  103.     delay(200);
  104.     fputs("\b\b8",out);    fflush(out);
  105.     delay(200);
  106.     fputs("\b\b9",out);    fflush(out);
  107.     pause();    
  108.  
  109. // backspace in mode 1
  110.     clrscr();
  111.     printf("Test backspace in mode 1");
  112.     pause();
  113.     clrscr();
  114.     mode(1);
  115.     fputs("01234", out);     fflush(out);
  116.     delay(200);
  117.     fputs("\b5",out);    fflush(out);
  118.     delay(200);
  119.     fputs("\b\b6",out);    fflush(out);
  120.     delay(200);
  121.     fputs("\b\b7",out);    fflush(out);
  122.     delay(200);
  123.     fputs("\b\b8",out);    fflush(out);
  124.     delay(200);
  125.     fputs("\b\b9",out);    fflush(out);
  126.     pause();    
  127.  
  128. // backspace in mode 2
  129.     clrscr();
  130.     printf("Test backspace in mode 2");
  131.     pause();
  132.     clrscr();
  133.     mode(2);
  134.     fputs("012", out);     fflush(out);
  135.     delay(200);
  136.     fputs("\b3",out);    fflush(out);
  137.     delay(200);
  138.     fputs("\b\b4",out);    fflush(out);
  139.     delay(200);
  140.     fputs("\b\b5",out);    fflush(out);
  141.     pause();    
  142.  
  143. // positioning in mode 0
  144.     clrscr();
  145.     printf("Test positioning in mode 0");
  146.     pause();
  147.     clrscr();
  148.     mode(0);
  149.     for (j=2;j>=0;j--) {
  150.         fputc('\v',out); fputc('0'+j,out);
  151.         for (i=0;i<5;i++) {
  152.         fputc('\t',out); fputc('0'+i,out); fputc('0'+i,out);
  153.         fflush(out); delay(200);
  154.         fputc('\t',out); fputc('9'-i,out); fputc('9'-i,out); 
  155.         fflush(out); delay(200);
  156.         };
  157.     };
  158.     pause();    
  159.  
  160.  
  161. // positioning in mode 1
  162.     clrscr();
  163.     printf("Test positioning in mode 1");
  164.     pause();
  165.     clrscr();
  166.     mode(1);
  167.         for (i=0;i<2;i++) {
  168.         fputc('\t',out); fputc('0'+i,out); fputc('0'+i,out);
  169.         fflush(out); delay(200);
  170.         fputc('\t',out); fputc('4'-i,out); fputc('4'-i,out); 
  171.         fflush(out); delay(200);
  172.         };
  173.     fputs("\t22",out); fflush(out);
  174.     pause();    
  175.  
  176. // positioning in mode 2
  177.     clrscr();
  178.     printf("Test positioning in mode 2");
  179.     pause();
  180.     clrscr();
  181.     mode(2);
  182.     fputs("\t00",out); fflush(out); delay(200);
  183.     fputs("\t22",out); fflush(out); delay(200);
  184.     fputs("\t11",out); fflush(out); delay(200);
  185.     pause();    
  186.  
  187.  
  188. // timing test, mode 1
  189.     clrscr();
  190.     printf("\nTiming test in mode 1");
  191.     pause();
  192.     clrscr();
  193.     mode(1);
  194.     gettime(&TimeOn);
  195.     for (i=0;i<100;i++) {
  196.         hpos(1);
  197.         fprintf(out,"%3d",i);
  198.         fflush(out);
  199.     };
  200.     gettime(&TimeOff);
  201.     Elapsed=((((TimeOff.ti_hour-TimeOn.ti_hour)*60
  202.            + (TimeOff.ti_min-TimeOn.ti_min))*60
  203.            + (TimeOff.ti_sec-TimeOn.ti_sec))*60
  204.            + (TimeOff.ti_hund-TimeOn.ti_hund))*10;
  205.  
  206.     printf("\nTime for 100 iterations = %d msec\n", Elapsed);
  207.  
  208.     return 0;
  209. }
  210.  
  211. void mode(int m)
  212. {
  213.     fputc('\x0e',out); fputc('0'+m,out);
  214. }
  215.  
  216. void vpos(int row)
  217. {
  218.     fputc('\v',out); fputc('0'+row,out);
  219. }
  220.  
  221. void hpos(int col)
  222. {
  223.     fputc('\t',out); fputc('0'+col,out);
  224. }
  225.  
  226. void pause(void)
  227. {
  228.     fflush(out);
  229.     while (!kbhit()) ;
  230.     getch();
  231. }
  232.  
  233.