home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / MODEM / UWPC201.ZIP / UW-SRC.ZIP / TIMER.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-11  |  3.2 KB  |  116 lines

  1. //-------------------------------------------------------------------------
  2. //
  3. // TIMER.CPP - Timer declarations for UW/PC.
  4. // 
  5. //  This file is part of UW/PC - a multi-window comms package for the PC.
  6. //  Copyright (C) 1990-1991  Rhys Weatherley
  7. //
  8. //  This program is free software; you can redistribute it and/or modify
  9. //  it under the terms of the GNU General Public License as published by
  10. //  the Free Software Foundation; either version 1, or (at your option)
  11. //  any later version.
  12. //
  13. //  This program is distributed in the hope that it will be useful,
  14. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. //  GNU General Public License for more details.
  17. //
  18. //  You should have received a copy of the GNU General Public License
  19. //  along with this program; if not, write to the Free Software
  20. //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. //
  22. // Revision History:
  23. // ================
  24. //
  25. //  Version  DD/MM/YY  By  Description
  26. //  -------  --------  --  --------------------------------------
  27. //    1.0    07/04/91  RW  Original Version of TIMER.CPP
  28. //
  29. // You may contact the author by:
  30. // =============================
  31. //
  32. //  e-mail: rhys@cs.uq.oz.au
  33. //    mail: Rhys Weatherley
  34. //          5 Horizon Drive
  35. //          Jamboree Heights
  36. //          Queensland 4074
  37. //        Australia
  38. //
  39. //-------------------------------------------------------------------------
  40.  
  41. #include "timer.h"        // Declarations for this module.
  42. #include <dos.h>        // DOS/BIOS manipulation routines.
  43.  
  44. //
  45. // Define various system timer values for UW/PC.
  46. //
  47. int    CurrentTime;    // Current 24-hour time in minutes.
  48. int    OnlineTime;    // Time in minutes since logon (mod 6000).
  49. int    TimerCount;    // Incremented every 18.2th of a second.
  50.  
  51. //
  52. // Global data needed for this module.
  53. //
  54. static    void    interrupt (far *saveint) (...);
  55. static    int    OnlineOffset;
  56.  
  57. //
  58. // Define the number of system ticks per minute.  The actual
  59. // value is 1092.266666, but this is close enough for UW/PC.
  60. //
  61. #define    TICKS_PER_MINUTE    1092
  62.  
  63. //
  64. // Get the current time from the BIOS data area.
  65. //
  66. #define    SYSTEM_TIME    (*((long far *)0x46C))
  67.  
  68. //
  69. // Convert a system time to a number of minutes.
  70. //
  71. #define    TO_MINUTES(x)    ((x) / TICKS_PER_MINUTE)
  72.  
  73. // Interrupt routine to intercept system timer ticks.
  74. static    void    interrupt TimerInt (...)
  75. {
  76.   (*saveint) ();        // Call old timer routine.
  77.   enable ();            // Enable interrupts.
  78.   ++TimerCount;
  79.   CurrentTime = TO_MINUTES (SYSTEM_TIME) % 1440;
  80.   ++OnlineOffset;
  81.   if (OnlineOffset > TICKS_PER_MINUTE)
  82.     {
  83.       OnlineTime = (OnlineTime + 1) % 6000;
  84.       OnlineOffset = 0;
  85.     }
  86. } // TimerInt //
  87.  
  88. //
  89. // Initialise the system timer routines.
  90. //
  91. void    InitTimers (void)
  92. {
  93.   saveint = getvect (0x1C);
  94.   setvect (0x1C,TimerInt);
  95.   CurrentTime = TO_MINUTES (SYSTEM_TIME) % 1440;
  96.   TimerCount = 0;
  97.   ResetOnline ();
  98. } // InitTimers //
  99.  
  100. //
  101. // Terminate the system timer routines.
  102. //
  103. void    TermTimers (void)
  104. {
  105.   setvect (0x1C,saveint);
  106. } // TermTimers //
  107.  
  108. //
  109. // Reset the current online time to zero.
  110. //
  111. void    ResetOnline (void)
  112. {
  113.   OnlineTime = 0;
  114.   OnlineOffset = 0;
  115. } // ResetOnline //
  116.