home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / tsr / mixtsr / clock.c next >
Encoding:
C/C++ Source or Header  |  1988-06-16  |  3.7 KB  |  152 lines

  1. /* ----- clock ----- */
  2.  
  3. #include <dos.h>
  4. #include <stdio.h>
  5. #include <conio.h
  6. #include <bios.h>
  7. #include <time.h>
  8. #include "tsr.h"
  9. #define ROW 5
  10. #define COL 30
  11. #define WID 24
  12. #define HIGH 1
  13. #define vad(x,y) ((y)*160+(x)*2)
  14.  
  15. /* --------- modify for the specific TSR ----------- */
  16. unsigned scancode = 52;   /* . */       /* hot key scan code */
  17. unsigned keymask = 8;     /* Alt */     /* hot key status mask */
  18. char signature[]="CLOCK";               /* tsr signature */
  19.  
  20. static int VSG;
  21.  
  22. void Msg_start(void);
  23. void Msg_resid(void);
  24. void Msg_restr(void);
  25. static void Msg_instr(void);
  26.  
  27. void gettext(int,int,int,int,char *);
  28. void puttext(int,int,int,int,char *);
  29.  
  30.  
  31. void popup()
  32. {
  33.    static int c;
  34.    static int sv[WID*HIGH*2];
  35.    static char addr[10];
  36.    static unsigned v,ch,kh,x1;
  37.    static char *tm;
  38.    static long tim,tim2;
  39.    extern int terminating,suspending;
  40.    static int col=COL,row=ROW;
  41.    int done;
  42.  
  43.    if (peekb(0,0x44a)!=80 || (peekb(0,0x449)!=2 && peekb(0,0x449)!=3))
  44.        return;
  45.  
  46.    if ((biosequip()&0x30)==0x30) VSG=0XB000;else VSG=0XB800;
  47.    done=0;
  48.    while (!done) {
  49.       gettext(col,row,col+WID-1,row+HIGH-1,sv);
  50.       kh=keyhit();
  51.       while (!kh) {
  52.          time(&tim);
  53.          if (tim!=tim2) {
  54.             tim2=tim;
  55.             tm=ctime(&tim);
  56.             for (v=0;v<WID;v++){
  57.                ch=*(tm+v)|0x7000;
  58.                puttext(col+v,row,col+v,row,&ch);
  59.             }
  60.          }
  61.          kh=keyhit();
  62.       }
  63.       puttext(col,row,col+WID-1,row+HIGH-1,sv);
  64.       tim2=0;
  65.       c=get_char();
  66.       if (c>127) {
  67.          int sh;
  68.          sh=peekb(0,0x417)&0x03;
  69.          c=c-128;
  70.          switch (c){
  71.             case 72: /* up */
  72.                if (row>0) row--;                if (sh) row=0;
  73.                break;
  74.             case 75: /* left */
  75.                if (col>0) col--;                if (sh) col=0;
  76.                break;
  77.             case 80: /* down */
  78.                if (row<25-HIGH) row++;          if (sh) row=25-HIGH;
  79.                break;
  80.             case 77: /* right */
  81.                if (col<80-WID) col++;           if (sh) col=80-WID;
  82.                break;
  83.             default:
  84.                c=1;
  85.                done=1;
  86.          }
  87.       }
  88.       else done=1;
  89.    }
  90.    terminating=(c=='u'||c=='U');
  91.    suspending=(c=='s'||c=='S');
  92. }
  93.  
  94. void gettext(int cs,int rs,int ce,int re,int *sv)
  95. {
  96.     int *ptr;
  97.     int cp,rp;
  98.  
  99.     ptr=sv;
  100.  
  101.     for (cp=cs; cp<=ce; cp++)
  102.         for (rp=rs; rp<=re; rp++) {
  103.            *ptr=vpeek(VSG,vad(cp,rp));ptr++;
  104.         }
  105. }
  106.  
  107. void puttext(int cs,int rs,int ce,int re,int *sv)
  108. {
  109.     int *ptr;
  110.     int cp,rp;
  111.     int chr,atr;
  112.  
  113.     ptr=sv;
  114.  
  115.     for (cp=cs; cp<=ce; cp++)
  116.         for (rp=rs; rp<=re; rp++) {
  117.            vpoke(VSG,vad(cp,rp),*ptr);ptr++;
  118.         }
  119. }
  120.  
  121.  
  122. void openfiles(){}
  123. void closefiles(){}
  124.  
  125. void Msg_start(void)
  126. {
  127.    printf("\nMemory Resident Clock is loaded...\n\n");
  128.    Msg_instr();
  129. }
  130. void Msg_resid(void)
  131. {
  132.    printf("\nMemory Resident Clock is already resident.\n\n");
  133.    Msg_instr();
  134. }
  135. void Msg_restr(void)
  136. {
  137.    printf("\nMemory Resident Clock is restarted.\n\n");
  138.    Msg_instr();
  139. }
  140. void Msg_instr()
  141. {
  142.    printf("  * Invoke the clock at any time with < Alt . >\n\n");
  143.    printf("  * Once invoked, the following apply:\n");
  144.    printf("      U key - unloads the clock\n");
  145.    printf("      S key - suspends the clock\n");
  146.    printf("      Cursor keys & shift key - moves the clock\n");
  147.    printf("            on the screen to where you want it.\n");
  148.    printf("      Any other key puts the clock away.\n\n");
  149.    printf("  * To unsuspend the clock, rerun the \n");
  150.    printf("    disk copy of the program.\n\n");
  151. }
  152.