Release 980503
[wine/multimedia.git] / misc / system.c
blob99fbcfb4c24405cc6c5263ce8561a79a842d2d10
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 "callback.h"
17 #include "windows.h"
18 #include "miscemu.h"
19 #include "debug.h"
21 typedef struct
23 FARPROC16 callback; /* NULL if not in use */
24 INT32 rate;
25 INT32 ticks;
26 } SYSTEM_TIMER;
28 #define NB_SYS_TIMERS 8
29 #define SYS_TIMER_RATE 54925
31 static SYSTEM_TIMER SYS_Timers[NB_SYS_TIMERS];
32 static int SYS_NbTimers = 0;
33 static BOOL32 SYS_TimersDisabled = FALSE;
35 /***********************************************************************
36 * SYSTEM_TimerTick
38 static void SYSTEM_TimerTick(void)
40 int i;
42 for (i = 0; i < NB_SYS_TIMERS; i++)
44 if (!SYS_Timers[i].callback) continue;
45 if ((SYS_Timers[i].ticks -= SYS_TIMER_RATE) <= 0)
47 SYS_Timers[i].ticks += SYS_Timers[i].rate;
48 Callbacks->CallSystemTimerProc( SYS_Timers[i].callback );
54 /**********************************************************************
55 * SYSTEM_StartTicks
57 * Start the system tick timer.
59 static void SYSTEM_StartTicks(void)
61 static BOOL32 handler_installed = FALSE;
63 if (!handler_installed)
65 handler_installed = TRUE;
66 SIGNAL_SetHandler( SIGALRM, SYSTEM_TimerTick, 1 );
68 #ifndef __EMX__ /* FIXME: Time don't work... Use BIOS directly instead */
70 struct itimerval vt_timer;
72 vt_timer.it_interval.tv_sec = 0;
73 vt_timer.it_interval.tv_usec = 54929;
74 vt_timer.it_value = vt_timer.it_interval;
75 setitimer( ITIMER_REAL, &vt_timer, NULL );
77 #endif
81 /**********************************************************************
82 * SYSTEM_StopTicks
84 * Stop the system tick timer.
86 static void SYSTEM_StopTicks(void)
88 #ifndef __EMX__ /* FIXME: Time don't work... Use BIOS directly instead */
89 struct itimerval vt_timer;
91 vt_timer.it_interval.tv_sec = 0;
92 vt_timer.it_interval.tv_usec = 0;
93 vt_timer.it_value = vt_timer.it_interval;
94 setitimer( ITIMER_REAL, &vt_timer, NULL );
95 #endif
99 /***********************************************************************
100 * InquireSystem (SYSTEM.1)
102 * Note: the function always takes 2 WORD arguments, contrary to what
103 * "Undocumented Windows" says.
105 DWORD WINAPI InquireSystem( WORD code, WORD arg )
107 WORD drivetype;
109 switch(code)
111 case 0: /* Get timer resolution */
112 return SYS_TIMER_RATE;
114 case 1: /* Get drive type */
115 drivetype = GetDriveType16( arg );
116 return MAKELONG( drivetype, drivetype );
118 case 2: /* Enable one-drive logic */
119 FIXME(system, "Case %d: set single-drive %d not supported\n", code, arg );
120 return 0;
122 WARN(system, "Unknown code %d\n", code );
123 return 0;
127 /***********************************************************************
128 * CreateSystemTimer (SYSTEM.2)
130 WORD WINAPI CreateSystemTimer( WORD rate, FARPROC16 callback )
132 int i;
134 for (i = 0; i < NB_SYS_TIMERS; i++)
135 if (!SYS_Timers[i].callback) /* Found one */
137 SYS_Timers[i].rate = (UINT32)rate * 1000;
138 if (SYS_Timers[i].rate < SYS_TIMER_RATE)
139 SYS_Timers[i].rate = SYS_TIMER_RATE;
140 SYS_Timers[i].ticks = SYS_Timers[i].rate;
141 SYS_Timers[i].callback = callback;
142 if ((++SYS_NbTimers == 1) && !SYS_TimersDisabled)
143 SYSTEM_StartTicks();
144 return i + 1; /* 0 means error */
146 return 0;
150 /***********************************************************************
151 * KillSystemTimer (SYSTEM.3)
153 * Note: do not confuse this function with USER.182
155 WORD WINAPI SYSTEM_KillSystemTimer( WORD timer )
157 if (!timer || (timer > NB_SYS_TIMERS)) return timer; /* Error */
158 SYS_Timers[timer-1].callback = NULL;
159 if ((!--SYS_NbTimers) && !SYS_TimersDisabled) SYSTEM_StopTicks();
160 return 0;
164 /***********************************************************************
165 * EnableSystemTimers (SYSTEM.4)
167 void WINAPI EnableSystemTimers(void)
169 SYS_TimersDisabled = FALSE;
170 if (SYS_NbTimers) SYSTEM_StartTicks();
174 /***********************************************************************
175 * DisableSystemTimers (SYSTEM.5)
177 void WINAPI DisableSystemTimers(void)
179 SYS_TimersDisabled = TRUE;
180 if (SYS_NbTimers) SYSTEM_StopTicks();