Release 971012
[wine/multimedia.git] / misc / system.c
blob1c34729709344a2e1d005a02a8b20fa60fa65976
1 /*
2 * SYSTEM DLL routines
4 * Copyright 1996 Alexandre Julliard
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <signal.h>
10 #include <time.h>
11 #include <sys/time.h>
12 #include <sys/timeb.h>
13 #include <sys/types.h>
14 #include <sys/wait.h>
16 #include "windows.h"
17 #include "miscemu.h"
19 typedef struct
21 FARPROC16 callback; /* NULL if not in use */
22 INT32 rate;
23 INT32 ticks;
24 } SYSTEM_TIMER;
26 #define NB_SYS_TIMERS 8
27 #define SYS_TIMER_RATE 54925
29 static SYSTEM_TIMER SYS_Timers[NB_SYS_TIMERS];
30 static int SYS_NbTimers = 0;
31 static BOOL32 SYS_TimersDisabled = FALSE;
33 /***********************************************************************
34 * SYSTEM_TimerTick
36 static void SYSTEM_TimerTick(void)
38 int i;
40 for (i = 0; i < NB_SYS_TIMERS; i++)
42 if (!SYS_Timers[i].callback) continue;
43 if ((SYS_Timers[i].ticks -= SYS_TIMER_RATE) <= 0)
45 SYS_Timers[i].ticks += SYS_Timers[i].rate;
46 SYS_Timers[i].callback();
52 /**********************************************************************
53 * SYSTEM_StartTicks
55 * Start the system tick timer.
57 static void SYSTEM_StartTicks(void)
59 static BOOL32 handler_installed = FALSE;
61 if (!handler_installed)
63 handler_installed = TRUE;
64 SIGNAL_SetHandler( SIGALRM, SYSTEM_TimerTick, 1 );
66 #ifndef __EMX__ /* FIXME: Time don't work... Use BIOS directly instead */
68 struct itimerval vt_timer;
70 vt_timer.it_interval.tv_sec = 0;
71 vt_timer.it_interval.tv_usec = 54929;
72 vt_timer.it_value = vt_timer.it_interval;
73 setitimer( ITIMER_REAL, &vt_timer, NULL );
75 #endif
79 /**********************************************************************
80 * SYSTEM_StopTicks
82 * Stop the system tick timer.
84 static void SYSTEM_StopTicks(void)
86 #ifndef __EMX__ /* FIXME: Time don't work... Use BIOS directly instead */
87 struct itimerval vt_timer;
89 vt_timer.it_interval.tv_sec = 0;
90 vt_timer.it_interval.tv_usec = 0;
91 vt_timer.it_value = vt_timer.it_interval;
92 setitimer( ITIMER_REAL, &vt_timer, NULL );
93 #endif
97 /***********************************************************************
98 * InquireSystem (SYSTEM.1)
100 * Note: the function always takes 2 WORD arguments, contrary to what
101 * "Undocumented Windows" says.
103 DWORD WINAPI InquireSystem( WORD code, WORD arg )
105 WORD drivetype;
107 switch(code)
109 case 0: /* Get timer resolution */
110 return SYS_TIMER_RATE;
112 case 1: /* Get drive type */
113 drivetype = GetDriveType16( arg );
114 return MAKELONG( drivetype, drivetype );
116 case 2: /* Enable one-drive logic */
117 fprintf( stderr, "InquireSystem(2): set single-drive %d not supported\n", arg );
118 return 0;
120 fprintf( stderr, "InquireSystem: unknown code %d\n", code );
121 return 0;
125 /***********************************************************************
126 * CreateSystemTimer (SYSTEM.2)
128 WORD WINAPI CreateSystemTimer( WORD rate, FARPROC16 callback )
130 int i;
132 for (i = 0; i < NB_SYS_TIMERS; i++)
133 if (!SYS_Timers[i].callback) /* Found one */
135 SYS_Timers[i].rate = (UINT32)rate * 1000;
136 if (SYS_Timers[i].rate < SYS_TIMER_RATE)
137 SYS_Timers[i].rate = SYS_TIMER_RATE;
138 SYS_Timers[i].ticks = SYS_Timers[i].rate;
139 SYS_Timers[i].callback = callback;
140 if ((++SYS_NbTimers == 1) && !SYS_TimersDisabled)
141 SYSTEM_StartTicks();
142 return i + 1; /* 0 means error */
144 return 0;
148 /***********************************************************************
149 * KillSystemTimer (SYSTEM.3)
151 * Note: do not confuse this function with USER.182
153 WORD WINAPI SYSTEM_KillSystemTimer( WORD timer )
155 if (!timer || (timer > NB_SYS_TIMERS)) return timer; /* Error */
156 SYS_Timers[timer-1].callback = NULL;
157 if ((!--SYS_NbTimers) && !SYS_TimersDisabled) SYSTEM_StopTicks();
158 return 0;
162 /***********************************************************************
163 * EnableSystemTimers (SYSTEM.4)
165 void WINAPI EnableSystemTimers(void)
167 SYS_TimersDisabled = FALSE;
168 if (SYS_NbTimers) SYSTEM_StartTicks();
172 /***********************************************************************
173 * DisableSystemTimers (SYSTEM.5)
175 void WINAPI DisableSystemTimers(void)
177 SYS_TimersDisabled = TRUE;
178 if (SYS_NbTimers) SYSTEM_StopTicks();
182 /***********************************************************************
183 * SYSTEM_GetTimerProc
185 * Return the timer proc of a system timer. Used by thunking code.
187 FARPROC16 SYSTEM_GetTimerProc( WORD timer )
189 if (!timer || (timer > NB_SYS_TIMERS)) return NULL;
190 return SYS_Timers[timer-1].callback;