home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / DSPCLOCK.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  3KB  |  88 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /* public domain TSR clock code. By Michelangelo Jones, 1:141/575 or
  4. // 1:1/124. Very little support available; this is a quick hack, not
  5. // an example of the best way to write a clock TSR! Use at own risk.
  6. // Runs under TC++/BC++. Your mileage may vary.
  7. */
  8.  
  9. #ifndef __HUGE__
  10. #error "Must be compiled using HUGE model-- for now"
  11. #endif
  12.  
  13. #include <dos.h>
  14.  
  15. extern unsigned _heaplen = 0;
  16. extern unsigned _stklen = 512;
  17.  
  18. static char * screenbase =
  19.            (char *)                  MK_FP (0xb800, 0); /* change for mono */
  20. static const long int * volatile ticks =                /* to 0xb000, 0 */
  21.            (long int * volatile)     MK_FP (0, 0x046c);
  22.  
  23. int calls, lastsec, lastmin, lasthr;
  24. const double tps = 18.20648;          /* found by experimentation! */
  25.  
  26. void interrupt (*oldhandler)(void);
  27.  
  28. void displayclock (void)
  29. {
  30.     char *moveinto = screenbase + 300;
  31.     char *initwith = "      :     :       ";
  32.  
  33. /* NOTE: This initializer only works because the attribute I want for the
  34. //       clock HAPPENS to be the same as the ASCII value for the SPACE char!
  35. //       Modify every alternate character if you want some other attribute.
  36. */
  37.  
  38.     while (*initwith)
  39.         *moveinto++ = *initwith++;
  40.     lastsec = -1;
  41.     lastmin = -1;
  42.     lasthr  = -1;
  43.     calls   = 20;
  44. }
  45.  
  46. void interrupt clockproc(void)
  47. {
  48.     static long seconds;
  49.  
  50.     if (calls < 17)
  51.         calls++;
  52.     else
  53.     {
  54.         seconds = (long) ((double) *ticks / tps);
  55.         if (screenbase[301] != ' ') /* if the attribute has changed, */
  56.             displayclock();         /* the screen scrolled, so update. */
  57.         if (seconds % 60 != lastsec)
  58.         {
  59.             lastsec = seconds % 60;
  60.             calls = 0;
  61.             screenbase[314] = (char) (lastsec/10) + 48;
  62.             screenbase[316] = (char) (lastsec%10) + 48;
  63.             if ((! lastsec) || (lastmin < 0))
  64.             {
  65.                 lastmin = (seconds % 3600) / 60;
  66.                 screenbase[308] = (char) (lastmin/10) + 48;
  67.                 screenbase[310] = (char) (lastmin%10) + 48;
  68.                 if ((! lastmin) || (lasthr < 0))
  69.                 {
  70.                     lasthr = ((seconds % 86400L) / 3600L);
  71.                     screenbase[302] = (char) (lasthr/10) + 48;
  72.                     screenbase[304] = (char) (lasthr%10) + 48;
  73.                 }
  74.             }
  75.         }
  76.     }
  77.     oldhandler ();
  78. }
  79.  
  80. main()
  81. {
  82.     oldhandler = getvect (0x1c);
  83.     displayclock();
  84.     setvect (0x1c, clockproc);
  85.     keep (0, (_SS + (_SP/16) - _psp));
  86.     return 0;
  87. }
  88.