4 * Copyright 1996 Alexandre Julliard
7 #include "wine/winbase16.h"
8 #include "wine/winuser16.h"
14 SYSTEMTIMERPROC callback; /* NULL if not in use */
19 #define NB_SYS_TIMERS 8
20 #define SYS_TIMER_RATE 54925
22 static SYSTEM_TIMER SYS_Timers[NB_SYS_TIMERS];
23 static int SYS_NbTimers = 0;
24 static HANDLE SYS_Service = INVALID_HANDLE_VALUE;
27 /***********************************************************************
30 static void CALLBACK SYSTEM_TimerTick( ULONG_PTR arg )
34 for (i = 0; i < NB_SYS_TIMERS; i++)
36 if (!SYS_Timers[i].callback) continue;
37 if ((SYS_Timers[i].ticks -= SYS_TIMER_RATE) <= 0)
39 SYS_Timers[i].ticks += SYS_Timers[i].rate;
40 SYS_Timers[i].callback( i+1 );
45 /**********************************************************************
48 * Start the system tick timer.
50 static void SYSTEM_StartTicks(void)
52 if ( SYS_Service == INVALID_HANDLE_VALUE )
53 SYS_Service = SERVICE_AddTimer( SYS_TIMER_RATE, SYSTEM_TimerTick, 0L );
57 /**********************************************************************
60 * Stop the system tick timer.
62 static void SYSTEM_StopTicks(void)
64 if ( SYS_Service != INVALID_HANDLE_VALUE )
66 SERVICE_Delete( SYS_Service );
67 SYS_Service = INVALID_HANDLE_VALUE;
72 /***********************************************************************
73 * InquireSystem (SYSTEM.1)
75 * Note: the function always takes 2 WORD arguments, contrary to what
76 * "Undocumented Windows" says.
78 DWORD WINAPI InquireSystem16( WORD code, WORD arg )
84 case 0: /* Get timer resolution */
85 return SYS_TIMER_RATE;
87 case 1: /* Get drive type */
88 drivetype = GetDriveType16( arg );
89 return MAKELONG( drivetype, drivetype );
91 case 2: /* Enable one-drive logic */
92 FIXME(system, "Case %d: set single-drive %d not supported\n", code, arg );
95 WARN(system, "Unknown code %d\n", code );
100 /***********************************************************************
101 * CreateSystemTimer (SYSTEM.2)
103 WORD WINAPI CreateSystemTimer( WORD rate, SYSTEMTIMERPROC callback )
106 for (i = 0; i < NB_SYS_TIMERS; i++)
107 if (!SYS_Timers[i].callback) /* Found one */
109 SYS_Timers[i].rate = (UINT)rate * 1000;
110 if (SYS_Timers[i].rate < SYS_TIMER_RATE)
111 SYS_Timers[i].rate = SYS_TIMER_RATE;
112 SYS_Timers[i].ticks = SYS_Timers[i].rate;
113 SYS_Timers[i].callback = callback;
114 if (++SYS_NbTimers == 1) SYSTEM_StartTicks();
115 return i + 1; /* 0 means error */
121 /***********************************************************************
122 * KillSystemTimer (SYSTEM.3)
124 * Note: do not confuse this function with USER.182
126 WORD WINAPI SYSTEM_KillSystemTimer( WORD timer )
128 if (!timer || (timer > NB_SYS_TIMERS)) return timer; /* Error */
129 SYS_Timers[timer-1].callback = NULL;
130 if (!--SYS_NbTimers) SYSTEM_StopTicks();
135 /***********************************************************************
136 * EnableSystemTimers (SYSTEM.4)
138 void WINAPI EnableSystemTimers16(void)
140 if ( SYS_Service != INVALID_HANDLE_VALUE )
141 SERVICE_Enable( SYS_Service );
145 /***********************************************************************
146 * DisableSystemTimers (SYSTEM.5)
148 void WINAPI DisableSystemTimers16(void)
150 if ( SYS_Service != INVALID_HANDLE_VALUE )
151 SERVICE_Disable( SYS_Service );