Board index » delphi » Turning Cursor Off and On... simple solution

Turning Cursor Off and On... simple solution

On Sat, 09 Nov 1996 01:03:12 GMT, wie...@cs.utexas.edu (Charlie

Quote
Wiederhold) wrote:
>Many many of the posts here regard turning the cursor on and off. I
>know that this is probably something that many of you already knew,
>but I know there are probably some people out there that just for some
>reason missed this simple solution. For the most part all people need
>to do is turn the cursor off when their program starts, and then turn
>it back on after the program exits. This is a pretty simple solution
>that works for me, and has simplified my life greatly. It also teaches
>a bit of good programming technique for working in text modes.

>Here is the source code for a simple program using this method.
>The code to turn the cursor off was taken from Timo Salmi's Pascal
>FAQ.

>PROGRAM CursorOnOff;

>USES
>  Crt,
>  DOS;

>VAR
>  OrigMode : Integer;
>  Regs     : Registers;

>BEGIN
>  {* Find the original textmode before program exectutes *}
>  OrigMode := LastMode;

>  {* Set the textmode to 25x80 and clear the screen with white text *}
>  {* and a black background just like in DOS *}
>  TextMode (3);
>  textcolor (7);
>  textbackground (0);
>  clrscr;

>  {* This whole section turns the cursor off. *}
>  {* Taken from Timo Salmi's FAQ *}
>  fillchar (Regs, sizeof(Regs), 0);  (* Initialize, a precaution *)
>  {* ... find out the current cursor size (regs.ch, regs.cl) ... *}
>  Regs.AH := $03;
>  Regs.BH := $00;    (* page 1, superfluous because of FillChar *)
>  intr ($10, Regs);  (* ROM BIOS video driver interrupt *)
>  {* ... turn off the cursor without changing its size ... *}
>  Regs.AH := $01;                   (* Below are bits 76543210 *)
>  Regs.CH := Regs.CH OR $20;  (* Turn on bit 5; $20 = 00100000 *)
>  intr ($10, Regs);

>  {* Test write to prove it is actually off *}
>  writeln ('The Cursor is now off...');
>  readln;

>  {* Reset the textmode as it was before execution *}
>  TextMode (OrigMode);
>  textcolor (7);
>  textbackground (0);
>  clrscr;

>  {* Test write to prove it is actually back on *}
>  writeln ('The Cursor is now on...');
>  readln;
>END.

>The reason this shows good programming technique, is it resets the
>video to whatever mode it was before your program ran. It is mostly
>usefull when you want to use higher modes such as 50x80, and want to
>reset it back to the standard 25x80.  As for the cursor being turned
>back on, that is just a product of reseting the textmode. I don't know
>how "clean" that is, but it works.

>Hope this helps at least one person who loves programming in Pascal as
>much as I do!

>Thanks!
>*************************************************************
>Charlie Wiederhold
>WiederWeb - http://www.cs.utexas.edu/users/wieder/
>wie...@cs.utexas.edu
>University of Texas at Austin - Computer Sciences
>UT Longhorn Band
>Programmer - Sunstorm Interactive

That seems like a lot more work then the version I use...  And I've
never had any problems with it...

Procedure Cursor(CursorOn: Boolean);

  Begin
    {[F-]}
      If CursorOn then
         Inline($B4 / 3 /         { mov ah,3 ; read c mode }
                $B7 / 0 /         { mov bh,0 ; for page 0. }
                $CD / 16 /        { int 10H ; CRT bios }
                $80 / $E5 / $DF / { and ch,DFH }
                $B4 / 1 /         { mov ah,1 ; set c type. }
                $CD / 16)
      else
         Inline($B4 / 3 /         { mov ah,3 ; read c mode }
                $B7 / 0 /         { mov bh,0 ; for page 0. }
                $CD / 16 /        { int 10H ; CRT bios }
                $80 / $CD / $20 / { or ch,20H }
                $B4 / 1 /         { mov ah,1 ; set c type. }
                $CD / 16)
      {[F+]}
  End;

Cyrus
cy...@iepstein.com

http://www.iepstein.com/cyrus.html

 

Re:Turning Cursor Off and On... simple solution


Quote
>That seems like a lot more work then the version I use...  And I've
>never had any problems with it...
>Procedure Cursor(CursorOn: Boolean);
>  Begin
>    {[F-]}
>      If CursorOn then
>         Inline($B4 / 3 /         { mov ah,3 ; read c mode }
>                $B7 / 0 /         { mov bh,0 ; for page 0. }
>                $CD / 16 /        { int 10H ; CRT bios }
>                $80 / $E5 / $DF / { and ch,DFH }
>                $B4 / 1 /         { mov ah,1 ; set c type. }
>                $CD / 16)
>      else
>         Inline($B4 / 3 /         { mov ah,3 ; read c mode }
>                $B7 / 0 /         { mov bh,0 ; for page 0. }
>                $CD / 16 /        { int 10H ; CRT bios }
>                $80 / $CD / $20 / { or ch,20H }
>                $B4 / 1 /         { mov ah,1 ; set c type. }
>                $CD / 16)
>      {[F+]}
>  End;

That works great, and I will start using it. The thing I showed mostly
had nothing to do with the cursor. What the program I posted did was
kill two birds with one stone. It helped make sure that the text mode
was returned to normal after execution of the program, and work with
the cursor. But, I can use yours for turning it on and off during the
execution of the program, which is even better. Thanks for the help!

*************************************************************
Charlie Wiederhold
WiederWeb - http://www.cs.utexas.edu/users/wieder/
wie...@cs.utexas.edu
University of Texas at Austin - Computer Sciences
UT Longhorn Band
Programmer - Sunstorm Interactive

Re:Turning Cursor Off and On... simple solution


Many many of the posts here regard turning the cursor on and off. I
know that this is probably something that many of you already knew,
but I know there are probably some people out there that just for some
reason missed this simple solution. For the most part all people need
to do is turn the cursor off when their program starts, and then turn
it back on after the program exits. This is a pretty simple solution
that works for me, and has simplified my life greatly. It also teaches
a bit of good programming technique for working in text modes.

Here is the source code for a simple program using this method.
The code to turn the cursor off was taken from Timo Salmi's Pascal
FAQ.

PROGRAM CursorOnOff;

USES
  Crt,
  DOS;

VAR
  OrigMode : Integer;
  Regs     : Registers;

BEGIN
  {* Find the original textmode before program exectutes *}
  OrigMode := LastMode;

  {* Set the textmode to 25x80 and clear the screen with white text *}
  {* and a black background just like in DOS *}
  TextMode (3);
  textcolor (7);
  textbackground (0);
  clrscr;

  {* This whole section turns the cursor off. *}
  {* Taken from Timo Salmi's FAQ *}
  fillchar (Regs, sizeof(Regs), 0);  (* Initialize, a precaution *)
  {* ... find out the current cursor size (regs.ch, regs.cl) ... *}
  Regs.AH := $03;
  Regs.BH := $00;    (* page 1, superfluous because of FillChar *)
  intr ($10, Regs);  (* ROM BIOS video driver interrupt *)
  {* ... turn off the cursor without changing its size ... *}
  Regs.AH := $01;                   (* Below are bits 76543210 *)
  Regs.CH := Regs.CH OR $20;  (* Turn on bit 5; $20 = 00100000 *)
  intr ($10, Regs);

  {* Test write to prove it is actually off *}
  writeln ('The Cursor is now off...');
  readln;

  {* Reset the textmode as it was before execution *}
  TextMode (OrigMode);
  textcolor (7);
  textbackground (0);
  clrscr;

  {* Test write to prove it is actually back on *}
  writeln ('The Cursor is now on...');
  readln;
END.

The reason this shows good programming technique, is it resets the
video to whatever mode it was before your program ran. It is mostly
usefull when you want to use higher modes such as 50x80, and want to
reset it back to the standard 25x80.  As for the cursor being turned
back on, that is just a product of reseting the textmode. I don't know
how "clean" that is, but it works.

Hope this helps at least one person who loves programming in Pascal as
much as I do!

Thanks!
*************************************************************
Charlie Wiederhold
WiederWeb - http://www.cs.utexas.edu/users/wieder/
wie...@cs.utexas.edu
University of Texas at Austin - Computer Sciences
UT Longhorn Band
Programmer - Sunstorm Interactive

Other Threads