home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pctech / hlsrc / hltext.c < prev    next >
C/C++ Source or Header  |  1988-09-09  |  4KB  |  221 lines

  1. /*+
  2.     Name:       HLTEXT.C
  3.     Author:     Kent J. Quirk
  4.         (c) Copyright 1988 Ziff Communications Co.
  5.     Abstract:   Tests a system's text speed by:
  6.         1)  using DOS to spit out X short and long lines of text
  7.         2)  using BIOS to scroll the same data
  8.         3)  using MSC's _outtext function to scroll the same data
  9.         4)  using _outtext to scroll the data inside a window
  10.         The user can set the video mode and the quantity of text.
  11.     History:    09-Sep-88   kjq     Version 1.00
  12. -*/
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <conio.h>
  18. #include <graph.h>
  19. #include <bios.h>
  20. #include "hl.h"
  21. #include "hltimes.h"
  22.  
  23. char *text[] = {
  24.         /* Rene Descartes */
  25. "Cogito, ergo sum.\r\n",
  26.         /* Oscar Wilde */
  27. "Nothing that is worth knowing can be taught.\r\n",
  28.         /* Arthur C. Clarke */
  29. "Any sufficiently advanced technology is indistinguishable from magic.\r\n"
  30. };
  31.  
  32. #define T_SHORT 0
  33. #define T_MEDIUM 1
  34. #define T_LONG 2
  35.  
  36. #define T_TOTAL 3
  37.  
  38. #define DOS 0
  39. #define BIOS 1
  40. #define MSC 2
  41. #define WIN_MSC 3
  42.  
  43. #define PTIMER(n,fmt) stop_timer(); printf(fmt,n)
  44.  
  45. void bios_text(index, nlines)
  46. int index;
  47. int nlines;
  48. {
  49.     char *p;
  50.     union REGS regs;
  51.      
  52.     while (nlines--)
  53.     {
  54.     p = text[index];
  55.     while (regs.h.al = *p++)
  56.     {    
  57.         regs.h.ah = 0x0E;        /* write TTY */
  58.         int86(0x10, ®s, ®s);
  59.     }
  60.     }
  61. }
  62.  
  63. void dos_text(index, nlines)
  64. int index;
  65. int nlines;
  66. {
  67.     while (nlines--)
  68.     fputs(text[index], stdout);
  69. }
  70.  
  71. void msc_text(index, nlines)
  72. int index;
  73. int nlines;
  74. {
  75.     _settextwindow(1,1,25,80);
  76.     _settextposition(25,1);
  77.     while (nlines--)
  78.     _outtext(text[index]);
  79. }
  80.  
  81. void win_text(index, nlines)
  82. int index;
  83. int nlines;
  84. {
  85.     _settextwindow(10,20,20,50);
  86.     _wrapon(_GWRAPOFF);
  87.     _settextposition(25,1);
  88.     while (nlines--)
  89.         _outtext(text[index]);
  90. }
  91.  
  92. void usage()
  93. {
  94.     printf("Usage:  HLTEXT [-?] [-nNLINES]\n");
  95.     printf("        NLINES is the number of lines to scroll for\n");
  96.     printf("        each subtest (default = 200)\n");
  97.     exit(1);
  98. }
  99.  
  100. char *rowname[4] = { "BIOS", "DOS", "MSC", "Windowed" };
  101. void (*scroll[4])() = {
  102.     bios_text, dos_text, msc_text, win_text
  103. };
  104. long times[4][4] = { 0 };
  105.  
  106. TIME_REC trec[] = {
  107.     { 0L, "Total: Text Scrolling" },
  108.     { 0L, "BIOS Scrolling" },
  109.     { 0L, "DOS Scrolling" },
  110.     { 0L, "MSC Scrolling" },
  111.     { 0L, "Windowed Scrolling" },
  112.     { -1L, "HLTEXT" }
  113. };
  114.  
  115. main(argc, argv)
  116. int argc;
  117. char *argv[];
  118. {
  119.     int i, j;
  120.     int nlines = 200;
  121.     int graphics = 0;
  122.     struct videoconfig config;
  123.     char *filename = NULL;
  124.     int program = -1;
  125.     int bench = 0;
  126.     int batch = 0;
  127.  
  128.     for (i=1; i<argc; i++)
  129.     {
  130.         if (argv[i][0] != '-')
  131.             usage();
  132.  
  133.         switch(tolower(argv[i][1])) {
  134.         case 'a':
  135.             batch = 1;
  136.             break;      /* ignore batch switch */
  137.         case 'b':
  138.             bench = 1;
  139.             break;
  140.         case 'n':
  141.             nlines = atoi(argv[i]+2);
  142.             break;
  143.         case 'g':
  144.             graphics = 1;
  145.             break;
  146.         case 'p':
  147.             program = atoi(argv[i]+2);
  148.             break;
  149.         case 'f':
  150.             filename = argv[i]+2;
  151.             break;
  152.         default:
  153.         case '?':
  154.             usage();
  155.             break;
  156.         }
  157.     }
  158.  
  159.     start_timer(0);
  160.     for (i=0; i<4; i++)
  161.     {
  162.         start_timer(1);
  163.         start_timer(2);
  164.         (*scroll[i])(T_SHORT, nlines);
  165.         stop_timer();
  166.         times[i][T_SHORT] = get_timer(2);
  167.  
  168.         start_timer(2);
  169.         (*scroll[i])(T_MEDIUM, nlines);
  170.         stop_timer();
  171.         times[i][T_MEDIUM] = get_timer(2);
  172.  
  173.         start_timer(2);
  174.         (*scroll[i])(T_LONG, nlines);
  175.         stop_timer();
  176.         times[i][T_LONG] = get_timer(2);
  177.         times[i][T_TOTAL] = get_timer(1);
  178.     }
  179.     trec[0].ticks=get_timer(0);
  180.  
  181.     for (i=0; i<25; i++)
  182.         printf("\n");
  183.  
  184.     if ((!bench) && (!batch))
  185.     {
  186.         printf("%12.12s%10s%10s%10s%10s\n",
  187.             " ", "Short", "Medium", "Long", "Total");
  188.         printf("%12.12s  %2d bytes  %2d bytes  %2d bytes\n",
  189.             " ", strlen(text[0]), strlen(text[1]), strlen(text[2]));
  190.         for (i=0; i<4; i++)
  191.         {
  192.             printf("\n%10.10s: ", rowname[i]);
  193.             for (j=0; j<4; j++)
  194.             {
  195.                 printf("%10s", time_secs(times[i][j]));
  196.             }
  197.             trec[i+1].ticks = times[i][T_TOTAL];
  198.         }
  199.         printf("\n");
  200.         printf("\nTotal time: %s\n", time_secs(trec[0].ticks));
  201.     }
  202.     else
  203.     {
  204.         for (i=0; i<4; i++)
  205.             trec[i+1].ticks = times[i][T_TOTAL];
  206.     }
  207.  
  208.     if ((filename != NULL) && (program >= 0))
  209.     {
  210.         if (opentime(filename))
  211.         {
  212.             for (i=0; i<(sizeof(trec)/sizeof(trec[0])); i++)
  213.             {
  214.                 savetime(program, i, &trec[i]);
  215.             }
  216.         }
  217.     }
  218.     closetime();
  219.     return(0);
  220. }
  221.