[fpc-pascal]high performance counter for dos/tp7
tom_at_work at gmx.at
Sun Mar 21 16:16:14 CET 2004
> > So a computer calling an interrupt routine a million times (for
> > accuracy) that does not seem like a good idea performance wise.
> > Also calculating the control word (?) can be inaccurate (?):
> > := $1234DD div frequency; ( ??? what about the remainder ??? )
> > So I don't really need any interrupts... I only need to be able to read
> > sort of thing that gives me a tick count and possible a tick frequency.
> > What are my alternatives for dos/turbo pascal 7 ?
> Off topic.
> > ( What about 32 bit free pascal :D ? )
> Search for Thomas Schatzl's (originally zen-)timer and CPU units. Probably
> link is on the contributed units page.
For FPC/Delphi on a few platforms there is my CPU unit, always available via
my homepage at http://members.yline.com/~tom_at_work/index.html .
On the same site there's reasonable good documentation available for it;
although it dates back to '2001, it's still up to date since nothing else
except that it can detect a few more hardware capabilities. All these
changes can be found in the accompanying docupd.txt text file...
Basically it offers an OOP timing interface with microsecond accuracy (well,
depending on your machine due to some calculation overhead and the usual OS
considerations) for most supported x86 FPC platforms I think.
Since it is based on the processor's TSC, which counts clock cycles, it is
quite useable imo. For the purists it offers direct access to the TSC value
For BP/TP the situation is as follows (as far as I remember it now and can
trace it back from my sources)...
<history, skip if not interested; hopefully not too off-topic either>
Once upon a time =) there had been some C library called ZenTimer (by M.
Abrash iirc, if you ever heard that name), which used the DOS BIOS timer
tick counter you mention, and by accident I came across a BP conversion
(iirc done by some demo coder whose name I don't know anymore and I can't
finde the original sources anymore either).
Since at that time FPC was still in its infancy *g* I ported it for the
go32v1 target (a predecessor to the current go32v2) with the same name,
added a few things (most notably more accurate TSC support for Pentiums)
until it came to version 1.15 (this had been 8.11.'98...) - at that time I
decided to give it a little more flexible OO interface, the first
incarnation of the CPU unit was born (still FPC only, but with time
additional OS/2 + Linux support as I can see from history logs)....
Some time later (actually nearly exactly 4 years ago), at the time the cpu
vendors (AMD, Cyrix, Intel, ...) started to go in different directions
concerning CPU features, detection etc. so there had been a new instance of
my CPU unit with a different API + core that requires much less adaptions
for new processors / processor generations. This version still serves its
purpose and should work fine with current FPC releases.
Basically meaning that...
... there has never been an "official" CPU or Zentimer unit for TP/BP from
me (except probably very early non-public versions of the ZenTimer unit
which I don't have anymore)...
... but afair S. Goehler backported a some version of my CPU unit to TP/BP
for his Grafx-unit, can't remember which version (so use your favourite
search engine on these keywords :-)
More information about the fpc-pascal