[comp.lang.pascal] difficulty filling in last square on screen

TOAD@LIVERPOOL.AC.UK (04/26/91)

I'm writing an editor type program in tp 5.5. This is not a particularly
difficult task, except that in crt mode I can't plot a character into the
bottom left corner of the screen without causing the screen to scroll. Now this
is not such a great problem as this point is effectively redundant anyway,
however, it does mean that there is now an unsightly black square on an
otherwise flawless display.
      I've considerd trying to download a character directly into the computer'
s screen memory, but my lack of knowledge of the IBM PC coupled with the loss
of of Borland's referance manuals has meant that I've had little success so
far.
      Any suggestions?

       TOAD................................

amead@s.psych.uiuc.edu (alan mead) (04/29/91)

TOAD@LIVERPOOL.AC.UK writes:

>I'm writing an editor type program in tp 5.5. This is not a particularly
>difficult task, except that in crt mode I can't plot a character into the
>bottom left corner of the screen without causing the screen to scroll. Now this
>...
>      Any suggestions?

Yup.  I wondered about this as well.  It was a problem for me when I
first wanted a "framed window".

Whether or not TP uses direct screen writes in WRITE() and WRITELN(),
the BIOS "ettiquite" is observed--thus if you write to the end of a
line, a carridge return-line feed combination is written.  If this
occurs at the last row, a scroll is perfromed as well.  This scroll
is causing your problem.

The easiest way to avoid this is to use your own direct screen writes
(well, the *easiest* method is to limit yourself to the first 1999
character cells, perhaps by only supporting 79 columns).

While many asembler implementations exist, like Technojock's Turbo
Toolkit and Borland's WIN.PAS and the windowing unit in the book
_Advanced Techniques in Turbo Pascal_ by Ohlsen & Stoker, (and many
others) you can do it pretty well in TP.

CAUTION:  The following is from memory, but I believe the details are
correct.

Video *TEXT* RAM starts at either $B800 (for color) or $B000 (for mono)
and is 4000 bytes long (25 x 80 x 2 = 4000; but remember that as an
offset the numbering goes from 0 to 3999).  The first byte is the
attribute (which is exactly like the TEXTATTR byte in the CRT unit).
The second byte is the ASCII (ie from the table in the back of the TP
manual) character occupying the cell.

So write your string to video RAM, try:

Mem[ Video_base : ( 160*( Row-1 ) + 2*( Col-1 ) )+1 ] := Byte( C );

where Row and Col are Y and X as in GotoXY(); VideoBase is either $B800
or $B000; and C is the character to be written.

The current screen colors of the text will not be altered.  The easiest
way to alter them (not the fastest) would be to set the correct colors
using TextColor() and TextBackground() and then assign

Mem[ Video_base : ( 160*( Row-1 ) + 2*( Col-1 ) )+0 ] := TextAttr;

You should also be warned that this method will not work with screen
sizes other than 80 columns x 25 rows and that it might not work on all
"compatibles" and it might not work in the future.

Hope this helps.

-alan : amead@s.psych.uiuc.edu

rind@popvax.uucp (747707@d.rind) (04/29/91)

TP uses the variables WindMin & WindMax (in the CRT unit) to keep track of 
the size of the screen.  The variables are Words with low-byte equal to
the x-coord and high-byte equal to the y-coord.  If you increase the 
size of WindMax, you can write to position (80,25) without scrolling.

David Rind
rind@popvax.harvard.edu