home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / thx / source / theatrix / timesrvr.cpp < prev    next >
C/C++ Source or Header  |  1995-04-26  |  1KB  |  46 lines

  1. #include <iostream.h>
  2. #include <dos.h>
  3. #include "theatrix.h"
  4.  
  5.  
  6. const int CLOCKVECT = 0x1C;
  7.  
  8. static void interrupt newhandler(...);     // our replacement handler
  9. static void interrupt (*oldhandler)(...);  // ptr to default handler
  10. int TimerServer::newtick;                  // declare static data member
  11.  
  12. void TimerServer::startup()
  13.   {
  14.   tickno=0;
  15.   newtick=FALSE;
  16.   oldhandler=getvect(CLOCKVECT);
  17.   setvect(CLOCKVECT,newhandler);
  18.   cout << "TIMERSERVER: hooked timer interrupt...\n";
  19.   }
  20.  
  21. void TimerServer::shutdown()
  22.   {
  23.   if (oldhandler)
  24.     {
  25.     setvect(CLOCKVECT,oldhandler);
  26.     cout << "TIMERSERVER: restored timer interrupt...\n";
  27.     oldhandler = 0;
  28.     }
  29.   }
  30.  
  31. void TimerServer::check(Folder& fld)
  32.   {
  33.   if (newtick)
  34.     {
  35.     tickno=++tickno%18;
  36.     fld.dispatch(tickno);
  37.     newtick=FALSE;
  38.     }
  39.   }
  40.  
  41. void interrupt newhandler(...)
  42.   {
  43.   TimerServer::newtick=TRUE;
  44.   oldhandler(...);                    // * it is vital than the default
  45.   }                                   //   handler get called
  46.