Converted to the new debug interface, using script written by Patrik
[wine.git] / misc / system.c
blob14f73b91ebbcfeb423c8b466772b9d2422a6b6a3
1 /*
2 * SYSTEM DLL routines
4 * Copyright 1996 Alexandre Julliard
5 */
7 #include "wine/winbase16.h"
8 #include "wine/winuser16.h"
9 #include "services.h"
10 #include "debug.h"
12 DEFAULT_DEBUG_CHANNEL(system)
14 typedef struct
16 SYSTEMTIMERPROC callback; /* NULL if not in use */
17 INT rate;
18 INT ticks;
19 } SYSTEM_TIMER;
21 #define NB_SYS_TIMERS 8
22 #define SYS_TIMER_RATE 54925
24 static SYSTEM_TIMER SYS_Timers[NB_SYS_TIMERS];
25 static int SYS_NbTimers = 0;
26 static HANDLE SYS_Service = INVALID_HANDLE_VALUE;
29 /***********************************************************************
30 * SYSTEM_TimerTick
32 static void CALLBACK SYSTEM_TimerTick( ULONG_PTR arg )
34 int i;
36 for (i = 0; i < NB_SYS_TIMERS; i++)
38 if (!SYS_Timers[i].callback) continue;
39 if ((SYS_Timers[i].ticks -= SYS_TIMER_RATE) <= 0)
41 SYS_Timers[i].ticks += SYS_Timers[i].rate;
42 SYS_Timers[i].callback( i+1 );
47 /**********************************************************************
48 * SYSTEM_StartTicks
50 * Start the system tick timer.
52 static void SYSTEM_StartTicks(void)
54 if ( SYS_Service == INVALID_HANDLE_VALUE )
55 SYS_Service = SERVICE_AddTimer( SYS_TIMER_RATE, SYSTEM_TimerTick, 0L );
59 /**********************************************************************
60 * SYSTEM_StopTicks
62 * Stop the system tick timer.
64 static void SYSTEM_StopTicks(void)
66 if ( SYS_Service != INVALID_HANDLE_VALUE )
68 SERVICE_Delete( SYS_Service );
69 SYS_Service = INVALID_HANDLE_VALUE;
74 /***********************************************************************
75 * InquireSystem (SYSTEM.1)
77 * Note: the function always takes 2 WORD arguments, contrary to what
78 * "Undocumented Windows" says.
80 DWORD WINAPI InquireSystem16( WORD code, WORD arg )
82 WORD drivetype;
84 switch(code)
86 case 0: /* Get timer resolution */
87 return SYS_TIMER_RATE;
89 case 1: /* Get drive type */
90 drivetype = GetDriveType16( arg );
91 return MAKELONG( drivetype, drivetype );
93 case 2: /* Enable one-drive logic */
94 FIXME(system, "Case %d: set single-drive %d not supported\n", code, arg );
95 return 0;
97 WARN(system, "Unknown code %d\n", code );
98 return 0;
102 /***********************************************************************
103 * CreateSystemTimer (SYSTEM.2)
105 WORD WINAPI CreateSystemTimer( WORD rate, SYSTEMTIMERPROC callback )
107 int i;
108 for (i = 0; i < NB_SYS_TIMERS; i++)
109 if (!SYS_Timers[i].callback) /* Found one */
111 SYS_Timers[i].rate = (UINT)rate * 1000;
112 if (SYS_Timers[i].rate < SYS_TIMER_RATE)
113 SYS_Timers[i].rate = SYS_TIMER_RATE;
114 SYS_Timers[i].ticks = SYS_Timers[i].rate;
115 SYS_Timers[i].callback = callback;
116 if (++SYS_NbTimers == 1) SYSTEM_StartTicks();
117 return i + 1; /* 0 means error */
119 return 0;
123 /***********************************************************************
124 * KillSystemTimer (SYSTEM.3)
126 * Note: do not confuse this function with USER.182
128 WORD WINAPI SYSTEM_KillSystemTimer( WORD timer )
130 if (!timer || (timer > NB_SYS_TIMERS)) return timer; /* Error */
131 SYS_Timers[timer-1].callback = NULL;
132 if (!--SYS_NbTimers) SYSTEM_StopTicks();
133 return 0;
137 /***********************************************************************
138 * EnableSystemTimers (SYSTEM.4)
140 void WINAPI EnableSystemTimers16(void)
142 if ( SYS_Service != INVALID_HANDLE_VALUE )
143 SERVICE_Enable( SYS_Service );
147 /***********************************************************************
148 * DisableSystemTimers (SYSTEM.5)
150 void WINAPI DisableSystemTimers16(void)
152 if ( SYS_Service != INVALID_HANDLE_VALUE )
153 SERVICE_Disable( SYS_Service );