4 * Copyright 1996 Alexandre Julliard
11 #include <sys/timeb.h>
12 #include <sys/types.h>
15 #include "wine/winbase16.h"
16 #include "wine/winuser16.h"
17 #include "selectors.h"
18 #include "sig_context.h"
24 SYSTEMTIMERPROC callback
; /* NULL if not in use */
29 #define NB_SYS_TIMERS 8
30 #define SYS_TIMER_RATE 54925
32 static SYSTEM_TIMER SYS_Timers
[NB_SYS_TIMERS
];
33 static int SYS_NbTimers
= 0;
34 static BOOL SYS_TimersDisabled
= FALSE
;
37 /***********************************************************************
40 static HANDLER_DEF(SYSTEM_TimerTick
)
45 for (i
= 0; i
< NB_SYS_TIMERS
; i
++)
47 if (!SYS_Timers
[i
].callback
) continue;
48 if ((SYS_Timers
[i
].ticks
-= SYS_TIMER_RATE
) <= 0)
50 SYS_Timers
[i
].ticks
+= SYS_Timers
[i
].rate
;
51 SYS_Timers
[i
].callback( i
+1 );
56 /**********************************************************************
59 * Start the system tick timer.
61 static void SYSTEM_StartTicks(void)
63 static BOOL handler_installed
= FALSE
;
65 if (!handler_installed
)
67 handler_installed
= TRUE
;
68 SIGNAL_SetHandler( SIGALRM
, SYSTEM_TimerTick
, 1 );
70 #ifndef __EMX__ /* FIXME: Time don't work... Use BIOS directly instead */
72 struct itimerval vt_timer
;
74 vt_timer
.it_interval
.tv_sec
= 0;
75 vt_timer
.it_interval
.tv_usec
= 54929;
76 vt_timer
.it_value
= vt_timer
.it_interval
;
77 setitimer( ITIMER_REAL
, &vt_timer
, NULL
);
83 /**********************************************************************
86 * Stop the system tick timer.
88 static void SYSTEM_StopTicks(void)
90 #ifndef __EMX__ /* FIXME: Time don't work... Use BIOS directly instead */
91 struct itimerval vt_timer
;
93 vt_timer
.it_interval
.tv_sec
= 0;
94 vt_timer
.it_interval
.tv_usec
= 0;
95 vt_timer
.it_value
= vt_timer
.it_interval
;
96 setitimer( ITIMER_REAL
, &vt_timer
, NULL
);
101 /***********************************************************************
102 * InquireSystem (SYSTEM.1)
104 * Note: the function always takes 2 WORD arguments, contrary to what
105 * "Undocumented Windows" says.
107 DWORD WINAPI
InquireSystem16( WORD code
, WORD arg
)
113 case 0: /* Get timer resolution */
114 return SYS_TIMER_RATE
;
116 case 1: /* Get drive type */
117 drivetype
= GetDriveType16( arg
);
118 return MAKELONG( drivetype
, drivetype
);
120 case 2: /* Enable one-drive logic */
121 FIXME(system
, "Case %d: set single-drive %d not supported\n", code
, arg
);
124 WARN(system
, "Unknown code %d\n", code
);
129 /***********************************************************************
130 * CreateSystemTimer (SYSTEM.2)
132 WORD WINAPI
CreateSystemTimer( WORD rate
, SYSTEMTIMERPROC callback
)
135 for (i
= 0; i
< NB_SYS_TIMERS
; i
++)
136 if (!SYS_Timers
[i
].callback
) /* Found one */
138 SYS_Timers
[i
].rate
= (UINT
)rate
* 1000;
139 if (SYS_Timers
[i
].rate
< SYS_TIMER_RATE
)
140 SYS_Timers
[i
].rate
= SYS_TIMER_RATE
;
141 SYS_Timers
[i
].ticks
= SYS_Timers
[i
].rate
;
142 SYS_Timers
[i
].callback
= callback
;
143 if ((++SYS_NbTimers
== 1) && !SYS_TimersDisabled
)
145 return i
+ 1; /* 0 means error */
151 /***********************************************************************
152 * KillSystemTimer (SYSTEM.3)
154 * Note: do not confuse this function with USER.182
156 WORD WINAPI
SYSTEM_KillSystemTimer( WORD timer
)
158 if (!timer
|| (timer
> NB_SYS_TIMERS
)) return timer
; /* Error */
159 SYS_Timers
[timer
-1].callback
= NULL
;
160 if ((!--SYS_NbTimers
) && !SYS_TimersDisabled
) SYSTEM_StopTicks();
165 /***********************************************************************
166 * EnableSystemTimers (SYSTEM.4)
168 void WINAPI
EnableSystemTimers16(void)
170 SYS_TimersDisabled
= FALSE
;
171 if (SYS_NbTimers
) SYSTEM_StartTicks();
175 /***********************************************************************
176 * DisableSystemTimers (SYSTEM.5)
178 void WINAPI
DisableSystemTimers16(void)
180 SYS_TimersDisabled
= TRUE
;
181 if (SYS_NbTimers
) SYSTEM_StopTicks();