home *** CD-ROM | disk | FTP | other *** search
- /*
- Module name.
- resclock.c - display clock w/optional comand timer
-
- -) Functional description.
- This program will display a clock in the upper right corner
- of the screen and optionally accept a time and DOS command
- as an argument. At the specified time the command is passed
- to DOS and the ISR is terminated and freed from memory. The
- command length is limited to 15 characters, so batch files
- should be used to execute more complex command line
- requirments
-
- --) NOTICE: Copyright (C) 1990 South Mountain Software, Inc.
- */
- #include "tsr.h"
- #include "resproto.h"
- #include "stdio.h"
- #include "stdlib.h"
- #include "conio.h"
- #include "string.h"
- #include "process.h"
- #include "isr.h"
-
- #define TRUE 1
- #define FALSE 0
-
- #define ROW 0
- #define COL 65
- #define ATTR 0x70 /* black on white */
-
- /* int 16h unique function we use to see if loaded */
- unsigned int myfunc = 0x7272;
-
- /* address to total timmer tics since midnight */
- long far * systics = (long far *) 0x0000046CL;
-
- int hr,min,sec,hd;
- int schr, schm; /* scheduled time vars */
- int cmdsize;
- char cmd[129];
- unsigned char stop = 0;
-
- extern unsigned kb_in_progress; /* for use with kb_init */
- extern char *kb_str_ptr; /* for use with kb_init */
-
- void clock(void);
- void keystuff(char *str);
- void display(char *str);
- void isrpre(void);
- int tim_pars(char *str);
- void keystuff(char *key_str);
-
- void main(int argc,char **argv)
- {
- int add_arg; /* counter for command line arguments */
-
- /* process timed command request */
- if(argc > 2) {
- tim_pars(argv[1]); /* parse the time into schr & schm */
-
- add_arg = 2;
- while(argc-- > 2) { /* add all arguments to command line */
- strcat(cmd, argv[add_arg++]);
- strcat(cmd, " ");
- }
- }
-
- if (tsrloaded(myfunc) == FALSE)
- {
- isrpre();
- initisr(0x1c, clock, 50, myfunc, SIG, (void far *) NULL,1);
- }
- else
- {
- printf("RESCLOCK Already Loaded!\n");
- exit(1);
- }
- }
-
- void clock()
- {
- char curtime[15]; /* buffer to hold time */
- char temp_ptr[17]; /* temporary buffer for itoa() */
- static cnt; /* times thru int 1Ch */
- static unsigned long tmp; /* will hold tics since midnight */
-
- tmp = *systics; /* get tics since midnight */
-
- /* this formula converts tics since midnight */
- hr = (int) (tmp / 65543L);
- tmp %= 65543L;
- min = (int) (tmp / 1092);
- tmp %= 1092;
- sec = (int) (tmp * 100L / 1821L);
-
- /* we'll only update the clock display when sec changes */
- if(cnt != sec) {
- cnt = sec;
-
- /* cannot use sprintf because it was compiled with
- stack checking on. */
- /* sprintf(curtime," %2d:%2d:%2d ",hr,min,sec); */
-
- /* do it the hard way with itoa */
- curtime[0] = ' ';
- curtime[1] = '\0';
- itoa(hr,temp_ptr,10);
- if(strlen(temp_ptr) == 1) /* force two digits for each number */
- strcat(curtime,"0");
- strcat(curtime,temp_ptr);
- strcat(curtime,":");
- itoa(min,temp_ptr,10);
- if(strlen(temp_ptr) == 1) /* force two digits for each number */
- strcat(curtime,"0");
- strcat(curtime,temp_ptr);
- strcat(curtime,":");
- itoa(sec,temp_ptr,10);
- if(strlen(temp_ptr) == 1) /* force two digits for each number */
- strcat(curtime,"0");
- strcat(curtime,temp_ptr);
- strcat(curtime," ");
- display(curtime); /* put the time on the screen */
- }
-
- /* process command if one was requested */
- if (!stop)
- if(cmdsize && hr == schr && min == schm)
- {
- if (freeisr() == 1) /* free ISR when done */
- {
- stop = 1;
- return; /* return to DOS to execute */
- }
- else
- {
- /* The following technique limits keyboard
- stuffing to 15 characters (the size of the
- keyboard buffer) so that the TSR can free
- itself before executing the command. The kb_init()
- function cannot be used here because this ISR
- is servicing a hardware interrupt and kb_init()
- does a DOS call to replace the timer interrupt vector.
- Instead it calls keystuff() below which physically
- stuffs the characters in the BIOS data area.
- */
- keystuff(cmd);
- return; /* return to DOS to execute */
- }
- }
- }
-
- /* Interleave atribute and display time */
- void display(str)
- char *str;
- {
- register char *curptr; /* used to steo thru buffer */
- char buf[31]; /* actual buffer to write to screen */
-
-
- curptr = buf;
-
- /* merge char and attribute for screen format */
- while(*str) {
- *curptr++ = *str++;
- *curptr++ = ATTR;
- }
-
- /* do the actual display */
- memtoscr(10, (ROW * 160) + (COL * 2), buf);
- return;
- }
-
- /*
- This function takes the time in HH:MM format and places it into
- two int variables for hour and minute.
- */
- int tim_pars(str)
- char *str;
- {
- char *ptr; /* used to step thru str */
-
- for(ptr = str; *ptr != ':' && *ptr; ptr++);
-
- if(*ptr == NULL) /* no : was found, invalid time */
- return(-1);
-
- *ptr++ = '\0'; /* split hour and point to minute */
- schr = atoi(str);
- schm = atoi(ptr);
-
- return(0);
- }
-
- void isrpre() /* simulates tsrpre() to keep this and resclok2.c similar */
- {
- printf("\nRESCLOCK By South Mountain Software\n\n");
- if((cmdsize = strlen(cmd)) > 0) /* verify command and time */
- {
- if(cmdsize <= 14) /* cmd includes trailing blank here */
- {
- printf("At %02d:%02d Execute %s\n", schr, schm, cmd);
- cmd[cmdsize] = '\0'; /* delete last blank */
- strcat(cmd, "\r\n"); /* cause return at end of command */
- cmdsize += 1;
- }
- else
- {
- putch(7);
- printf("Command length exceeds max of 13 characters!\n");
- printf("Try using a batch file to work around this.\n");
- }
- }
- }
-
-
- /* keystuff.c - stuff characters into the keyboard buffer */
-
- /* this function clears the keyboard buffer and stuffs a */
- /* string of up to 15 chars into the kybd buffer */
-
- void keystuff(char *str)
- {
- int i = 0;
- char far *pokechar;
-
- pokechar = (char far *) 0x0000041eL; /* address of BIOS keyboard buffer */
-
- while(*str){
- *pokechar++ = *str++; /* poke ascii code into buffer */
- *pokechar++ = 1; /* poke 1 - will not handle function keys */
- i+=2; /* i points to next ascii position */
- }
- pokechar = (char far *) 0x0000041a;
- *pokechar = 0x1e; /* point buffer head to start */
- pokechar = (char far *) 0x0000041c; /* point tail to end */
- *pokechar = 0x1e + i;
-
- }