Board index » delphi » Own delay procedure

Own delay procedure

How can I write a own delay procedure to avoid using the crt unit?

I'll appreciate any help.
Thank you and bye.

      /~~\                              MARCELLO RAFFA -- ITALY
   +--|__|----------)  /-----------------------------------------\
  () -____-   [__]  |  | E-Mail: mailto:sra...@eniware.it        |
 _+---              |[]| News: it.comp.*, TPascal and UFO groups |[
/__;-(__)-----(__)--/  \---(__)-------(__)-------(__)-------(__)-/

 

Re:Own delay procedure


In article <50p7eq$...@server-b.cs.interbusiness.it>,

Quote
Marcello Raffa <sra...@eniware.it> wrote:

:How can I write a own delay procedure to avoid using the crt unit?

You don't have to:

 112582 Aug 16 1994 ftp://garbo.uwasa.fi/pc/ts/tspa3470.zip
 tspa3470.zip Turbo Pascal 7.0 real mode units for (real:-) programmers.

   All the best, Timo

....................................................................
Prof. Timo Salmi   Co-moderator of news:comp.archives.msdos.announce
Moderating at ftp:// & http://garbo.uwasa.fi archives  193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa
t...@uwasa.fi http://uwasa.fi/~ts BBS 961-3170972; FIN-65101,  Finland

Re:Own delay procedure


I hereby include 2 delay procedures, you may decide which is better.

Version 1 (Although CRT is not required, but DOS is required in version 1)
Uses Dos;
Procedure MyDelay(HundSec:LongInt);
Var
  Hour, Minute, Second, Hundred : Word;
  Prev, Now : LongInt;
Begin
  GetTime(Hour,Minute,Second,Hundred);
  Prev := ((Hour * 60 + Minute) * 60 + Second) * 100 + Hundred;
  Repeat
    GetTime(Hour,Minute,Second,Hundred);
    Now := ((Hour * 60 + Minute) * 60 + Second) * 100 + Hundred;
    If Now < Prev then Prev := Prev - (24 * 60 * 60 * 100);
  Until Now >= (Prev + HundSec);
end;  { of Procedure MyDelay }

Version 2 (Borland Pascal 7.0)
Procedure MyDelay(Num:LongInt);
Const
  Now : LongInt absolute $40:$6C;
Var
  Prev : LongInt;
Begin
  Prev := Now;
  Repeat
    If Now < Prev then Dec(Prev,(24 * 60 * 60 * 10 * 182));
  Until Now >= (Prev + Num);
end;  { of Procedure MyDelay }

                                from Poon Wing Chi (Hong Kong)

In article <50p7eq$...@server-b.cs.interbusiness.it>, sra...@eniware.it (Marcello Raffa) says:

Quote

>How can I write a own delay procedure to avoid using the crt unit?

>I'll appreciate any help.
>Thank you and bye.

>      /~~\                              MARCELLO RAFFA -- ITALY
>   +--|__|----------)  /-----------------------------------------\
>  () -____-   [__]  |  | E-Mail: mailto:sra...@eniware.it        |
> _+---              |[]| News: it.comp.*, TPascal and UFO groups |[
>/__;-(__)-----(__)--/  \---(__)-------(__)-------(__)-------(__)-/

 =============================================
 |  Please feel free to contact me at:       |
 |      b91593%lxhk02.school.net...@hk.net   |
 |      astronet!poon.wing....@hk.super.net  |
 |  Please have a view of my homepage at:    |
 |      http://lxhk02.school.net.hk/~b91593/ |
 |  Telephone Number : (852) 23562172        |
 =============================================

Re:Own delay procedure


In article <50sc2l$...@ecs2.school.net.hk> of Sat, 7 Sep 1996 17:40:37
in comp.lang.pascal.borland, Poon Wing Chi <b91...@lxhk02.school.net.hk>
wrote:

Quote
> ...
>Version 2 (Borland Pascal 7.0)
>Procedure MyDelay(Num:LongInt);
>Const                                     <- should be  Var
>  Now : LongInt absolute $40:$6C;
>Var
>  Prev : LongInt;
>Begin
>  Prev := Now;
>  Repeat
>    If Now < Prev then Dec(Prev,(24 * 60 * 60 * 10 * 182));
>  Until Now >= (Prev + Num);
>end;  { of Procedure MyDelay }

Note that Now will be accessed non-atomically, as two 16-bit words;
hence, once an hour, when Now reaches a multiple of 2^16, there is a
(small) chance that the value obtained will be inconsistent.  Also, one
can calculate the end value (Prev+Num) before entering the loop, thus
waiting faster.  Also, 24*60*60*10*182 should be (24*60*60*182) div 10
(but the clock is actually a bit faster than 18.2; the constant should
be $00180000 plus about $180 I think).  Note that the routine by me in
Timo's Pascal FAQ, #67, A2, has the non-atomic defect.

I have a delay routine which loops counting CHANGES in the byte at
Seg0040:$006C.  PT18 is a pointer, or a ^longint, already set to contain
Seg0040:$006C.

procedure WaitTix(Tix : shortint) {MSDOS/DPMI} ;
var x46C : byte ; PB18 : ^byte absolute PT18 ;
begin x46C := PB18^ ;
  repeat
    if x46C<>PB18^ then begin x46C := PB18^ ; Dec(Tix) end ;
    until Tix<0 end {WaitTix} ;

I'll put more in the URL below, before long I hope.
--
John Stockton, Surrey, UK.  J...@merlyn.demon.co.uk  Turnpike v1.12  MIME
     http://www.merlyn.demon.co.uk/pascal.htm#Wait

Re:Own delay procedure


Quote
sra...@eniware.it (Marcello Raffa) writes:
>   Prev := ((Hour * 60 + Minute) * 60 + Second) * 100 + Hundred;

You need a type cast to Longint here, otherwise the whole calculation will be
done in words, and overflow (except from 0:00 to about 0:11).

Quote
> Version 2 (Borland Pascal 7.0)

Should work with all versions (at least from 5.x), but only in real mode
(because of "absolute $40:...")

Quote
>     If Now < Prev then Dec(Prev,(24 * 60 * 60 * 10 * 182));

Should be "div", there are 18.2 ticks / second -^

For a resolution of 1/18.2s (55ms), these routines are fine. However, if you
need shorter timings (1/100s, e.g.), these will not suffice (even if the
GetTime Dos call returns hundreths of seconds, it only has a resolution of
55ms). For a different approach, very similar to that found in Crt, see my
posting on 'Re: "pause"'.

Hope this helps,
Frank

Other Threads