include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / dlls / system.drv16 / system.c
blob0b95bbfb6faeb0da55ccb218ae86a7977aeb2d31
1 /*
2 * SYSTEM DLL routines
4 * Copyright 1996 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wine/winbase16.h"
26 #include "wine/winuser16.h"
27 #include "wownt32.h"
28 #include "winternl.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(system);
33 typedef struct
35 FARPROC16 callback16;
36 INT rate;
37 INT ticks;
38 } SYSTEM_TIMER;
40 #define NB_SYS_TIMERS 8
41 #define SYS_TIMER_RATE 54925
43 static SYSTEM_TIMER SYS_Timers[NB_SYS_TIMERS];
44 static int SYS_NbTimers = 0;
45 static HANDLE SYS_timer;
46 static HANDLE SYS_thread;
47 static BOOL SYS_timers_disabled;
50 /***********************************************************************
51 * SYSTEM_TimerTick
53 static void CALLBACK SYSTEM_TimerTick( LPVOID arg, DWORD low, DWORD high )
55 int i;
57 if (SYS_timers_disabled) return;
58 for (i = 0; i < NB_SYS_TIMERS; i++)
60 if (!SYS_Timers[i].callback16) continue;
61 if ((SYS_Timers[i].ticks -= SYS_TIMER_RATE) <= 0)
63 FARPROC16 proc = SYS_Timers[i].callback16;
64 CONTEXT context;
66 SYS_Timers[i].ticks += SYS_Timers[i].rate;
68 memset( &context, 0, sizeof(context) );
69 context.SegCs = SELECTOROF( proc );
70 context.Eip = OFFSETOF( proc );
71 context.Ebp = CURRENT_SP + FIELD_OFFSET(STACK16FRAME, bp);
72 context.Eax = i + 1;
74 WOWCallback16Ex( 0, WCB16_REGS, 0, NULL, (DWORD *)&context );
80 /***********************************************************************
81 * SYSTEM_TimerThread
83 static DWORD CALLBACK SYSTEM_TimerThread( void *dummy )
85 LARGE_INTEGER when;
87 if (!(SYS_timer = CreateWaitableTimerA( NULL, FALSE, NULL ))) return 0;
89 when.u.LowPart = when.u.HighPart = 0;
90 SetWaitableTimer( SYS_timer, &when, (SYS_TIMER_RATE+500)/1000, SYSTEM_TimerTick, 0, FALSE );
91 for (;;) SleepEx( INFINITE, TRUE );
95 /**********************************************************************
96 * SYSTEM_StartTicks
98 * Start the system tick timer.
100 static void SYSTEM_StartTicks(void)
102 if (!SYS_thread) SYS_thread = CreateThread( NULL, 0, SYSTEM_TimerThread, NULL, 0, NULL );
106 /**********************************************************************
107 * SYSTEM_StopTicks
109 * Stop the system tick timer.
111 static void SYSTEM_StopTicks(void)
113 if (SYS_thread)
115 CancelWaitableTimer( SYS_timer );
116 TerminateThread( SYS_thread, 0 );
117 CloseHandle( SYS_thread );
118 CloseHandle( SYS_timer );
119 SYS_thread = 0;
124 /***********************************************************************
125 * InquireSystem (SYSTEM.1)
127 * Note: the function always takes 2 WORD arguments, contrary to what
128 * "Undocumented Windows" says.
130 DWORD WINAPI InquireSystem16( WORD code, WORD arg )
132 WORD drivetype;
133 WCHAR root[3];
135 switch(code)
137 case 0: /* Get timer resolution */
138 return SYS_TIMER_RATE;
140 case 1: /* Get drive type */
141 root[0] = 'A' + arg;
142 root[1] = ':';
143 root[2] = 0;
144 drivetype = GetDriveTypeW( root );
145 if (drivetype == DRIVE_CDROM) drivetype = DRIVE_REMOTE;
146 else if (drivetype == DRIVE_NO_ROOT_DIR) drivetype = DRIVE_UNKNOWN;
147 return MAKELONG( drivetype, drivetype );
149 case 2: /* Enable one-drive logic */
150 FIXME("Case %d: set single-drive %d not supported\n", code, arg );
151 return 0;
153 WARN("Unknown code %d\n", code );
154 return 0;
158 /***********************************************************************
159 * CreateSystemTimer (SYSTEM.2)
161 WORD WINAPI CreateSystemTimer16( WORD rate, FARPROC16 proc )
163 int i;
164 for (i = 0; i < NB_SYS_TIMERS; i++)
165 if (!SYS_Timers[i].callback16) /* Found one */
167 SYS_Timers[i].rate = (UINT)rate * 1000;
168 if (SYS_Timers[i].rate < SYS_TIMER_RATE)
169 SYS_Timers[i].rate = SYS_TIMER_RATE;
170 SYS_Timers[i].ticks = SYS_Timers[i].rate;
171 SYS_Timers[i].callback16 = proc;
172 if (++SYS_NbTimers == 1) SYSTEM_StartTicks();
173 return i + 1; /* 0 means error */
175 return 0;
179 /***********************************************************************
180 * KillSystemTimer (SYSTEM.3)
182 * Note: do not confuse this function with USER.182
184 WORD WINAPI SYSTEM_KillSystemTimer( WORD timer )
186 if ( !timer || timer > NB_SYS_TIMERS || !SYS_Timers[timer-1].callback16 )
187 return timer; /* Error */
188 SYS_Timers[timer-1].callback16 = 0;
189 if (!--SYS_NbTimers) SYSTEM_StopTicks();
190 return 0;
194 /***********************************************************************
195 * EnableSystemTimers (SYSTEM.4)
197 void WINAPI EnableSystemTimers16(void)
199 SYS_timers_disabled = FALSE;
203 /***********************************************************************
204 * DisableSystemTimers (SYSTEM.5)
206 void WINAPI DisableSystemTimers16(void)
208 SYS_timers_disabled = TRUE;
212 /***********************************************************************
213 * GetSystemMSecCount (SYSTEM.6)
215 DWORD WINAPI GetSystemMSecCount16(void)
217 return GetTickCount();
221 /***********************************************************************
222 * Get80x87SaveSize (SYSTEM.7)
224 WORD WINAPI Get80x87SaveSize16(void)
226 return 94;
230 /***********************************************************************
231 * Save80x87State (SYSTEM.8)
233 void WINAPI Save80x87State16( char *ptr )
235 #ifdef __i386__
236 __asm__(".byte 0x66; fsave %0; fwait" : "=m" (ptr) );
237 #endif
241 /***********************************************************************
242 * Restore80x87State (SYSTEM.9)
244 void WINAPI Restore80x87State16( const char *ptr )
246 #ifdef __i386__
247 __asm__(".byte 0x66; frstor %0" : : "m" (ptr) );
248 #endif
252 /***********************************************************************
253 * A20_Proc (SYSTEM.20)
255 void WINAPI A20_Proc16( WORD unused )
257 /* this is also a NOP in Windows */