Own delay procedure 
Author Message
 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
   +--|__|----------)  /-----------------------------------------\

 _+---              |[]| News: it.comp.*, TPascal and UFO groups |[
/__;-(__)-----(__)--/  \---(__)-------(__)-------(__)-------(__)-/



Wed, 18 Jun 1902 08:00:00 GMT  
 Own delay procedure


: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

....................................................................

Moderating at ftp:// & http://garbo.uwasa.fi archives  193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa



Wed, 18 Jun 1902 08:00:00 GMT  
 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)


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
>   +--|__|----------)  /-----------------------------------------\

> _+---              |[]| News: it.comp.*, TPascal and UFO groups |[
>/__;-(__)-----(__)--/  \---(__)-------(__)-------(__)-------(__)-/

 =============================================
 |  Please feel free to contact me at:       |


 |  Please have a view of my homepage at:    |
 |      http://lxhk02.school.net.hk/~b91593/ |
 |  Telephone Number : (852) 23562172        |
 =============================================


Wed, 18 Jun 1902 08:00:00 GMT  
 Own delay procedure




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.
--

     http://www.merlyn.demon.co.uk/pascal.htm#Wait



Wed, 18 Jun 1902 08:00:00 GMT  
 Own delay procedure

Quote:

>   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



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. delay procedure & time of cpu (BP7)

2. Procedure Delay in TPW

3. Delay procedure

4. Problem with Delay procedure on 486s

5. Calling a procedure within a procedure

6. HELP - calling a Procedure from with a Procedure??

7. re : main-->procedure coomunication + Menu Procedure

8. Using a Procedure within a Procedure?

9. Procedure as parameter in procedure

10. Fast PutCharacter Procedure &/or remove cursor procedure

11. fast putchar procedure and remove cursor procedure needed for lord II type game

12. passing procedures as arguments for another procedure in Turbo pascal

 

 
Powered by phpBB® Forum Software