-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtimer.c
More file actions
54 lines (45 loc) · 1.07 KB
/
timer.c
File metadata and controls
54 lines (45 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#if !defined(MSDOS)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/times.h>
long hz;
unsigned long Timer(void)
{
struct tms t;
clock_t clock;
clock=times(&t);
return((unsigned long)(clock*(1000.0/hz)));
}
void TimerInit(void)
{
hz=sysconf(_SC_CLK_TCK);
if(hz==0)
{
fprintf(stderr,"cannot get system clock frequency\n");
exit(1);
}
}
#else
#include <dos.h>
unsigned long Timer(void)
{
/* const unsigned long timer_freq=1193182UL;*/
unsigned long time;
union REGS r;
r.h.ah=0;
int86(0x1A,&r,&r);
time=((unsigned)r.w.dx+(((unsigned long)(unsigned)r.w.cx)<<16))*55UL;
/* disable();
outportb(0x43,0);
time=(unsigned long)(unsigned)inportb(0x40);
time+=(unsigned long)(unsigned)inportb(0x40)<<8;
time=(time*1000UL)/timer_freq;
time=((unsigned long)(unsigned)peek(0,0x46C)
+(((unsigned long)(unsigned)peek(0,0x46E))<<16))*55UL;
enable();*/
return(time);
}
void TimerInit(void) {}
#endif