[comp.lang.pascal] Reverse Video in Turbo Pascal

tasos@bu-cs.BU.EDU (Anastasios Kotsikonas) (10/18/89)

Does anyone know how to write characters in reverse video in Turbo Pascal
using the crt unit? I know it doesn't work with the usual escape sequence.
Strangly enough, the escape sequence works without the crt unit. 

Thanks in advance,
Tasos

Internet: tasos@cs.bu.edu

jrwsnsr@nmtsun.nmt.edu (Jonathan R. Watts) (10/18/89)

In article <40680@bu-cs.BU.EDU>, tasos@bu-cs.BU.EDU (Anastasios Kotsikonas) writes:
> Does anyone know how to write characters in reverse video in Turbo Pascal
> using the crt unit? I know it doesn't work with the usual escape sequence.
> Strangly enough, the escape sequence works without the crt unit. 

The reason the escape sequences work WITHOUT the crt unit is that then they
go through ANSI.SYS, which is what decodes them.  With the crt unit installed,
output is written directly to screen memory, which is faster, BECAUSE it
bypasses the bios, including ANSI.

To write reverse video in TP you could use
    TextAttr := (TextAttr shr 4) + (TextAttr shl 4);
This should switch the foreground and background colors.
Note that this won't work if you had the high-intensity bit set before-hand;
you'll end up with blinking text.  Conversely, if the text was blinking,
it will become high-intensity.  Sigh!

  - Jonathan Watts

jrwsnsr@nmtsun.nmt.edu

   

zougas@me.utoronto.ca ("Athanasios(Tom) Zougas") (10/18/89)

In article <3341@nmtsun.nmt.edu> jrwsnsr@nmtsun.nmt.edu (Jonathan R. Watts) writes:
>In article <40680@bu-cs.BU.EDU>, tasos@bu-cs.BU.EDU (Anastasios Kotsikonas) writes:
>> Does anyone know how to write characters in reverse video in Turbo Pascal
>> using the crt unit? I know it doesn't work with the usual escape sequence.
>> Strangly enough, the escape sequence works without the crt unit. 
>
>The reason the escape sequences work WITHOUT the crt unit is that then they
>go through ANSI.SYS, which is what decodes them.  With the crt unit installed,
>output is written directly to screen memory, which is faster, BECAUSE it
>bypasses the bios, including ANSI.
>
>To write reverse video in TP you could use
>    TextAttr := (TextAttr shr 4) + (TextAttr shl 4);
A better way is to set
	directvideo := false;
in you initialization. This will cause the output to NOT bypass bios
and thus, will be decoded by the ANSI driver.
The same thing will allow you to use 'write' and 'writeln' in graphics
mode and actually get text on the screen, for the same reason.

Tom.

-- 
I can be reached at...
  INTERNET:	zougas@me.utoronto.ca
  USENET:	zougas@me.toronto.edu
  BITNET:	zougas@ME.UTORONTO.BITNET
  UUCP:		...!utai!me!zougas

austin@bucsf.bu.edu (Austin Ziegler) (10/20/89)

>>>>> On 18 Oct 89 16:23:15 GMT, zougas@me.utoronto.ca ("Athanasios(Tom) Zougas") said:
Tom> In article <3341@nmtsun.nmt.edu> jrwsnsr@nmtsun.nmt.edu (Jonathan R. Watts) writes:
>In article <40680@bu-cs.BU.EDU>, tasos@bu-cs.BU.EDU (Anastasios Kotsikonas) writes:
>> Does anyone know how to write characters in reverse video in Turbo Pascal
>> using the crt unit? I know it doesn't work with the usual escape sequence.
>> Strangly enough, the escape sequence works without the crt unit. 
>
>To write reverse video in TP you could use
>    TextAttr := (TextAttr shr 4) + (TextAttr shl 4);

Tom> A better way is to set
Tom> 	directvideo := false;
[because it then allows ANSI to decode the strings]

   Even better would be to use the CRT unit, and, if you know the colors
(which most of us do), actually set the colors using TextBackground and
TextColor.  In your own unit, include the following three functions

FUNCTION GetBackground: BYTE;

 BEGIN  { Get the current background color }
  GetBackground:=TextAttr SHR 4;
 END; { GetBackground }

FUNCTION GetColor: BYTE;

 BEGIN { Get the current foreground color }
  GetColor:=(TextAttr SHL 4) SHR 4;
 END; { GetColor }

PROCEDURE ReverseColors;

  VAR Fg, Bg: BYTE;

 BEGIN { Reverse the colors ignoring high intensity and blink }
  Fg:=GetColor;
  Bg:=GetBackground;
  IF Fg > 15 { Strip the high intensity }
   THEN Dec (Fg,8);
  IF Bg > 15 { Strip the blink }
   THEN Dec (Bg,8);
  TextColor (Bg);
  TextBackground (Fg);
 END; { ReverseColors }

  These three should fix the problem, and if included into a personal unit,
they should not cause any problems whatsoever.

	  Elminster, the Sage of Shadowdale (austin@bucsf.bu.edu)
	       700 Commonwealth Box 2094, Boston, MA  02215

	      "S.F.'S NO GOOD!!" They bellow till we're deaf.
	    "But this looks good." "WELL THEN IT'S NOT S.F.!!"
			     -- Kingsley Amis

lowey@dvinci.usask.ca (Kevin Lowey) (10/23/89)

From article <40862@bu-cs.BU.EDU>, by austin@bucsf.bu.edu (Austin Ziegler):
> Tom> A better way is to set
> Tom> 	directvideo := false;
> [because it then allows ANSI to decode the strings]

(I know you aren't Tom, but I'll mention this here)

The directvideo flag only determines whether the CRT unit uses direct screen
writes, or BIOS calls.  Since the ANSI escape sequences only work when sending
output to the Standard Output (DOS) the Directvideo flag has no effect on
whether ANSI is used or not.  If you use the CRT unit, ANSI.SYS is not
available.

  However, if you assign a file to the file name '' (two quotes with 
nothing in between) then that file is associated with the standard input
by RESET, or the Standard Output with REWRITE.  That way you could do things
like:

  ASSIGN (STDIO,'');
  RESET (STDIO);
  write (stdio,'This goes through ',chr(27),'[1mANSI.SYS');
  write ('This goes through the CRT unit');

  However, I don't know how wise it is to mix CRT and ANSI in the same 
program.  I recommend using either one, or the other, but not both.
 
>    Even better would be to use the CRT unit, and, if you know the colors
> (which most of us do), actually set the colors using TextBackground and
> TextColor.  In your own unit, include the following three functions
> 

  If anyone is interested, I've created a unit that emulates most of the
CRT unit functions using ANSI.SYS.  The only things that are not emulated
are because of limitations in ANSI.SYS, like no ability to set the left
and right margins so scrolling scrolls everything on a line.  However most
things work ok. 

  The file is called KVL_ANSI.PAS and is available from my OPUS bulletin
board at (306) 966-4857.  People can download this file on the first call,
or file request it from another Fidonet BBS.  The unit is about 23K.

  I will be away for two weeks, but after then I can send it through mail
to people who request it.

- Kevin Lowey @ 140/43 - LOWEY@SASK.USASK.CA - ...!alberta!dvinci!lowey