home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / COMM / MISC / SRC26_2.ZIP / SRC / SAVERPC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-13  |  2.8 KB  |  149 lines

  1. /*
  2.  * saverPC.c: hterm CRT saver for IBM-PC
  3.  *
  4.  * Author: HIRANO Satoshi
  5.  * (C) 1989  Halca Computer Science Laboratory TM
  6.  *           University of Tokyo
  7.  *
  8.  * 1.1 89/06/20 Halca.Hirano creation; null functions
  9.  * 1.2 89/07/20 Halca.Hirano add kermit timer
  10.  *     ----- V2.3.-1 distributin ----
  11.  * 1.3 89/09/17 Halca.Hirano add special saver attachment mechanism
  12.  *    ---- V2.4.0 distribution ----
  13.  * 1.4 89/12/03 Halca.Hirano
  14.  *    add BS key watcher timer
  15.  *
  16.  * $Header: saverpc.cv  1.9  90/07/03 22:59:24  hirano  Exp $
  17.  */
  18.  
  19.  
  20. #include "option.h"
  21. #include <stdio.h>
  22. #include "config.h"
  23. #include "hterm.h"
  24. #include "default.h"
  25. #include "global.h"
  26.  
  27. /*
  28.  * saver type description
  29.  *
  30.  * TO ADD YOUR SAVER:
  31.  *    0) make source.c
  32.  *    1) add extern void FAR newSaver() to next line
  33.  *    2) add saverInfo in savers[]
  34.  *    3) add source.c in makefile
  35.  */
  36. static void FAR blankSaver();
  37.  
  38. struct saverInfo {
  39.     char *name;
  40.     void (FAR *saverFunc)();
  41. };
  42.  
  43. struct saverInfo savers[] = {
  44.     {" Blank Saver ", blankSaver},
  45.     /* Insert your saver here. */
  46. };
  47.  
  48. void (interrupt FAR *oldVect)();
  49.  
  50. static void FAR INTERRUPT timerHandler(void );
  51. static void timerInit(void );
  52.  
  53.  
  54. void saverInit()
  55. {
  56.     saver = DEFAULT_CRT_SAVER;
  57.     maxSaverType = sizeof(savers)/sizeof(savers[0]) - 1;
  58.     saverType = DEFAULT_SAVER_TYPE;    /* maybe blank saver        */
  59.     oldVect = 0;
  60.     saverReInit();
  61. }
  62.  
  63. void saverReInit()
  64. {
  65.     setTimerValue();        /* set timerLoadValue non zero    */
  66.     timerInit();            /* iniz timer interrupt        */
  67. }
  68.  
  69. static void interrupt FAR timerHandler()
  70. {
  71.     /*
  72.      * 54.95 msec timer (18.2 ticks/sec)
  73.      */
  74.     --timerValue;
  75.     --kermitTimer;
  76.     --portTimer;
  77.     --bsKeyWatcherTimer;
  78.     --blinkTimer;
  79. }
  80.  
  81. static void timerInit()
  82. {
  83.     oldVect = GET_DOSVECT(TIMER_VECT);
  84.     SET_DOSVECT(TIMER_VECT, timerHandler);
  85. }
  86.  
  87. void saverSetup()
  88. {
  89.     setTimerValue();
  90.     if (saverType > maxSaverType)
  91.         saverType = 0;
  92. }
  93.  
  94. void saverEnd()
  95. {
  96.     timerLoadValue = 0;
  97.     if (oldVect)
  98.         SET_DOSVECT(TIMER_VECT, oldVect);
  99.     oldVect = 0;
  100. }
  101.  
  102. char *saverName(n)
  103. int n;
  104. {
  105.     return(savers[n].name);
  106. }
  107.  
  108. void setTimerValue()
  109. {
  110.     switch (saver) {
  111.     case CRT_SAVER_3: 
  112.         timerLoadValue = 3 * 60 * 18;     /* 3 min */
  113.         break;
  114.     case CRT_SAVER_OFF:
  115.     case CRT_SAVER_10:
  116.     default: 
  117.         timerLoadValue = 10 * 60 * 18; /* 10 min */ 
  118.         break;
  119.     }
  120.      bsKeyWatcherTimer = BS_WATCHER_SAMPLING_TIME*TICK_SEC;
  121. }
  122.  
  123. void CRTSaver()
  124. {
  125.     if (saverType > maxSaverType)
  126.         saverType = 0;
  127.     savePage(page0Save);
  128.     textCRTOnOff(NO);        /* erase text CRT    */
  129.     cursorOnOff(NO);
  130.     /*
  131.      * call saver
  132.      */
  133.     (*savers[saverType].saverFunc)();
  134.     restorePage(page0Save);
  135.     timerValue = timerLoadValue;
  136.     textCRTOnOff(YES);
  137.     cursorOnOff(cursor);
  138. }
  139.  
  140. static void FAR blankSaver()
  141. /*
  142.  * keep screen blank
  143.  */
  144. {
  145.     while (checkEvent() == 0) {
  146.         ;
  147.     }
  148. }
  149.