{  (c) Copyright 1998,2000 Bernhard R. Link (2:2476/841.64;brl@gmx.de)
***************************************************************************
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
****************************************************************************}
Unit UDelay;
{$I platform.inc}
{$I mkglobal.inc}
{Diese Unit soll ein Delay zur Verfgung stellen.
Um es etwas zu beschrnken auf Wait reduziert. }
{$IFNDEF PPC_Virtual}
{$IFNDEF UseCrt}
{$DEFINE NoCRT}
{$ENDIF}
{$ENDIF}
{Unter BP kann mit USLDelay da ganze OS/2 und Desqview-freundlich gemacht werden}
{$IFNDEF PPC_BP}
{$UNDEF UseUSLDelay}
{$ENDIF}
interface

Procedure Delay(ms:Word);
{Wartet ms Milisekunden oder ungefhr 100 Millisekunden,
je nach Implementation}

implementation
{$IFDEF UseUSLDelay}
uses USLDelay;

Procedure Delay(ms:Word);
begin
USLDelay.Delay(ms);
end;

{$ELSE}

{$IFDEF OS_Linux}
  {$IFDEF PPC_VIRTUAL}
uses crt; {Nicht gerade elegant!}

Procedure Delay(ms:Word);
begin
Crt.Delay(ms);
end;
  {$ELSE}
  {$IFDEF PPC_FPC}
uses Linux;

Procedure Delay(ms:Word);
begin
Select(0,nil,nil,nil,ms)
end;
  {$ENDIF}
  {$ENDIF}
{$ELSE} {not OS_Linux}
{$IFDEF OS_WINDOWS}
    {$IFDEF PPC_Delphi2}
uses Windows, Classes, Graphics, Forms, Controls, StdCtrls, ExtCtrls, ComCtrls;
Procedure Delay(Ms: Word);
begin
sleep(ms);
End;
    {$ELSE}
uses Wintypes,Winprocs;
      {$IFDEF MKW}
{Aus MKWCrt von und Copyright Mark May}
Procedure Delay(Ms: Word);
  Const
    TimerId = 1989;
  Var
    DDone: Boolean;
    DTime:Longint;

  Begin
  DTime:=ms;
  DDone := False;
  If SetTimer(HWindow,TimerId, DTime, nil) <> 0 Then
    Begin
    While Not DDone Do
      Begin
      WaitMessage;
      If PeekMessage(Message, HWindow, 0, 0, pm_Remove) Then
        Begin
        If Message.Message = wm_Timer Then
          DDone := True
        Else
          If (TranslateAccelerator(HWindow, Accels, Message) = 0) Then
            Begin
            TranslateMessage(Message);
            DispatchMessage(Message);
            End;
        End;
      End;
    KillTimer(HWindow, TimerId);
    End;
  End;
      {$ELSE MKW}
{Aus Online-hilfe:}

Procedure Delay(ms : Word);
Var
  TickCount : LongInt;
  M         : TMsg;
Begin
  TickCount := GetTickCount;
  While GetTickCount - TickCount < Longint(ms) do
    If PeekMessage(M,0,0,0,pm_Remove) then
      Begin
        TranslateMessage(M); DispatchMessage(M);
      End;
End;
      {$ENDIF MKW}
      {$ENDIF PPC_DELPHI2}
    {$Else}{not OS_Linux and not OS_Windows}
{$IfNDEF NoCRT}

Uses
  {$IFDEF OPRO}
  OpCrt;
  {$ELSE}
  Crt;
  {$ENDIF}

Procedure Delay(ms:Word);
begin
  {$IFDEF OPRO}
  OpCrt.
  {$ELSE}
  Crt.
  {$ENDIF}
Delay(ms);
end;

{$Else NoCRT}

Procedure Delay(ms:Word);
var p:^Word;ot,wt:Longint;
begin
p:=ptr(Seg0040,$6C); {Timer ticks since midnight}
ot:=p^;            {check for midnight-overrun}
wt:=ot+(182*ms+5000)div 10000;
While(p^>=ot)and(p^<=wt) do;
end;

{$EndIF NoCRT}
{$EndIf OS_Windows}
{$ENDIF OS_Linux}
{$ENDIF USDLDelay}
end.


