home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
BTMTSRC3.ZIP
/
TIMER.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-01
|
8KB
|
256 lines
/*--------------------------------------------------------------------------*/
/* */
/* */
/* ------------ Bit-Bucket Software, Co. */
/* \ 10001101 / Writers and Distributors of */
/* \ 011110 / Freely Available<tm> Software. */
/* \ 1011 / */
/* ------ */
/* */
/* (C) Copyright 1987-90, Bit Bucket Software Co., a Delaware Corporation. */
/* */
/* */
/* This module was written by Bob Hartman */
/* with some hacking done by Vince Perriello */
/* */
/* */
/* BinkleyTerm timer routines */
/* */
/* */
/* For complete details of the licensing restrictions, please refer */
/* to the License agreement, which is published in its entirety in */
/* the MAKEFILE and BT.C, and also contained in the file LICENSE.240. */
/* */
/* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
/* BINKLEYTERM LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
/* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
/* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT BIT BUCKET */
/* SOFTWARE CO. AT ONE OF THE ADDRESSES LISTED BELOW. IN NO EVENT */
/* SHOULD YOU PROCEED TO USE THIS FILE WITHOUT HAVING ACCEPTED THE */
/* TERMS OF THE BINKLEYTERM LICENSING AGREEMENT, OR SUCH OTHER */
/* AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO. */
/* */
/* */
/* You can contact Bit Bucket Software Co. at any one of the following */
/* addresses: */
/* */
/* Bit Bucket Software Co. FidoNet 1:104/501, 1:132/491, 1:141/491 */
/* P.O. Box 460398 AlterNet 7:491/0 */
/* Aurora, CO 80046 BBS-Net 86:2030/1 */
/* Internet f491.n132.z1.fidonet.org */
/* */
/* Please feel free to contact us at any time to share your comments about */
/* our software and/or licensing policies. */
/* */
/*--------------------------------------------------------------------------*/
/*
This file contains routines to implement a simple multiple
alarm system. The routines allow setting any number of alarms,
and then checking if any one of them has expired. It also allows
adding time to an alarm.
*/
/*
* $Log: H:/binkley/vcs/timer.c_v $
**
** Rev 1.0 01 Sep 1991 14:34:30 cml
** Changes made on Binkley:
**
** - Bent the timing rules slightly for Wazoo initiation.
** - Changed ALL async routines.
** - Removed ESC as a shell.
*/
#include <stdio.h>
#ifdef OS_2
#define INCL_DOSDATETIME
#define INCL_DOSPROCESS
#include <os2.h>
#include <process.h>
#endif
#include "com.h"
#include "xfer.h"
#include "zmodem.h"
#include "keybd.h"
#include "sbuf.h"
#include "sched.h"
#include "externs.h"
#include "prototyp.h"
#include "timer.h"
#ifdef OS_2
/* CML saving excess cpu cycles calling the OS! Start a separate thread! */
#define TIMER_STACKSIZE 2048
TID timer_tid;
int timer_stack[TIMER_STACKSIZE / sizeof(int)];
long update_sem = 0L;
long timer_sem = 0L;
DATETIME curtime; /* CML */
void far timer_thread(void *dummy)
{
DosSetPrty(PRTYS_THREAD,PRTYC_FOREGROUNDSERVER,PRTYD_MAXIMUM,timer_tid);
while (1)
{
DosSemRequest(&update_sem,SEM_INDEFINITE_WAIT);
DosGetDateTime(&curtime);
DosSemClear(&update_sem);
DosSleep(5L); /* sleep */
}
}
int start_timer(void)
{
DosSemClear(&timer_sem);
if ((timer_tid = _beginthread(timer_thread,timer_stack,TIMER_STACKSIZE,NULL)) == -1)
return 0;
return 1;
}
void hold_timer(void)
{
DosSemRequest(&timer_sem,SEM_INDEFINITE_WAIT);
}
void restart_timer(void)
{
DosSemClear(&timer_sem);
}
/* End of code by CML */
#endif
/*
long timerset (t)
unsigned int t;
This routine returns a timer variable based on the MS-DOS
time. The variable returned is a long which corresponds to
the MS-DOS time at which the timer will expire. The variable
need never be used once set, but to find if the timer has in
fact expired, it will be necessary to call the timeup function.
The expire time 't' is in hundredths of a second.
Note: This routine as coded had a granularity of one week. I
have put the code that implements that inside the flag
"HIGH_OVERHEAD". If you want it, go ahead and use it. For
BT's purposes, (minute) granularity should suffice.
*/
long pascal timerset (t)
unsigned int t;
{
long l;
#ifdef HIGH_OVERHEAD
int l2;
#endif
int hours, mins, secs, ths;
#ifdef HIGH_OVERHEAD
extern int week_day ();
#endif
#ifndef OS_2
/* Get the DOS time and day of week */
dostime (&hours, &mins, &secs, &ths);
#else
DosSemRequest(&update_sem,SEM_INDEFINITE_WAIT);
hours = curtime.hours; /* CML added this time to save repeated calls to OS */
mins = curtime.minutes;
secs = curtime.seconds;
ths = curtime.hundredths;
DosSemClear(&update_sem);
#endif
#ifdef HIGH_OVERHEAD
l2 = week_day ();
#endif
/* Figure out the hundredths of a second so far this week */
l =
#ifdef HIGH_OVERHEAD
l2 * PER_DAY +
(hours % 24) * PER_HOUR +
#endif
(mins % 60) * PER_MINUTE +
(secs % 60) * PER_SECOND +
ths;
/* Add in the timer value */
l += t;
/* Return the alarm off time */
return (l);
}
/*
int timeup (t)
long t;
This routine returns a 1 if the passed timer variable corresponds
to a timer which has expired, or 0 otherwise.
*/
int pascal timeup (t)
long t;
{
long l;
/* Get current time in hundredths */
l = timerset (0);
/* If current is less then set by more than max int, then adjust */
if (l < (t - 65536L))
{
#ifdef HIGH_OVERHEAD
l += PER_WEEK;
#else
l += PER_HOUR;
#endif
}
/* Return whether the current is greater than the timer variable */
return ((l - t) >= 0L);
}
/*
long addtime (t1, t2)
long t1;
unsigned int t2;
This routine adds t2 hundredths of a second to the timer variable
in t1. It returns a new timer variable.
Not needed in BinkleyTerm, commented out.
long addtime (t1, t2)
long t1;
unsigned int t2;
{
return (t1 + t2);
}
*/