Changed initial process creation to avoid memory allocations.
[wine/multimedia.git] / misc / system.c
blob227a0f4da6cc4da89c7be9f63fc57caa70c2ddd5
1 /*
2 * SYSTEM DLL routines
4 * Copyright 1996 Alexandre Julliard
5 */
7 #include <stdlib.h>
8 #include <signal.h>
9 #include <time.h>
10 #include <sys/time.h>
11 #include <sys/timeb.h>
12 #include <sys/types.h>
13 #include <sys/wait.h>
15 #include "wine/winbase16.h"
16 #include "wine/winuser16.h"
17 #include "selectors.h"
18 #include "sig_context.h"
19 #include "miscemu.h"
20 #include "debug.h"
22 typedef struct
24 SYSTEMTIMERPROC callback; /* NULL if not in use */
25 INT32 rate;
26 INT32 ticks;
27 } SYSTEM_TIMER;
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 BOOL32 SYS_TimersDisabled = FALSE;
37 /***********************************************************************
38 * SYSTEM_TimerTick
40 static HANDLER_DEF(SYSTEM_TimerTick)
42 int i;
43 HANDLER_INIT();
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 /**********************************************************************
57 * SYSTEM_StartTicks
59 * Start the system tick timer.
61 static void SYSTEM_StartTicks(void)
63 static BOOL32 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 );
79 #endif
83 /**********************************************************************
84 * SYSTEM_StopTicks
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 );
97 #endif
101 /***********************************************************************
102 * InquireSystem (SYSTEM.1)
104 * Note: the function always takes 2 WORD arguments, contrary to what
105 * "Undocumented Windows" says.
107 DWORD WINAPI InquireSystem( WORD code, WORD arg )
109 WORD drivetype;
111 switch(code)
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 );
122 return 0;
124 WARN(system, "Unknown code %d\n", code );
125 return 0;
129 /***********************************************************************
130 * CreateSystemTimer (SYSTEM.2)
132 WORD WINAPI CreateSystemTimer( WORD rate, SYSTEMTIMERPROC callback )
134 int i;
135 for (i = 0; i < NB_SYS_TIMERS; i++)
136 if (!SYS_Timers[i].callback) /* Found one */
138 SYS_Timers[i].rate = (UINT32)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)
144 SYSTEM_StartTicks();
145 return i + 1; /* 0 means error */
147 return 0;
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();
161 return 0;
165 /***********************************************************************
166 * EnableSystemTimers (SYSTEM.4)
168 void WINAPI EnableSystemTimers(void)
170 SYS_TimersDisabled = FALSE;
171 if (SYS_NbTimers) SYSTEM_StartTicks();
175 /***********************************************************************
176 * DisableSystemTimers (SYSTEM.5)
178 void WINAPI DisableSystemTimers(void)
180 SYS_TimersDisabled = TRUE;
181 if (SYS_NbTimers) SYSTEM_StopTicks();