1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
|
/*
* SYSTEM DLL routines
*
* Copyright 1996 Alexandre Julliard
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "wine/winbase16.h"
#include "wine/winuser16.h"
#include "wownt32.h"
#include "winternl.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(system);
typedef struct
{
SYSTEMTIMERPROC callback; /* NULL if not in use */
FARPROC16 callback16;
INT rate;
INT ticks;
} SYSTEM_TIMER;
#define NB_SYS_TIMERS 8
#define SYS_TIMER_RATE 54925
static SYSTEM_TIMER SYS_Timers[NB_SYS_TIMERS];
static int SYS_NbTimers = 0;
static HANDLE SYS_timer;
static HANDLE SYS_thread;
static int SYS_timers_disabled;
/***********************************************************************
* SYSTEM_TimerTick
*/
static void CALLBACK SYSTEM_TimerTick( LPVOID arg, DWORD low, DWORD high )
{
int i;
if (SYS_timers_disabled) return;
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;
SYS_Timers[i].callback( i+1 );
}
}
}
/***********************************************************************
* SYSTEM_TimerThread
*/
static DWORD CALLBACK SYSTEM_TimerThread( void *dummy )
{
LARGE_INTEGER when;
if (!(SYS_timer = CreateWaitableTimerA( NULL, FALSE, NULL ))) return 0;
when.u.LowPart = when.u.HighPart = 0;
SetWaitableTimer( SYS_timer, &when, (SYS_TIMER_RATE+500)/1000, SYSTEM_TimerTick, 0, FALSE );
for (;;) SleepEx( INFINITE, TRUE );
}
/**********************************************************************
* SYSTEM_StartTicks
*
* Start the system tick timer.
*/
static void SYSTEM_StartTicks(void)
{
if (!SYS_thread) SYS_thread = CreateThread( NULL, 0, SYSTEM_TimerThread, NULL, 0, NULL );
}
/**********************************************************************
* SYSTEM_StopTicks
*
* Stop the system tick timer.
*/
static void SYSTEM_StopTicks(void)
{
if (SYS_thread)
{
CancelWaitableTimer( SYS_timer );
TerminateThread( SYS_thread, 0 );
CloseHandle( SYS_thread );
CloseHandle( SYS_timer );
SYS_thread = 0;
}
}
/***********************************************************************
* InquireSystem (SYSTEM.1)
*
* Note: the function always takes 2 WORD arguments, contrary to what
* "Undocumented Windows" says.
*/
DWORD WINAPI InquireSystem16( WORD code, WORD arg )
{
WORD drivetype;
switch(code)
{
case 0: /* Get timer resolution */
return SYS_TIMER_RATE;
case 1: /* Get drive type */
drivetype = GetDriveType16( arg );
return MAKELONG( drivetype, drivetype );
case 2: /* Enable one-drive logic */
FIXME("Case %d: set single-drive %d not supported\n", code, arg );
return 0;
}
WARN("Unknown code %d\n", code );
return 0;
}
/***********************************************************************
* CreateSystemTimer (SYSTEM.2)
*/
WORD WINAPI CreateSystemTimer( WORD rate, SYSTEMTIMERPROC callback )
{
int i;
for (i = 0; i < NB_SYS_TIMERS; i++)
if (!SYS_Timers[i].callback) /* Found one */
{
SYS_Timers[i].rate = (UINT)rate * 1000;
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;
if (++SYS_NbTimers == 1) SYSTEM_StartTicks();
return i + 1; /* 0 means error */
}
return 0;
}
/**********************************************************************/
static void call_timer_proc16( WORD timer )
{
CONTEXT86 context;
FARPROC16 proc = SYS_Timers[timer-1].callback16;
memset( &context, 0, sizeof(context) );
context.SegFs = wine_get_fs();
context.SegGs = wine_get_gs();
context.SegCs = SELECTOROF( proc );
context.Eip = OFFSETOF( proc );
context.Ebp = OFFSETOF(NtCurrentTeb()->WOW32Reserved) + FIELD_OFFSET(STACK16FRAME,bp);
context.Eax = timer;
WOWCallback16Ex( 0, WCB16_REGS, 0, NULL, (DWORD *)&context );
}
/**********************************************************************/
WORD WINAPI WIN16_CreateSystemTimer( WORD rate, FARPROC16 proc )
{
WORD ret = CreateSystemTimer( rate, call_timer_proc16 );
if (ret) SYS_Timers[ret - 1].callback16 = proc;
return ret;
}
/***********************************************************************
* KillSystemTimer (SYSTEM.3)
*
* Note: do not confuse this function with USER.182
*/
WORD WINAPI SYSTEM_KillSystemTimer( WORD timer )
{
if ( !timer || timer > NB_SYS_TIMERS || !SYS_Timers[timer-1].callback )
return timer; /* Error */
SYS_Timers[timer-1].callback = NULL;
if (!--SYS_NbTimers) SYSTEM_StopTicks();
return 0;
}
/***********************************************************************
* EnableSystemTimers (SYSTEM.4)
*/
void WINAPI EnableSystemTimers16(void)
{
SYS_timers_disabled = 0;
}
/***********************************************************************
* DisableSystemTimers (SYSTEM.5)
*/
void WINAPI DisableSystemTimers16(void)
{
SYS_timers_disabled = 1;
}
/***********************************************************************
* GetSystemMSecCount (SYSTEM.6)
*/
DWORD WINAPI GetSystemMSecCount16(void)
{
return GetTickCount();
}
/***********************************************************************
* Get80x87SaveSize (SYSTEM.7)
*/
WORD WINAPI Get80x87SaveSize16(void)
{
return 94;
}
/***********************************************************************
* Save80x87State (SYSTEM.8)
*/
void WINAPI Save80x87State16( char *ptr )
{
#ifdef __i386__
__asm__(".byte 0x66; fsave %0; fwait" : "=m" (ptr) );
#endif
}
/***********************************************************************
* Restore80x87State (SYSTEM.9)
*/
void WINAPI Restore80x87State16( const char *ptr )
{
#ifdef __i386__
__asm__(".byte 0x66; frstor %0" : : "m" (ptr) );
#endif
}
/***********************************************************************
* A20_Proc (SYSTEM.20)
*/
void WINAPI A20_Proc16( WORD unused )
{
/* this is also a NOP in Windows */
}
|