Dec 202017
Turbo Pascal Unit Overcome Bug of Delay Function on Fast 33mhz machines.
File FWAIT1.ZIP from The Programmer’s Corner in
Category Pascal Source Code
Turbo Pascal Unit Overcome Bug of Delay Function on Fast 33mhz machines.
File Name File Size Zip Size Zip Type
FASTWAIT.PAS 2418 890 deflated
TEST.PAS 2292 809 deflated
WAIT.ASM 2516 847 deflated
WAIT.DOC 3921 1671 deflated
WAIT.OBJ 319 291 deflated

Download File FWAIT1.ZIP Here

Contents of the WAIT.DOC file

FastWait Copyright (c) 1991 Southern Software

Version 1.00 - 4/8/91

Allows PC's faster than 20 mhz (386/486) to properly use a delay
function based upon a null looping procedure such as is used in the
Turbo Pascal "Delay" procedure. Wait is accurate for PC's as fast as
1,100 mhz equivalent!

USAGE: Simply place "FastWait" in the Uses section of your program
and replace each occurrence of "delay" in your program with


Existing program:
Uses CRT;

writeln('This program delays for 5 seconds.);

New program:
Uses FastWait, CRT; {Now also uses "FastWait"}

writeln('This program delays for 5 seconds.);
wait(5000); {changed "delay" to "wait"}

User accessible variables in FastWait unit:

WaitOneMS : Number of loops required for one millisecond delay
LoopsPerTick : LongInt which is # loops in timer for one
BIOS tick (18.2 ticks per second)
BIOSTick : An absolute LongInt variable into the PC BIOS area
which is the system counter and is incremented 18.2
times per second.

Procedure in FastWait unit:

procedure Wait( ms : word );

procedure ShortDelay(NumLoops : word);
This procedure is for very short timing loops ( < 1ms) that cannot be
handled by the delay routine.

The variable "LoopsPerTick" has the number of loops to do for one BIOS
tick (18.2 of these/sec). If you want to delay for "X" s, the number
of loops required would be "(LoopsPerTick*X) div 54945"

This will not compile if you are using TP 4.0, 5.0 or 5.5 due to the
conditional defines. This is because it makes use of the "asm"
statement which is not available in TP versions prior to 6.0.

Technical Discussion
In the Turbo CRT unit, there has been a word variable named "DelayCnt"
(local variable to the CRT unit) which is the number of loops that
were done in one clock tick divided by 55. This is a decent approx-
imation of the number of loops required for one millisecond (the
"Delay" procedure merely called a null loop "DelayCnt" times for each
millisecond specified in the call to the procedure. (Note- For those
using Object Professional or Turbo Professional, this variable is called
"OneMS", but the logic is identical).

Unfortunately, if the clock speed gets to about 25 mhz, the PC is so
fast that the PC can do more than 65,535 loops and the null loop timer
does not work. The value 65,535 is divided by 55 to give 1,191
regardless of the speed of the PC. Subsequent calls to the delay
procedure cause shorter-than-expected delays since the delay count
calculated for one millisecond is too low. This problem gets worse the
faster the PC becomes.

The "Wait" procedure is a simple solution to this problem. The number
of loops done in one clock tick is stored in a LongInt rather than a
word variable so the limit of 65,535 loops in one clock tick is not a

Special goody if you are using TP 6.0+ (or if you want to make the
assembly code below in a separate ASM file) -- A routine called
"ShortDelay" is provided which will be included in the FastWait unit
automatically if you are using TP 6.0+ that allows you to specify
delays which are shorter than 1 millisecond (the lower limit of
the "delay" and "wait" routines.

Public Usage
This utility is provided for the public domain on an as-is basis
free of charge. It may be used in any programs with no royalties.
Southern Software retains all rights to the code and is not liable
for anything which may happen as a result of using the code.

 December 20, 2017  Add comments

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>