1996-05-28 18:54:58 +00:00
|
|
|
/*
|
|
|
|
* SYSTEM DLL routines
|
|
|
|
*
|
|
|
|
* Copyright 1996 Alexandre Julliard
|
2002-03-09 23:29:33 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
1996-05-28 18:54:58 +00:00
|
|
|
*/
|
|
|
|
|
2003-01-07 20:36:20 +00:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
2003-09-05 23:08:26 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2000-02-10 19:03:02 +00:00
|
|
|
#include "windef.h"
|
2003-09-05 23:08:26 +00:00
|
|
|
#include "winbase.h"
|
2000-02-10 19:03:02 +00:00
|
|
|
#include "wingdi.h"
|
1999-02-19 10:37:02 +00:00
|
|
|
#include "wine/winbase16.h"
|
|
|
|
#include "wine/winuser16.h"
|
2003-08-23 23:30:51 +00:00
|
|
|
#include "wownt32.h"
|
2005-05-16 14:45:18 +00:00
|
|
|
#include "kernel_private.h"
|
2005-05-16 19:44:54 +00:00
|
|
|
#include "kernel16_private.h"
|
2002-03-09 23:29:33 +00:00
|
|
|
#include "wine/debug.h"
|
1997-08-04 16:34:36 +00:00
|
|
|
|
2002-03-09 23:29:33 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(system);
|
1999-04-19 14:56:29 +00:00
|
|
|
|
1997-08-04 16:34:36 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
1998-12-10 10:44:38 +00:00
|
|
|
SYSTEMTIMERPROC callback; /* NULL if not in use */
|
2001-12-17 22:13:31 +00:00
|
|
|
FARPROC16 callback16;
|
|
|
|
INT rate;
|
|
|
|
INT ticks;
|
1997-08-04 16:34:36 +00:00
|
|
|
} SYSTEM_TIMER;
|
1996-05-28 18:54:58 +00:00
|
|
|
|
1997-08-04 16:34:36 +00:00
|
|
|
#define NB_SYS_TIMERS 8
|
|
|
|
#define SYS_TIMER_RATE 54925
|
|
|
|
|
|
|
|
static SYSTEM_TIMER SYS_Timers[NB_SYS_TIMERS];
|
|
|
|
static int SYS_NbTimers = 0;
|
2002-03-23 18:48:53 +00:00
|
|
|
static HANDLE SYS_timer;
|
|
|
|
static HANDLE SYS_thread;
|
|
|
|
static int SYS_timers_disabled;
|
1998-12-10 10:44:38 +00:00
|
|
|
|
1996-05-28 18:54:58 +00:00
|
|
|
/***********************************************************************
|
1997-08-04 16:34:36 +00:00
|
|
|
* SYSTEM_TimerTick
|
|
|
|
*/
|
2002-03-23 18:48:53 +00:00
|
|
|
static void CALLBACK SYSTEM_TimerTick( LPVOID arg, DWORD low, DWORD high )
|
1997-08-04 16:34:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2002-03-23 18:48:53 +00:00
|
|
|
if (SYS_timers_disabled) return;
|
1997-08-04 16:34:36 +00:00
|
|
|
for (i = 0; i < NB_SYS_TIMERS; i++)
|
|
|
|
{
|
|
|
|
if (!SYS_Timers[i].callback) continue;
|
|
|
|
if ((SYS_Timers[i].ticks -= SYS_TIMER_RATE) <= 0)
|
|
|
|
{
|
|
|
|
SYS_Timers[i].ticks += SYS_Timers[i].rate;
|
1998-12-10 10:44:38 +00:00
|
|
|
SYS_Timers[i].callback( i+1 );
|
1997-08-04 16:34:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-23 18:48:53 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SYSTEM_TimerThread
|
|
|
|
*/
|
|
|
|
static DWORD CALLBACK SYSTEM_TimerThread( void *dummy )
|
|
|
|
{
|
|
|
|
LARGE_INTEGER when;
|
|
|
|
|
|
|
|
if (!(SYS_timer = CreateWaitableTimerA( NULL, FALSE, NULL ))) return 0;
|
|
|
|
|
2004-01-23 01:51:33 +00:00
|
|
|
when.u.LowPart = when.u.HighPart = 0;
|
2002-03-23 18:48:53 +00:00
|
|
|
SetWaitableTimer( SYS_timer, &when, (SYS_TIMER_RATE+500)/1000, SYSTEM_TimerTick, 0, FALSE );
|
2003-06-30 02:10:19 +00:00
|
|
|
for (;;) SleepEx( INFINITE, TRUE );
|
2002-03-23 18:48:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-08-04 16:34:36 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* SYSTEM_StartTicks
|
|
|
|
*
|
|
|
|
* Start the system tick timer.
|
1996-05-28 18:54:58 +00:00
|
|
|
*/
|
1997-08-04 16:34:36 +00:00
|
|
|
static void SYSTEM_StartTicks(void)
|
|
|
|
{
|
2002-03-23 18:48:53 +00:00
|
|
|
if (!SYS_thread) SYS_thread = CreateThread( NULL, 0, SYSTEM_TimerThread, NULL, 0, NULL );
|
1997-08-04 16:34:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SYSTEM_StopTicks
|
|
|
|
*
|
|
|
|
* Stop the system tick timer.
|
|
|
|
*/
|
|
|
|
static void SYSTEM_StopTicks(void)
|
|
|
|
{
|
2002-03-23 18:48:53 +00:00
|
|
|
if (SYS_thread)
|
1999-04-11 15:04:00 +00:00
|
|
|
{
|
2002-03-23 18:48:53 +00:00
|
|
|
CancelWaitableTimer( SYS_timer );
|
|
|
|
TerminateThread( SYS_thread, 0 );
|
|
|
|
CloseHandle( SYS_thread );
|
|
|
|
CloseHandle( SYS_timer );
|
|
|
|
SYS_thread = 0;
|
1999-04-11 15:04:00 +00:00
|
|
|
}
|
1997-08-04 16:34:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InquireSystem (SYSTEM.1)
|
|
|
|
*
|
|
|
|
* Note: the function always takes 2 WORD arguments, contrary to what
|
|
|
|
* "Undocumented Windows" says.
|
|
|
|
*/
|
1999-02-26 11:11:13 +00:00
|
|
|
DWORD WINAPI InquireSystem16( WORD code, WORD arg )
|
1996-05-28 18:54:58 +00:00
|
|
|
{
|
|
|
|
WORD drivetype;
|
|
|
|
|
|
|
|
switch(code)
|
|
|
|
{
|
|
|
|
case 0: /* Get timer resolution */
|
1997-08-04 16:34:36 +00:00
|
|
|
return SYS_TIMER_RATE;
|
1996-05-28 18:54:58 +00:00
|
|
|
|
|
|
|
case 1: /* Get drive type */
|
1997-08-04 16:34:36 +00:00
|
|
|
drivetype = GetDriveType16( arg );
|
1996-05-28 18:54:58 +00:00
|
|
|
return MAKELONG( drivetype, drivetype );
|
|
|
|
|
|
|
|
case 2: /* Enable one-drive logic */
|
1999-06-26 19:09:08 +00:00
|
|
|
FIXME("Case %d: set single-drive %d not supported\n", code, arg );
|
1996-05-28 18:54:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1999-06-26 19:09:08 +00:00
|
|
|
WARN("Unknown code %d\n", code );
|
1996-05-28 18:54:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1997-08-04 16:34:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateSystemTimer (SYSTEM.2)
|
|
|
|
*/
|
1998-12-10 10:44:38 +00:00
|
|
|
WORD WINAPI CreateSystemTimer( WORD rate, SYSTEMTIMERPROC callback )
|
1997-08-04 16:34:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < NB_SYS_TIMERS; i++)
|
|
|
|
if (!SYS_Timers[i].callback) /* Found one */
|
|
|
|
{
|
1999-02-26 11:11:13 +00:00
|
|
|
SYS_Timers[i].rate = (UINT)rate * 1000;
|
1997-08-04 16:34:36 +00:00
|
|
|
if (SYS_Timers[i].rate < SYS_TIMER_RATE)
|
|
|
|
SYS_Timers[i].rate = SYS_TIMER_RATE;
|
|
|
|
SYS_Timers[i].ticks = SYS_Timers[i].rate;
|
|
|
|
SYS_Timers[i].callback = callback;
|
1999-04-11 15:04:00 +00:00
|
|
|
if (++SYS_NbTimers == 1) SYSTEM_StartTicks();
|
1997-08-04 16:34:36 +00:00
|
|
|
return i + 1; /* 0 means error */
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-12-01 23:58:28 +00:00
|
|
|
/**********************************************************************/
|
|
|
|
|
2001-12-17 22:13:31 +00:00
|
|
|
static void call_timer_proc16( WORD timer )
|
1999-09-20 18:45:53 +00:00
|
|
|
{
|
|
|
|
CONTEXT86 context;
|
2001-12-17 22:13:31 +00:00
|
|
|
FARPROC16 proc = SYS_Timers[timer-1].callback16;
|
|
|
|
|
2003-11-05 00:46:44 +00:00
|
|
|
memset( &context, 0, sizeof(context) );
|
1999-09-20 18:45:53 +00:00
|
|
|
|
2003-11-05 00:46:44 +00:00
|
|
|
context.SegFs = wine_get_fs();
|
|
|
|
context.SegGs = wine_get_gs();
|
2000-09-25 23:53:07 +00:00
|
|
|
context.SegCs = SELECTOROF( proc );
|
|
|
|
context.Eip = OFFSETOF( proc );
|
2005-05-14 12:16:46 +00:00
|
|
|
context.Ebp = OFFSETOF(NtCurrentTeb()->WOW32Reserved) + (WORD)&((STACK16FRAME*)0)->bp;
|
2002-08-31 18:47:00 +00:00
|
|
|
context.Eax = timer;
|
1999-09-20 18:45:53 +00:00
|
|
|
|
2003-08-23 23:30:51 +00:00
|
|
|
WOWCallback16Ex( 0, WCB16_REGS, 0, NULL, (DWORD *)&context );
|
1999-09-20 18:45:53 +00:00
|
|
|
}
|
|
|
|
|
2000-12-01 23:58:28 +00:00
|
|
|
/**********************************************************************/
|
|
|
|
|
1999-09-20 18:45:53 +00:00
|
|
|
WORD WINAPI WIN16_CreateSystemTimer( WORD rate, FARPROC16 proc )
|
|
|
|
{
|
2001-12-17 22:13:31 +00:00
|
|
|
WORD ret = CreateSystemTimer( rate, call_timer_proc16 );
|
|
|
|
if (ret) SYS_Timers[ret - 1].callback16 = proc;
|
|
|
|
return ret;
|
1999-09-20 18:45:53 +00:00
|
|
|
}
|
|
|
|
|
1997-08-04 16:34:36 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* KillSystemTimer (SYSTEM.3)
|
|
|
|
*
|
|
|
|
* Note: do not confuse this function with USER.182
|
|
|
|
*/
|
1997-08-24 16:00:30 +00:00
|
|
|
WORD WINAPI SYSTEM_KillSystemTimer( WORD timer )
|
1997-08-04 16:34:36 +00:00
|
|
|
{
|
2002-05-31 23:06:46 +00:00
|
|
|
if ( !timer || timer > NB_SYS_TIMERS || !SYS_Timers[timer-1].callback )
|
1999-09-20 18:45:53 +00:00
|
|
|
return timer; /* Error */
|
1997-08-04 16:34:36 +00:00
|
|
|
SYS_Timers[timer-1].callback = NULL;
|
1999-04-11 15:04:00 +00:00
|
|
|
if (!--SYS_NbTimers) SYSTEM_StopTicks();
|
1997-08-04 16:34:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* EnableSystemTimers (SYSTEM.4)
|
|
|
|
*/
|
1999-02-26 11:11:13 +00:00
|
|
|
void WINAPI EnableSystemTimers16(void)
|
1997-08-04 16:34:36 +00:00
|
|
|
{
|
2002-03-23 18:48:53 +00:00
|
|
|
SYS_timers_disabled = 0;
|
1997-08-04 16:34:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DisableSystemTimers (SYSTEM.5)
|
|
|
|
*/
|
1999-02-26 11:11:13 +00:00
|
|
|
void WINAPI DisableSystemTimers16(void)
|
1997-08-04 16:34:36 +00:00
|
|
|
{
|
2002-03-23 18:48:53 +00:00
|
|
|
SYS_timers_disabled = 1;
|
1997-08-04 16:34:36 +00:00
|
|
|
}
|
1999-07-11 17:20:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 19:59:40 +00:00
|
|
|
* Get80x87SaveSize (SYSTEM.7)
|
1999-07-11 17:20:01 +00:00
|
|
|
*/
|
1999-07-31 17:32:05 +00:00
|
|
|
WORD WINAPI Get80x87SaveSize16(void)
|
1999-07-11 17:20:01 +00:00
|
|
|
{
|
|
|
|
return 94;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 19:59:40 +00:00
|
|
|
* Save80x87State (SYSTEM.8)
|
1999-07-11 17:20:01 +00:00
|
|
|
*/
|
1999-07-31 17:32:05 +00:00
|
|
|
void WINAPI Save80x87State16( char *ptr )
|
1999-07-11 17:20:01 +00:00
|
|
|
{
|
|
|
|
#ifdef __i386__
|
|
|
|
__asm__(".byte 0x66; fsave %0; fwait" : "=m" (ptr) );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 19:59:40 +00:00
|
|
|
* Restore80x87State (SYSTEM.9)
|
1999-07-11 17:20:01 +00:00
|
|
|
*/
|
1999-07-31 17:32:05 +00:00
|
|
|
void WINAPI Restore80x87State16( const char *ptr )
|
1999-07-11 17:20:01 +00:00
|
|
|
{
|
|
|
|
#ifdef __i386__
|
|
|
|
__asm__(".byte 0x66; frstor %0" : : "m" (ptr) );
|
|
|
|
#endif
|
|
|
|
}
|