4 * Copyright 1996 Alexandre Julliard
12 #include <sys/timeb.h>
13 #include <sys/types.h>
22 FARPROC16 callback
; /* NULL if not in use */
27 #define NB_SYS_TIMERS 8
28 #define SYS_TIMER_RATE 54925
30 static SYSTEM_TIMER SYS_Timers
[NB_SYS_TIMERS
];
31 static int SYS_NbTimers
= 0;
32 static BOOL32 SYS_TimersDisabled
= FALSE
;
34 /***********************************************************************
37 static void SYSTEM_TimerTick(void)
41 for (i
= 0; i
< NB_SYS_TIMERS
; i
++)
43 if (!SYS_Timers
[i
].callback
) continue;
44 if ((SYS_Timers
[i
].ticks
-= SYS_TIMER_RATE
) <= 0)
46 SYS_Timers
[i
].ticks
+= SYS_Timers
[i
].rate
;
47 Callbacks
->CallSystemTimerProc( SYS_Timers
[i
].callback
);
53 /**********************************************************************
56 * Start the system tick timer.
58 static void SYSTEM_StartTicks(void)
60 static BOOL32 handler_installed
= FALSE
;
62 if (!handler_installed
)
64 handler_installed
= TRUE
;
65 SIGNAL_SetHandler( SIGALRM
, SYSTEM_TimerTick
, 1 );
67 #ifndef __EMX__ /* FIXME: Time don't work... Use BIOS directly instead */
69 struct itimerval vt_timer
;
71 vt_timer
.it_interval
.tv_sec
= 0;
72 vt_timer
.it_interval
.tv_usec
= 54929;
73 vt_timer
.it_value
= vt_timer
.it_interval
;
74 setitimer( ITIMER_REAL
, &vt_timer
, NULL
);
80 /**********************************************************************
83 * Stop the system tick timer.
85 static void SYSTEM_StopTicks(void)
87 #ifndef __EMX__ /* FIXME: Time don't work... Use BIOS directly instead */
88 struct itimerval vt_timer
;
90 vt_timer
.it_interval
.tv_sec
= 0;
91 vt_timer
.it_interval
.tv_usec
= 0;
92 vt_timer
.it_value
= vt_timer
.it_interval
;
93 setitimer( ITIMER_REAL
, &vt_timer
, NULL
);
98 /***********************************************************************
99 * InquireSystem (SYSTEM.1)
101 * Note: the function always takes 2 WORD arguments, contrary to what
102 * "Undocumented Windows" says.
104 DWORD WINAPI
InquireSystem( WORD code
, WORD arg
)
110 case 0: /* Get timer resolution */
111 return SYS_TIMER_RATE
;
113 case 1: /* Get drive type */
114 drivetype
= GetDriveType16( arg
);
115 return MAKELONG( drivetype
, drivetype
);
117 case 2: /* Enable one-drive logic */
118 fprintf( stderr
, "InquireSystem(2): set single-drive %d not supported\n", arg
);
121 fprintf( stderr
, "InquireSystem: unknown code %d\n", code
);
126 /***********************************************************************
127 * CreateSystemTimer (SYSTEM.2)
129 WORD WINAPI
CreateSystemTimer( WORD rate
, FARPROC16 callback
)
133 for (i
= 0; i
< NB_SYS_TIMERS
; i
++)
134 if (!SYS_Timers
[i
].callback
) /* Found one */
136 SYS_Timers
[i
].rate
= (UINT32
)rate
* 1000;
137 if (SYS_Timers
[i
].rate
< SYS_TIMER_RATE
)
138 SYS_Timers
[i
].rate
= SYS_TIMER_RATE
;
139 SYS_Timers
[i
].ticks
= SYS_Timers
[i
].rate
;
140 SYS_Timers
[i
].callback
= callback
;
141 if ((++SYS_NbTimers
== 1) && !SYS_TimersDisabled
)
143 return i
+ 1; /* 0 means error */
149 /***********************************************************************
150 * KillSystemTimer (SYSTEM.3)
152 * Note: do not confuse this function with USER.182
154 WORD WINAPI
SYSTEM_KillSystemTimer( WORD timer
)
156 if (!timer
|| (timer
> NB_SYS_TIMERS
)) return timer
; /* Error */
157 SYS_Timers
[timer
-1].callback
= NULL
;
158 if ((!--SYS_NbTimers
) && !SYS_TimersDisabled
) SYSTEM_StopTicks();
163 /***********************************************************************
164 * EnableSystemTimers (SYSTEM.4)
166 void WINAPI
EnableSystemTimers(void)
168 SYS_TimersDisabled
= FALSE
;
169 if (SYS_NbTimers
) SYSTEM_StartTicks();
173 /***********************************************************************
174 * DisableSystemTimers (SYSTEM.5)
176 void WINAPI
DisableSystemTimers(void)
178 SYS_TimersDisabled
= TRUE
;
179 if (SYS_NbTimers
) SYSTEM_StopTicks();