home *** CD-ROM | disk | FTP | other *** search
/ Megazine / Megazine-1.iso / PROGRAMA / C / ZTIMER23 / SRC / ZTIMER / ZTIMER.CPP < prev   
Encoding:
C/C++ Source or Header  |  1996-02-05  |  1.8 KB  |  77 lines

  1. /****************************************************************************
  2. *
  3. *                           The Zen Timer Library
  4. *
  5. *                               From the book
  6. *                         "Zen of Assembly Language"
  7. *                            Volume 1, Knowledge
  8. *
  9. *                             by Michael Abrash
  10. *
  11. *                      Modifications by Kendall Bennett
  12. *                   Copyright (C) 1993-4 SciTech Software
  13. *
  14. * Filename:        $Workfile:   ztimer.cpp  $
  15. * Version:        $Revision:   1.0  $
  16. *
  17. * Language:        C++ 2.1
  18. * Environment:    IBM PC (MS DOS)
  19. *
  20. * Description:    Non-inline member functions for the C++ class interface
  21. *                to the Zen Timer Library.
  22. *
  23. * $Date:   05 Feb 1996 14:50:22  $ $Author:   KendallB  $
  24. *
  25. ****************************************************************************/
  26.  
  27. #include <stdio.h>
  28. #include <iostream.h>
  29. #include "pmode.h"
  30. #include "ztimer.h"
  31.  
  32. /*----------------------------- Implementation ----------------------------*/
  33.  
  34. // Compute the time elapsed between calls to LZTimerOn() and LZTimerOff()
  35. // and add it to the current count.
  36.  
  37. void LZTimer::computeTime()
  38. {
  39.     if (!overflow()) {
  40.         ulong newcount = LZTimerCount();
  41.         if (newcount == 0xFFFFFFFFL)
  42.             _overflow = true;
  43.         else
  44.             _count += newcount;
  45.         }
  46. }
  47.  
  48. // Routine to stop the ultra long period timer. The timer resolution is low
  49. // enough to make this routine non-inline.
  50.  
  51. void ULZTimer::stop()
  52. {
  53.     _finish = ULZReadTime();
  54.     _count += ULZElapsedTime(_start,_finish);
  55. }
  56.  
  57. ostream& operator << (ostream& o,LZTimer& timer)
  58. {
  59.     char    buf[40];
  60.  
  61.     if (!timer.overflow()) {
  62.         sprintf(buf, "%.6f", timer.count() * timer.resolution());
  63.         o << buf;
  64.         }
  65.     else
  66.         o << "overflow";
  67.     return o;
  68. }
  69.  
  70. ostream& operator << (ostream& o,ULZTimer& timer)
  71. {
  72.     char    buf[40];
  73.  
  74.     sprintf(buf, "%.1f", timer.count() * timer.resolution());
  75.     return o << buf;
  76. }
  77.