home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / util2 / nansi987.lzh / RAWTEST.C < prev    next >
C/C++ Source or Header  |  1987-09-13  |  3KB  |  75 lines

  1. /*_ rawtest.c   Sat Sep 12 1987   Modified by: Pat Myrto */
  2. /*------ rawtest.lc -------------------------------------------------
  3. C program to demonstrate the difference in speed between
  4. DOS's raw and cooked modes when writing to the DOS console.
  5. Requires setraw.c; make the demo as follows:
  6.     cl -o demo setraw.c rawtest.c
  7. and run it by typing
  8.     demo
  9.  
  10. Note- C's raw mode (i.e. using mode "rb" or "wb" with fopen)
  11. is not the same as DOS's raw mode, and does not affect speed.
  12.  
  13. What does affect speed is whether output is performed with single-character
  14. DOS calls, which is the default.  To get a speed improvement, you must 
  15. open "con" WITHOUT a trailing colon, and use that file for high-speed output.
  16.  
  17. Note that using stdout as the output file the ioctl function calls don't
  18. seem to affect speed ... you must open the con device - most likely
  19. the redirection capability is what bogs it down.
  20.  
  21. When using MS-DOS raw mode, the console is in totally unbuffered mode-
  22. echo is turned off, no printer echoing is done, and no line editing
  23. is done, regardless of which file setraw was applied to.  This means
  24. that the console must be in non-raw ("cooked") mode for line-oriented
  25. console input to work properly.
  26.  
  27. Note: no speed difference will be noticed when using the standard console
  28. driver ANSI.SYS that comes with DOS; you must be using NANSI.SYS to
  29. get massively fast output.  
  30. To use nansi.sys, insert the following line in \config.sys:
  31.     device = nansi.sys
  32. and put nansi.sys on the top level directory; the system will load
  33. it at boot time.
  34. (If there was already a line invoking plain old ansi.sys, remove it.)
  35. --------------------------------------------------------------------*/
  36.  
  37. #include <stdio.h>
  38.  
  39. char    response[128];
  40.  
  41. main(argc, argv)
  42. int    argc;
  43. char    **argv;
  44. {
  45.     FILE    *fp;
  46.     int    fd;
  47.     int    old_rawness;
  48.     int    i;
  49.  
  50.     fp = fopen("con", "w");
  51.     if (fp == NULL) fprintf(stderr, "can't open 'con'!");
  52.     fd = fileno(fp);        /* get Level 1 file descriptor */
  53.     old_rawness = getraw(fd);    /* Save old raw/cooked state */
  54.  
  55.     setraw(fd, 0);            /* make sure we're in cooked mode */
  56.  
  57.     puts("Cooked mode test (hit return):");
  58.     gets(response);
  59.     fprintf(fp, "\033[2J");        /* clear screen */
  60.     for (i=0; i<20; i++)
  61.         fprintf(fp, "This is cooked mode!  Why is it so darned slow? %d\n", i);
  62.     fflush(fp);
  63.  
  64.     puts("Raw mode test (hit return):");
  65.     gets(response);            /* must be in cooked mode to use gets */
  66.     setraw(fd, 1);            /* enter raw mode */
  67.     fprintf(fp, "\033[2J");        /* clear screen */
  68.     for (i=0; i<20; i++)
  69.         fprintf(fp, "-- This is raw mode- it's clearly faster than cooked! %d\n", i);
  70.     fflush(fp);            /* finish writing while in raw mode */
  71.     setraw(fp, 0);    /* go back to old raw/cooked state  */
  72.  
  73. }
  74. /*--- end of rawtest.lc ---*/
  75.