  ------------------------------------------------------------------------

Fix for "Runtime Error 200" bug of Borland Pascal 7 on fast PCs

Explains the cause of this bug and sumarizes solutions both for users and
developers (people who do have / don't have pascal source of their
programs).

Also available: french translation

Contents:

   * Preface
   * Cause explained
   * Solutions Index
   * Comments
   * What's new [NEW! ] (25-May-1999)
   * other Web Pages

  ------------------------------------------------------------------------

Preface

Borland Turbo Pascal 7 is a great Pascal compiler for PC's. Unfortunately
it has not been updated by Borland for many years (for a possible
alternative see FPC).

All programs compiled with Borland Pascal 7 that use the system unit Crt
(almost all programs do that) abort with the error message "Runtime
Error 200" on all fast PCs, for example Pentium II with 233 MHz.

Programs compiled with Borland Pascal 6 are said to not abort with a
runtime error, but their delay is completely wrong on fast PCs (and the
problem starts there at much lower speeds than the problem of version 7).

This Web page tries to explain the problem and summarize some existing
solutions.

Borland (aka Inprise) does not offer a solution for this bug (shame on
them!). Instead their Pascal Developer Support recommends an Altavista
search, which probably is how you have found this web page.

  ------------------------------------------------------------------------

Cause

The bug is in the initialization for the delay procedure that is part of
the initialization of the Crt unit. The delay initialization is called in
every program that uses the Crt unit, not just on those that use the delay
procedure. The Crt unit is included in most programs that are written in
Borland Pascal.

The delay initialization counts how often a tiny do-nothing loop must be
called in order to delay by 55 milliseconds (time measured by reading the
Bios Time Counter at memory address 40:6C that ticks 18.2 times a second,
i.e. each 55 milliseconds).

This number is then divided by 55 to get the number of calls for one
millisecond. The result is written to a word (16 bit) variable. The
overflow of this variable triggers the run time error (the meaning of
Runtime Error 200 is division by zero, but it is caused by an overflow in
this case).

  ------------------------------------------------------------------------

Solutions

The following list shows all solutions that I currently know.
If something is missing here, please tell me.

Index of recommended solutions

   * You have only an EXE file, no Pascal source
        o ask the person who does have the pascal source for a new or
          recompiled version
        o TpPatch   Patch program for existing executable files
          (caution: only for programs that no not require correct timing)
        o if you need correct timing, you may experiment with tp7p5fix from
          the other solutions below, it doesn't tell if such programs work
          with that or not (probably not but maybe worth a try).

   * You have pascal source and the Turbo Pascal compiler
        o T7TplFix   [NEW! ] patch program for Run Time Library file
          (TURBO.TPL)
        o NewDelay   unit with delay replacement (good) and error trap (a
          bit dubious)
        o RDelay   unit with delay replacement and runtime patch routine
        o extract the file CRT.DIF from T7TplFix, apply the listed changes
          to CRT.ASM and then recompile the run time library yourself.
          (Only possible if you have the source of the run time library,
          i.e. you have Borland Pascal, not Turbo Pascal.)

Note: If you have Turbo Pascal or Borland Pascal version 7.0, I recommend
you contact Borland / Inprise to obtain version 7.01 because version 7.0
contains several bugs. Lately there have been reports in usenet that
Borland doesn't know about a 7.01 bug fix version, it's still called 7.0,
so it may be better to ask for replacement disks for version 7.0 (will come
as one cdrom containing version 7.01).

Index of other solutions

bppatch   Solution by German computer magazine c't
     contains description, program patch, source patch and copy of patched
     run time library
     problem: rtl is based on version 7.0, thus reintroducing several old
     errors while fixing one new one, description and patch are very good
     though.

bp7patch   patch program for all Run Time Library files
     problem: does much more changes than can be easily explained

tp7p5fix   TSR program, catches error while program starts
     problem: no description available how and how well this program works,
     probably only for programs that do not require precise timing

tpbug   new TPL files
     problem: contain much more changes than can be easily explained

  ------------------------------------------------------------------------

