home *** CD-ROM | disk | FTP | other *** search
- v1.2, 11 Dec 91
- Toad Hall Tweak
- - Porting to Borland C++.
- - Extracted all the asm stuff in timer.c into a separate TIMER1.ASM
- module. There are *too* many incompatibilities in how all the
- different compilers deal with inline assembly language. Ptui.
- Now it's outside clean. TIMER1.OBJ (as assembled by TASM v2.0
- for the Small model) is included. The original TIMER.OBJ was
- useless because it demanded external (and unknown) libraries.
- - In TIMER.C, forced most everything (to include its function returns)
- to unsigned longs (since signs were screwing things up).
- - Hacked the TESTTIME.C code (1) to truly reflect the sec/ms returns
- (since our functions are now returning actual millisecs.
- - I still don't trust that "TIMER_DEFINITION" constant being used
- in TIMER.C .. it affects the time_elapsed() function badly when
- we have short delays (e.g., returning 0 when in fact there WAS
- elapsed time). Well, heck with it.
- - Makefiles: I included two new ones to suit the newer MAKE.EXE
- (v3.6) provided with BCC v2.0:
- MAKEFILE.BCC Nice simple one (but with all required flags)
- Usage: MAKE -fmakefile.bcc
- TESTFILE.MAK Horribleness produced by Borland's PRJ2MAK.EXE
- utility and my working TESTFILE.PRJ as produced
- by Borland's BC.EXE v2.0
- These files may need editing for your path to Borland's \lib and \include
- directories.
- I renamed the original Quick-C makefile to MAKEFILE.QCL,
- and the original TCC makefile to MAKEFILE.TCC.
-
- - Repacked the entire schmear as MSEC_13.ZIP (so we can have version
- numbers in the title, ne?)
-
- David Kirschbaum
- Toad Hall
- kirsch@usasoc.soc.mil Internet
- or kirsch%maxemail@sesi.com uunet
-
- ====
- October 1991
-
- Fred C. Smith
- 617-438-5471 (home)
- uunet!samsung!wizvax!fcshome!fredex
-
- I have taken the routines as described below and modified elapsedtime() so
- that it now returns an unsigned long representing the number of milliseconds
- elapsed since start and stop. The version described below by Mr. Pentcheff
- returns a double representing the elapsed time in seconds. This works just
- fine, but I didn't want to pay the price (in bloat) of having to load
- floating-point code into the program just to get this feature.
-
- The function prototypes listed at the bottom have been updated to reflect
- this change.
-
- NOTE that the existing documentation in this package can't make up it's
- mind whether this provides MILLIsecond or MICROsecond precision. Well,
- it's actually MILLIsecond.
-
- This stuff, as it stands now, compiles and runs just fine when compiled
- with Microsoft QuickC 2.0. I assume that it will also work with later
- versions of QuickC and with MSC 6.0--but not MSC 5.1, as it lacks the
- in-line assembler support. NOTE that I have not updated the makefiles
- for Microsoft C. It's not a big deal to compile, though. for QC2.0
- just do:
-
- qcl -c timer.c
-
- and you will get timer.obj, for inclusion in other programs.
-
- Also, I have included a copy of timer.obj, compiled with QC 2.0, for
- those of you you don't have a suitable version of Microsoft C.
- ------------------------------------------------------------------------
-
-
- Dean Pentcheff
- Department of Integrative Biology
- University of California at Berkeley
- dean@violet.berkeley.edu
-
- The code here provides PC programs with a millisecond resolution timer. It
- is entirely based on "tctimer" 1.0 by Richard S. Sadowsky (released to the
- public domain 8/10/88) which, in turn, is based on "tptime" by Brian Foley
- and Kim Kokkonen of TurboPower Software (also public domain). I have
- slightly rewritten the code to conform to C language conventions (in tctimer,
- results were passed as argument pointers rather than function returns). In
- this version, elapsedtime() returns a time in seconds rather than
- milliseconds, saving a floating point division by 1000.0.
-
- These routines reprogram the timer chip, so they probably won't work if your
- program does the same. Other than that, there should be no incompatibility
- problems. They do not interfere with Turbo's sound() and nosound()
- functions.
-
- I've tested these under Turbo C 2.0. Note that the file tctimer.c must be
- separately compiled with the standalone "tcc" compiler since it uses inline
- assembly. Attempting to compile it under "tc" will result in compile-time
- error messages.
-
- The routine "initializetimer()" MUST be called first to reset the timer. The
- calling program MUST also call "restoretimer()" before exiting to reset the
- timer to its original state.
-
-
- The following routines are included (see testtimer.c for examples):
-
- /*Reprogram the timer chip to allow 1 millisecond resolution*/
- void initializetimer(void);
-
- /*Read the timer with 1 millisecond resolution*/
- long readtimer(void);
-
- /*Calculate time elapsed (in milliseconds) between Start and Stop*/
- unsigned long elapsedtime(long start, long stop);
-
- /*Restore the timer chip to its normal state*/
- void restoretimer(void);
-
-
- Limitations
- -----------
- Because long integers are used to represent time, TCTIMER cannot be used to
- time events longer than about 60 minutes:
-
- 4,294,967,295 (= $FFFFFFFF, largest unsigned value represented by longint)
- / 1,193,181 (timer resolution in counts/second)
- ---------------
- 3,599
- / 60 (seconds/minute)
- -------
- 59.9 minutes
-
- This should hardly be a problem, however, since an event longer than an hour
- presumably doesn't need to be timed with 1-microsecond accuracy anyway.
-
- Also note that the process of reading the time takes time. Hence, results of
- timing very short events will be skewed by the overhead of reading the timer.
- The following table shows the time measured between two calls to ReadTimer,
- one right after the other.
-
- Toshiba 1000 (4.77MHz 8088) 125 microseconds (tctimer)
- ATT 6300 (8MHz 8086) 53 " (tctimer)
- Deskpro 286 (8MHz 80286) 35 " (tctimer)
- Sperry IT (7.1MHz 286, 0 wait) 32 " (tctimer)
- IBM PS/2 model 50 25 " (tctimer)
- PC Designs GV386 (16MHz) 27 " (tctimer)
- PC Source Standard 286 (10MHz) 21 " (these routines)