This 'README.TXT' file  was originally written for  the  CRT replacement
units  made available by Pedt Scragg.  It  was changed  slightly for the
current Robert AH Prins created replacement unit.

CRT Replacement Units for Turbo/Borland pascal Compilers
========================================================

1. Preamble
-----------

The Crt unit as supplied by Borland has a few defects.  No smart linking
is possible with the unit and the  T/BP7 version  fails  with RTE200  on
fast  computers whilst  the  TP6 version has inconsistent delay problems
when used on a fast computer.

These CRT units have been written as a direct replacement to the Borland
supplied CRT unit to both remove the RTE200 problem in T/BP7 and also to
shrink the  required code to a minimum  if all procedures and  functions
are not used.


2. Reasoning
------------

There seemed  a  need to  address  these  problems in  view of the  many
questions asked in newsgroups about the RTE bug in T/BP7 and a number of
questions about the TP6 Delay.  A rewritten CRT unit that could be  used
as a drop in replacement to  the Borland supplied unit whilst offering a
number of enhancements that did not break older programs and precompiled
units started to seem a needed resource to Turbo Pascal programmers.

Caveats:

 - this replacement unit uses 386 instructions, it will not run on 8088,
   8086 and 80286 CPUs!

 - the Delay function will calibrate itself on the first use. If this is
   not acceptable, a Delay(1) must be inserted before the first real use
   of Delay().


3. Testing
----------

Testing was carried  out by  myself, using nested precompiled units,  to
check if dropping  a replacement CRT  unit into the turbo.tpl or tpp.tpl
library would break a precompiled unit that used the original CRT.  This
has proved not to be the case.

Following testing,  it seems that  the interface part  of  CRT  has  not
changed since V5.00 of Turbo Pascal.  I was able to drop in the new unit
directly into turbo.tpl and  the V7 tpp.tpl for  all versions from V5.00
upwards so have made these units additionally available.  I do  not have
Delphi 1 installed, so  instead I have added the .OBJ files and the full
modified 'CRT.PAS' file.  Using  these it would be possible to roll your
own D1 units.  A description on how to adapt D1 to generate DOS and DPMI
executables can be found on http://www.pedt.demon.co.uk/usenet/


4. Distributed Files
--------------------

This distribution contains the following files:

CRT50.TPU    - CRT for V5.00
CRT55.TPU    - CRT for V5.50
CRT60.TPU    - CRT for V6.00
CRT70.TPU    - CRT for V7.0x Real Mode
CRT70.TPP    - CRT for V7.0x Protected Mode
CRT_TEST.PAS - A Test program that exercises most of the CRT unit
README.TXT   - This File
CRT.PAS      - Pascal source for the CRT unit
*.OBJ        - The .OBJ files used to create the unit
CRT.OBP      - This one's for BP7/D1 [DPMI]
SE.ASM       - Equates
ALIGN.ASM    - Alter code alignment
CRTDELAY.ASM - The source of the improved Delay function
TIME.PAS     - A timer unit
CLOCK.ASM    - Millisecond timer code by Norbert Juffa
WT4TICK.ASM  - Wait for low-memory clock to roll over
CLOCK.OBJ    - Object file required for Time unit
WT4TICK.OBJ  - Object file required for Time unit


5. Replacing CRT.TPU into TURBO.TPL or CRT.TPP into TPP.TPL
-----------------------------------------------------------

First BACK UP YOUR ORIGINAL LIBRARY!

Extract the relevant files from  the .ZIP file and rename the files with
the correct CRT<version>.TPU/P to CRT.TPU/P as required.

For example, for V6 of Turbo pascal rename CRT60.TPU to CRT.TPU

Use TPUMOVER.EXE supplied with your distribution of the compiler.

Follow the instructions of TPUMOVER to delete  the current CRT unit from
the TURBO.TPL or TPP.TPL as required.  Now add the new CRT.TPU/P unit to
the *.TPL file.

You  may wish to check that  previously compiled programs  using CRT and
external  programs will still compile  and run properly.  It is STRONGLY
suggested that this is done by copying the source to a new directory and
compiling  from there rather  than  over-writing  your  *.TPU files even
though a back up of *.TPL files will mean you can restore the original.


6. Changes
----------

a)  Split into separate sections (18 *.OBJ files) to maximise the amount
of  smart linking that can be done.  This means that  programs  will  be
smaller if not using all the procedures and functions in CRT.

b)  Supports F11, F12 etc. if extended keyboard available.  Uses  Int$16
$00/$01 otherwise as  per the  original CRT unit.  Already written  code
should be  perfectly OK with the  extension to ReadKey  to read extended
codes as they should come up as unrecognised in older code.  Gray cursor
keys and KeyPad give the KeyPad codes on extended keyboards. If you need
to distinguish between the  cursor  keys and the keypad keys  you should
already have your own unit to do this. The extended keyboard is detected
by examining the BIOS data segment!

c) CheckSnow is  set  false on EGA, VGA or better grahpics by default on
both initialisation and  TextMode changes.  CheckSnow still sets true on
CGA  cards.  The assembly code used is as fast as the need to explicitly
set CheckSnow to false on EGA/VGA cards after using TextMode.

d) Writing via DirectVideo or BIOS  writes: checking conditions  changed
so that non-CGA Text Ouput works  a little faster on most  machines.  As
most computers now in  use have EGA, VGA or SVGA graphics, the coding is
set to maximise the speed  of writing to these cards  at the expense  of
making CGA writes slightly slower.

e) Modes above  $7 checked and,  if Text Mode rather than Graphics Mode,
no force into 80x25 Text Mode on program startup.  The original CRT unit
set 80x25 colour text mode (Mode  3) if the  video mode was above Mode 3
and not Monochrome Adaptor.  If you use 132x25 text  mode then this will
stay  when  running programs  compiled with the  new  CRT  unit.  If you
explicitly need 80x25 then  use  TextMode to change the mode  at program
startup  whilst using the LastMode variable to store the original screen
mode to restore this on program termination.

f) Delay fixed to longint/dword status to prevent RTE200.  This occurred
on computers  above  200MHz using T/PP7.0x  and has  been the subject of
many questions in comp.lang.pascal.borland & borland.public.turbopascal.
The  version  of CRT  for TP6.00  resolves  the  incorrect delay  of the
original CRT unit for fast computers.  The new code uses 'mul' to 'div',
and is likely to fail when CPUs reach an extremely high  speed.  If this
happens, the Delay() function will no longer delay at all...

g) Instructions, as far as  possible,  allow pipelining on P5+  and  any
compatible CPU to maximise the speed of the unit. Slow CISC instructions
(loop/stosb/lodsb/etc) have  been replaced by  their simpler  and faster
equivalents.


7. Not changed
--------------

1. In BW40/80 modes, colour EGA/VGA cards will allow changing the colour
of Text or Background to non-BW colours.

2. Interface part of the unit - to remain compatible.


8. Thanks
---------

My thanks to Norbert Juffa,  Pedt Scragg and indirectly to William Peavy
and Osmo Ronkanen for  providing  me with the  code to start with in the
first place.


8. Bug Reports
--------------

Tell me, prino@bigfoot.com, what's wrong and I'll  do my best to correct
it as soon as possible.


9. Disclaimer
-------------

Units  are supplied as is and whilst testing seems to indicate that they
operate  as  a  drop in replacement  without  any  problems, programmers
should make their own tests  to  ensure  that  their  program  works  as
expected.


Robert AH Prins, December 2002
email: prino@bigfoot.com