Comments

Looking through the list of files above, most of you will probably come to
the conclusion that no real solution seems to be available.

Programmers using Turbo Pascal 7.01 can now solve their problem since
t7tplfix.zip is available. Programmers using Borland Pascal 7.01 and still
must search and apply the patch themselves to get a working version of
TPP.TPL (for protected mode). Users without source of their programs can
still not get a real solution if the programs rely on a precise delay
function. Such a solution will probably never exist.

Of the two files recommended by Borland, one will cause the delay procedure
to not run correct on fast computers, the other can be used only by owners
of the full Borland Pascal package because the file TPP.TPL is required and
it does a lot of suspicions changes to other units as well.

By using any of the other files, you must send your customers a program
that is patched to patch itself at runtime with even its authors saying
that this is not very nice. Or you can prevent the run time error but must
live with a delay procedure that is known to run at unpredictable speeds.
Or you must persuade your customers to install a TSR program that you don't
know precisely what it does. Or you reintroduce all the bugs of Borland
Pascal 7.0 when replacing a otherwise correct version 7.01 with a patched
version 7.0. Or you can used a patched run time library that contains a lot
of additional changes that nobody has yet explained.

It is a shame for Borland that they seem to be unable or unwilling to solve
this bug themselves and offer download of fixed TURBO.TPL and TPP.TPL files
from their web page!

If you feel like you should say Borland what you think about their support,
please remember they have changed their name to Inprise, so you may try
mailing to customer-service@inprise.com (if you get a reply, please tell
me).

  ------------------------------------------------------------------------

What's New

   * 26-May-1999 new patch for Runtime Library of Turbo Pascal versions 7.0
     and 7.01
     A new version of t7tplfix.zip is available here.
     It should be able to patch files TURBO.TPL, TPP.TPL, and CRT.TPU of
     Turbo Pascal and Borland Pascal versions 7.0 and 7.01.
     Please note that I still recommend updating to the bug fixed version
     7.01 that could already be patched with the previous version, but if
     you don't want difficult discussions with Borland, this is an
     alternative to fix at least the most annoying bug.

   * 29-Sept-1998 similar Bug found in Windows-95
     Borland is not the only company that didn't expect computers to become
     that fast and thus having bugs in their progams: A similar error has
     been found in Windows-95: on computers with an AMD K6-2 with 350 MHz
     or more the driver IOS.VXD causes a division by zero because it
     contains a timing loop that overflows on computers with too high
     speed.
     For more informations about this see
     www.amd.com/products/cpg/k623d/win95_update_k6.html. This problem is
     solved by the patch amdk6upd.exe that can be downloaded from Microsoft
     (go to their homepage, click on search and enter the filename) or try
     this webpage (link probably works only limited time because Microsoft
     often rearranges their web pages).

   * 22-Aug-1998 Patch Program available T7TplFix.zip
     patch for run time library TURBO.TPL of Turbo Pascal 7.01

   * 22-July-1998 new version of bp7patch.zip
     does not require TPP.TPL any more, i.e. works if you have Turbo
     Pascal, not Borland Pascal

  ------------------------------------------------------------------------

Web-Pages

Some other web pages that contain informations about this topic:

Official and of no big help:

   * Borland's Pascal Developer Support
   * Intel Developer Support

Inofficial but much more help:

   * J R Stockton's Borland Pascal Time and Date Page
   * Stefan Ghler's TP-BUG page
   * Franz Glaser's Pascal+Delphi site (click on patches)

More about Borland Turbo Pascal:

   * my Pascal Page
   * other Pascal Pages

  ------------------------------------------------------------------------
Last change: 22-Aug-1998
Collection and Descriptions  1998 by Klaus Hartnegg
All information and programs mentioned herein are provided without
warranty. Use all on your own risk.
Best viewed with any browser. Created using The Semware Editor and vi.
Ceterum censeo Microsoft esse delendam.
[Image] (Counter started 21-July-1998)
[IPStat]
