1996-05-28 18:54:58 +00:00
|
|
|
/*
|
|
|
|
* SYSTEM DLL routines
|
|
|
|
*
|
|
|
|
* Copyright 1996 Alexandre Julliard
|
|
|
|
*/
|
|
|
|
|
1999-02-19 10:37:02 +00:00
|
|
|
#include "wine/winbase16.h"
|
|
|
|
#include "wine/winuser16.h"
|
1999-04-11 15:04:00 +00:00
|
|
|
#include "services.h"
|
1999-06-26 19:09:08 +00:00
|
|
|
#include "debugtools.h"
|
1997-08-04 16:34:36 +00:00
|
|
|
|
1999-04-19 14:56:29 +00:00
|
|
|
DEFAULT_DEBUG_CHANNEL(system)
|
|
|
|
|
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 */
|
1999-02-26 11:11:13 +00:00
|
|
|
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;
|
1999-04-11 15:04:00 +00:00
|
|
|
static HANDLE SYS_Service = INVALID_HANDLE_VALUE;
|
1996-05-28 18:54:58 +00:00
|
|
|
|
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
|
|
|
|
*/
|
1999-04-11 15:04:00 +00:00
|
|
|
static void CALLBACK SYSTEM_TimerTick( ULONG_PTR arg )
|
1997-08-04 16:34:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* 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)
|
|
|
|
{
|
1999-04-11 15:04:00 +00:00
|
|
|
if ( SYS_Service == INVALID_HANDLE_VALUE )
|
|
|
|
SYS_Service = SERVICE_AddTimer( SYS_TIMER_RATE, SYSTEM_TimerTick, 0L );
|
1997-08-04 16:34:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SYSTEM_StopTicks
|
|
|
|
*
|
|
|
|
* Stop the system tick timer.
|
|
|
|
*/
|
|
|
|
static void SYSTEM_StopTicks(void)
|
|
|
|
{
|
1999-04-11 15:04:00 +00:00
|
|
|
if ( SYS_Service != INVALID_HANDLE_VALUE )
|
|
|
|
{
|
|
|
|
SERVICE_Delete( SYS_Service );
|
|
|
|
SYS_Service = INVALID_HANDLE_VALUE;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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
|
|
|
{
|
|
|
|
if (!timer || (timer > NB_SYS_TIMERS)) return timer; /* Error */
|
|
|
|
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
|
|
|
{
|
1999-04-11 15:04:00 +00:00
|
|
|
if ( SYS_Service != INVALID_HANDLE_VALUE )
|
|
|
|
SERVICE_Enable( SYS_Service );
|
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
|
|
|
{
|
1999-04-11 15:04:00 +00:00
|
|
|
if ( SYS_Service != INVALID_HANDLE_VALUE )
|
|
|
|
SERVICE_Disable( SYS_Service );
|
1997-08-04 16:34:36 +00:00
|
|
|
}
|
1999-07-11 17:20:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Get80x87SaveSize16 (SYSTEM.7)
|
|
|
|
*/
|
1999-07-31 17:32:05 +00:00
|
|
|
WORD WINAPI Get80x87SaveSize16(void)
|
1999-07-11 17:20:01 +00:00
|
|
|
{
|
|
|
|
return 94;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Save80x87State16 (SYSTEM.8)
|
|
|
|
*/
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Restore80x87State16 (SYSTEM.9)
|
|
|
|
*/
|
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
|
|
|
|
}
|
|
|
|
|