📄 cmttimer.c
字号:
#include <dos.h>
#include "cmtlib.h"
static unsigned long far *biosticker=(unsigned long *)0x0040006cl;
/* ----------------------------------------------------------------
** Timer.
** ----------------------------------------------------------------
*/
/*man**************************************************************
NAME
cmt_tsart - starts a timer
SYNOPSIS
#include "cmtlib.h"
void far cdecl cmt_tstart(CMT_TIMER far *t,unsigned long ticks)
DESCRIPTION
this function starts a timer countdown on the given
timer for given number of 55 ms clock ticks.
******************************************************************/
void far cdecl cmt_tstart(CMT_TIMER far *t,unsigned long ticks)
{
if (t) {
t->length=ticks;
disable();
t->start=*biosticker;
enable();
t->end=t->start+ticks;
}
}
/*man**************************************************************
NAME
cmt_texpired - check if the timer has expired
SYNOPSIS
#include "cmtlib.h"
int far cdecl cmt_texpired(CMT_TIMER far *t)
DESCRIPTION
this function check if the given timer has expired.
DIAGNOSTICS
returns 1 if the timer has expired, 0 if it is not.
******************************************************************/
int far cdecl cmt_texpired(CMT_TIMER far *t)
{
unsigned long tick;
if (t) {
disable();
tick=*biosticker;
enable();
if (t->end<t->start) {
tick+=t->start;
if (tick<t->start && tick>t->end)
return 1;
}
else {
if (tick>t->end || tick<t->start)
return 1;
}
}
return 0;
}
/*man**************************************************************
NAME
cmt_expire - force timer to expire
SYNOPSIS
#include "cmtlib.h"
void far cdecl cmt_expire(CMT_TIMER far *t)
DESCRIPTION
this function immidiately expires the given timer.
******************************************************************/
void far cdecl cmt_expire(CMT_TIMER far *t)
{
t->end=t->start;
t->length=0;
}
/*man**************************************************************
NAME
cmt_sleep - blocks a task for given number of seconds
SYNOPSIS
#include "cmtlib.h"
void far cdecl cmt_sleep(unsigned int seconds)
DESCRIPTION
this is a sleep function it goes into loop giving away
the calling task's timeslice and waiting for a given
number of seconds to pass by.
if number of seconds is 0, cmt_sleep equals to cmt_pause
******************************************************************/
void far cdecl cmt_sleep(unsigned int seconds)
{
CMT_TIMER t;
if (!seconds)
cmt_pause();
else {
cmt_tstart(&t,(unsigned long)seconds*18L+(seconds/5));
while (!cmt_texpired(&t))
cmt_pause();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -