home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / timer / msec_12 / readme < prev    next >
Encoding:
Text File  |  1991-12-11  |  6.1 KB  |  147 lines

  1. v1.2, 11 Dec 91
  2. Toad Hall Tweak
  3. - Porting to Borland C++.
  4. - Extracted all the asm stuff in timer.c into a separate TIMER1.ASM
  5.   module.  There are *too* many incompatibilities in how all the
  6.   different compilers deal with inline assembly language.  Ptui.
  7.   Now it's outside clean.  TIMER1.OBJ (as assembled by TASM v2.0
  8.   for the Small model) is included.  The original TIMER.OBJ was
  9.   useless because it demanded external (and unknown) libraries.
  10. - In TIMER.C, forced most everything (to include its function returns)
  11.   to unsigned longs (since signs were screwing things up).
  12. - Hacked the TESTTIME.C code (1) to truly reflect the sec/ms returns
  13.   (since our functions are now returning actual millisecs.
  14. - I still don't trust that "TIMER_DEFINITION" constant being used
  15.   in TIMER.C .. it affects the time_elapsed() function badly when
  16.   we have short delays (e.g., returning 0 when in fact there WAS
  17.   elapsed time).  Well, heck with it.
  18. - Makefiles:  I included two new ones to suit the newer MAKE.EXE
  19.   (v3.6) provided with BCC v2.0:
  20.   MAKEFILE.BCC        Nice simple one (but with all required flags)
  21.             Usage:  MAKE -fmakefile.bcc
  22.   TESTFILE.MAK        Horribleness produced by Borland's PRJ2MAK.EXE
  23.             utility and my working TESTFILE.PRJ as produced
  24.             by Borland's BC.EXE v2.0
  25.   These files may need editing for your path to Borland's \lib and \include
  26.   directories.
  27.   I renamed the original Quick-C makefile to MAKEFILE.QCL,
  28.   and the original TCC makefile to MAKEFILE.TCC.
  29.  
  30. - Repacked the entire schmear as MSEC_13.ZIP (so we can have version
  31.   numbers in the title, ne?)
  32.  
  33. David Kirschbaum
  34. Toad Hall
  35. kirsch@usasoc.soc.mil        Internet
  36. or  kirsch%maxemail@sesi.com    uunet
  37.  
  38. ====
  39. October 1991
  40.  
  41. Fred C. Smith
  42. 617-438-5471 (home)
  43. uunet!samsung!wizvax!fcshome!fredex
  44.  
  45. I have taken the routines as described below and modified elapsedtime() so
  46. that it now returns an unsigned long representing the number of milliseconds
  47. elapsed since start and stop. The version described below by Mr. Pentcheff
  48. returns a double representing the elapsed time in seconds. This works just
  49. fine, but I didn't want to pay the price (in bloat) of having to load
  50. floating-point code into the program just to get this feature.
  51.  
  52. The function prototypes listed at the bottom have been updated to reflect
  53. this change.
  54.  
  55. NOTE that the existing documentation in this package can't make up it's
  56. mind whether this provides MILLIsecond or MICROsecond precision. Well,
  57. it's actually MILLIsecond.
  58.  
  59. This stuff, as it stands now, compiles and runs just fine when compiled
  60. with Microsoft QuickC 2.0. I assume that it will also work with later
  61. versions of QuickC and with MSC 6.0--but not MSC 5.1, as it lacks the
  62. in-line assembler support. NOTE that I have not updated the makefiles
  63. for Microsoft C. It's not a big deal to compile, though. for QC2.0
  64. just do:
  65.  
  66.     qcl -c timer.c
  67.  
  68. and you will get timer.obj, for inclusion in other programs.
  69.  
  70. Also, I have included a copy of timer.obj, compiled with QC 2.0, for
  71. those of you you don't have a suitable version of Microsoft C.
  72. ------------------------------------------------------------------------
  73.  
  74.  
  75. Dean Pentcheff
  76. Department of Integrative Biology
  77. University of California at Berkeley
  78. dean@violet.berkeley.edu
  79.  
  80. The code here provides PC programs with a millisecond resolution timer.  It
  81. is entirely based on "tctimer" 1.0 by Richard S. Sadowsky (released to the
  82. public domain 8/10/88) which, in turn, is based on "tptime" by Brian Foley
  83. and Kim Kokkonen of TurboPower Software (also public domain).  I have
  84. slightly rewritten the code to conform to C language conventions (in tctimer,
  85. results were passed as argument pointers rather than function returns).  In
  86. this version, elapsedtime() returns a time in seconds rather than
  87. milliseconds, saving a floating point division by 1000.0.
  88.  
  89. These routines reprogram the timer chip, so they probably won't work if your
  90. program does the same.  Other than that, there should be no incompatibility
  91. problems.  They do not interfere with Turbo's sound() and nosound()
  92. functions.
  93.  
  94. I've tested these under Turbo C 2.0.  Note that the file tctimer.c must be
  95. separately compiled with the standalone "tcc" compiler since it uses inline
  96. assembly.  Attempting to compile it under "tc" will result in compile-time
  97. error messages.
  98.  
  99. The routine "initializetimer()" MUST be called first to reset the timer.  The
  100. calling program MUST also call "restoretimer()" before exiting to reset the
  101. timer to its original state.
  102.  
  103.  
  104. The following routines are included (see testtimer.c for examples):
  105.  
  106. /*Reprogram the timer chip to allow 1 millisecond resolution*/
  107. void initializetimer(void);
  108.  
  109. /*Read the timer with 1 millisecond resolution*/
  110. long readtimer(void);
  111.  
  112. /*Calculate time elapsed (in milliseconds) between Start and Stop*/
  113. unsigned long    elapsedtime(long start, long stop);
  114.  
  115. /*Restore the timer chip to its normal state*/
  116. void restoretimer(void);
  117.  
  118.  
  119. Limitations
  120. -----------
  121. Because long integers are used to represent time, TCTIMER cannot be used to
  122. time events longer than about 60 minutes:
  123.  
  124.   4,294,967,295 (= $FFFFFFFF, largest unsigned value represented by longint)
  125. /     1,193,181 (timer resolution in counts/second)
  126. ---------------
  127.           3,599
  128.         /    60 (seconds/minute)
  129.         -------
  130.            59.9 minutes
  131.  
  132. This should hardly be a problem, however, since an event longer than an hour
  133. presumably doesn't need to be timed with 1-microsecond accuracy anyway.
  134.  
  135. Also note that the process of reading the time takes time. Hence, results of
  136. timing very short events will be skewed by the overhead of reading the timer.
  137. The following table shows the time measured between two calls to ReadTimer,
  138. one right after the other.
  139.  
  140.   Toshiba 1000 (4.77MHz 8088)    125 microseconds  (tctimer)
  141.   ATT 6300 (8MHz 8086)            53     "         (tctimer)
  142.   Deskpro 286 (8MHz 80286)        35     "         (tctimer)
  143.   Sperry IT (7.1MHz 286, 0 wait)  32     "         (tctimer)
  144.   IBM PS/2 model 50               25     "         (tctimer)
  145.   PC Designs GV386 (16MHz)        27     "         (tctimer)
  146.   PC Source Standard 286 (10MHz)  21     "         (these routines)
  147.