Board index » delphi » How can I clear the screen without the Crt unit?

How can I clear the screen without the Crt unit?

In article <3401f2a9.109904...@news.southeast.net>, rdon...@southeast.net

Quote
(R.E.Donais) wrote:

=>>
=>>The best way is writing directly into the graphic memory.
=>
=>AFAIK, writing to graphic memory has no effect on a text
=>screen.

pendandic. write to $b800 or $b000 then.

BEvyn.

--
disclaimer

not only did i not post this i have never seen any of these letters before in my life.

these opinions represent no one least of all myself.

 

Re:How can I clear the screen without the Crt unit?


Quote
Hentrich <hentr...@frss01.fr.bosch.de> wrote:
>Timo Salmi wrote:
>>   var regs : registers;
>>   begin
>>     FillChar (regs, SizeOf(regs), 0);
>>     regs.ah := $00;
>>     regs.al := $03;
>>     Intr ($10, regs);
>>   end;  (* cls *)
>The way, using "Registers" from the unit "dos" is very unusable.
>It's too slow. All registers are saved, the registers are set to the
>values in the var "registers" die interrupt is executed and all the
>stuff back.

I just cant help jumping in here. How can you say that using resgisters from the
dos unit is slow, and then present "asm int end;" as a faster way??  The
difference between the two are, if my calculations are correct, 8 cycles.

If speed is important, try this (Does not work in monochrome) :

Procedure AsmClrscr;Assembler;
Asm
    mov ax,SEGb800
    mov cx,1000
    xor di,di
    mov es,ax
    db 66h
    xor ax,ax
    db 66h
    rep stosw
End;

--
 Kim Robert Blix  ( kimrb...@online.no  &  http://home.sn.no/~kblix )

 "How do you shoot the devil in the back?"
 "What if you miss?" -Verbal Kint
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Re:How can I clear the screen without the Crt unit?


Scott Earnest <set...@ix.netcom.com> once said:

Quote
>Kim Robert Blix wrote:
>> I just cant help jumping in here. How can you say that using resgisters from the
>> dos unit is slow, and then present "asm int end;" as a faster way??  The
>> difference between the two are, if my calculations are correct, 8 cycles.

>Your calculations are way off.  First, you have a fillchar(), two

[Dump snipped]

ooookey, So i missed by a 100 cycles or so :) I didnt really think it was THAT
long,and I have a bad habit of not checking things before I speak.

Quote
>> If speed is important, try this (Does not work in monochrome) :

[My clrscr snipped]

Quote
>No local variables, so WYSIWTPC (What you see is what TP compiles ;-),

Exqueze me ? :) Abbrivations are nice and all but what does that mean? :)

Quote
>more or less.  Far less code to run.  BTW, you could make this more
>global by storing the active video segment in a global variable.  Also
>only works for an 80x25 screen, page 0.

Jupps, I know.. Alter the value in CX as needed :) (I never use more then one
page anyway)

Quote
>Why not something like:

[Snip your clrscr]

Quote
>Over all, I still find it a bit silly to be trying to optimize screen
>clearing routines for textmode anyway.  Realistically, just how often is
>it needed?  It is hardly likely to be a great bottleneck in a program.

I dont know about you, but I have always enjoyed twinking things into running
faster :)..  You are correct though, if cls'ing a textmode screen is the
bottleneck, its time to sit back and take a look at your program.

Quote
>Scott Earnest        | We now return you to our regularly |

--
 Kim Robert Blix  ( kimrb...@online.no  &  http://home.sn.no/~kblix )

 "How do you shoot the devil in the back?"
 "What if you miss?" -Verbal Kint
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Re:How can I clear the screen without the Crt unit?


Quote
Kim Robert Blix wrote:
> >> If speed is important, try this (Does not work in monochrome) :
> [My clrscr snipped]

> >No local variables, so WYSIWTPC (What you see is what TP compiles ;-),
>                                   ^    ^   ^   ^  ^    ^^ ^
> Exqueze me ? :) Abbrivations are nice and all but what does that mean? :)

Ummm, check the text in parentheses -- I spelled it out.  ;-)

Quote
> >more or less.  Far less code to run.  BTW, you could make this more
> >global by storing the active video segment in a global variable.  Also
> >only works for an 80x25 screen, page 0.

> Jupps, I know.. Alter the value in CX as needed :) (I never use more then one
> page anyway)

Never say never, you might just need it some time.  ;-)

Quote
> >Why not something like:
> [Snip your clrscr]

> >Over all, I still find it a bit silly to be trying to optimize screen
> >clearing routines for textmode anyway.  Realistically, just how often is
> >it needed?  It is hardly likely to be a great bottleneck in a program.

> I dont know about you, but I have always enjoyed twinking things into running
> faster :)..  You are correct though, if cls'ing a textmode screen is the
> bottleneck, its time to sit back and take a look at your program.

True.  But there's also something to be said for relatively small,
elegant code which gets the job done *and* is flexible.  :-)  Yeah,
speed's good and I like the challenge of optimizing, but some things
just don't need it -- which allows more time for the things that do.

Quote
> >Scott Earnest        | We now return you to our regularly |

> --
>  Kim Robert Blix  ( kimrb...@online.no  &  http://home.sn.no/~kblix )

>  "How do you shoot the devil in the back?"
>  "What if you miss?" -Verbal Kint
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
Scott Earnest        | We now return you to our regularly |
set...@ix.netcom.com | scheduled chaos and mayhem. . . .  |

Re:How can I clear the screen without the Crt unit?


Quote
Timo Salmi wrote:

> 117. *****
>  Q: How can I clear the screen without the Crt unit?

>  A: Take a Cleenex and rub :-). Or turn off the computer.

>  A2: The alternative below writes by direct screen writing a null
> character to the ordinary 80 x 25 screen and drawing black on black.
>   (* Clear the 80 x 25 screen without the Crt unit *)
>   procedure ClrScreen;
>   type ScreenType = array [0..1999] of array [0..1] of byte;
>   var ColorScreen : ScreenType Absolute $B800:$0000;
>   begin
>     FillChar (ColorScreen, SizeOf(ColorScreen), 0);
>   end;

>  A3: There are also other approaches. These ones use the ROM BIOS to
> set the video mode and at the same time clear the screen.
>   (* Set a 25*80 text mode and clear screen, no Crt unit required *)
>   procedure CLS;
>   var regs : registers;
>   begin
>     FillChar (regs, SizeOf(regs), 0);
>     regs.ah := $00;
>     regs.al := $03;
>     Intr ($10, regs);
>   end;  (* cls *)

>   (* Set a 25*40 text mode and clear screen, no Crt unit required *)
>   procedure CLS40;
>   var regs : registers;
>   begin
>     FillChar (regs, SizeOf(regs), 0);
>     regs.ah := $00;
>     regs.al := $01;
>     Intr ($10, regs);
>   end;  (* cls40 *)

>    All the best, Timo

There is one important approach missing:

If ANSI.SYS is installed,

write(#27'[2J');

will do it (but *only* without Crt).
This has the advantage that
- it won't clear the screen when redirected (but when looking at the
  result, it will)
- it works even if the screen where output goes is not the screen
  of the computer the program is running on (or maybe it's graphics
  mode, but text supported by an ANSI driver replacement)

It has the disatvantage that
- it doesn't work without ANSI.SYS
- it doesn't work with crt unit
- it's slow :-)

BTW, in plain DOS, type cls > file.txt, and look what file.txt looks
like! (possibly works only with ANSI.SYS installed, and not with all
DOS versions...)

Ahh, that brings me to the following:

procedure TheUltimateClearScreen;
        { needs unit Dos }
 begin
  exec(GetEnv('COMSPEC'), '/C CLS);
 end;

This should work with any DOS (except perhaps for very old versions),
doesn't depend on any installed drivers, and works independent of
whether Crt is included or not :-)

Re:How can I clear the screen without the Crt unit?


Dr John Stockton (j...@merlyn.demon.co.uk) wrote:

Quote
> SegB000, SegB800 are variables, not constants, so they cannot be used as
> in ScrSeg above; but "if Cond then Seg := SegB000 else Seg := SegB800 ;
> PScreen := Ptr(Seg, 0)" will fix that easily enough.

One, somewhat more complicated, way of doing it would be

  PSeg : array [boolean] of ^Word = (@SegB800, @SegB000);

to be accessed by

  PScreen := Ptr(PSeg[LastMode=Mono]^,0)

(not tested).

Quote
> But Cond needs to use ThisMode (which does not AFAIR exist) rather than
> LastMode - it's tempting to assume mono or colour throughout.

Don't be misled by the strange name, but LastMode is in fact "ThisMode",
as is shown by the following program:

uses crt;
begin
  textmode(3);
  writeln(lastmode);
  readln;
  textmode(0);
  writeln(lastmode)
end.

Looking at the Crt source shows that LastMode is updated in the procedure
CrtSetup which is called at initialization and in TextMode *after* setting
the mode.

I'm wondering why it's called LastMode at all. The only reason I can think
of is its use to switch back from graphics mode to text mode, where it's
indeed the last text mode. So you can say, it's the last text mode that
was set (though Crt), regardless if it's still active, or a graphics mode
has been set.

One further remark: I think it might be wise not to fill all bytes with 0,
but to set the attribute bytes to 7 (or so), because BIOS output does not
use the TextAttr value as the current attribute, but leaves the attribute
unchanged. (And when scrolling, it uses the current attribute of the first
character of the last line for the whole new line, or something equally
strange.) Therefore, setting all attribute bytes to 0 will cause all BIOS
output to be invisible.

Apart from all that, I still can't see any reason for such rather
compilcated code instead of using a simple BIOS interrupt for its
designed function...

--
Frank Heckenbach, Erlangen, Germany, heck...@mi.uni-erlangen.de
Internet links:        http://home.pages.de/~fjf/links.htm
Turbo Pascal programs: http://home.pages.de/~fjf/programs.htm

Re:How can I clear the screen without the Crt unit?


Quote
Christopher Eltschka wrote:
> There is one important approach missing:

> If ANSI.SYS is installed,

> write(#27'[2J');

> will do it (but *only* without Crt).

program clear_with_ANSI;

uses
  Crt;

var
  con : text;

begin
  writeln ('Going to ANSI-clear the screen.');
  readln;
  assign (con,'');
  rewrite (con);
  write (con,#27'2J');
  writeln ('Done!');
  close (con);
end.

Quote
> This has the advantage that
> - it won't clear the screen when redirected (but when looking at the
>   result, it will)

This is true (but your part in parentheses isn't necessarily true, since
not all viewers will use standard output to display files).  One tricky
way that *might* work is to allocate a handle to the standard error
device, then write to that -- it doesn't follow the redirection of
standard output.

Quote
> - it works even if the screen where output goes is not the screen
>   of the computer the program is running on (or maybe it's graphics
>   mode, but text supported by an ANSI driver replacement)

Maybe I'm tired, but I'm not following that.

Quote
> It has the disatvantage that
> - it doesn't work without ANSI.SYS
> - it doesn't work with crt unit
> - it's slow :-)

> BTW, in plain DOS, type cls > file.txt, and look what file.txt looks
> like! (possibly works only with ANSI.SYS installed, and not with all
> DOS versions...)

> Ahh, that brings me to the following:

> procedure TheUltimateClearScreen;
>         { needs unit Dos }
>  begin
>   exec(GetEnv('COMSPEC'), '/C CLS);
>  end;

Well now, *that* is slow!  :-)  Running an entire program to clear the
screen?

Quote
> This should work with any DOS (except perhaps for very old versions),
> doesn't depend on any installed drivers, and works independent of
> whether Crt is included or not :-)

--
Scott Earnest        | We now return you to our regularly |
set...@ix.netcom.com | scheduled chaos and mayhem. . . .  |

Re:How can I clear the screen without the Crt unit?


In article <5ueklb$c6...@rznews.rrze.uni-erlangen.de> of Mon, 1 Sep 1997
14:49:15 in comp.lang.pascal.borland, Frank Heckenbach <heck...@mi.uni-

Quote
erlangen.de> wrote:
>Dr John Stockton (j...@merlyn.demon.co.uk) wrote:

>> SegB000, SegB800 are variables, not constants, so they cannot be used as
>> in ScrSeg above; but "if Cond then Seg := SegB000 else Seg := SegB800 ;
>> PScreen := Ptr(Seg, 0)" will fix that easily enough.

>One, somewhat more complicated, way of doing it would be
>  PSeg : array [boolean] of ^Word = (@SegB800, @SegB000);
>to be accessed by
>  PScreen := Ptr(PSeg[LastMode=Mono]^,0)
>(not tested).

Clever.  It does at least compile (but requires Crt, see Subject line!),

Quote

>> But Cond needs to use ThisMode (which does not AFAIR exist) rather than
>> LastMode - it's tempting to assume mono or colour throughout.

>Don't be misled by the strange name, but LastMode is in fact "ThisMode",
>as is shown by the following program:

>uses crt;
>begin
>  textmode(3);
>  writeln(lastmode);
>  readln;
>  textmode(0);
>  writeln(lastmode)
>end.

Agreed :=( .

Quote
>Looking at the Crt source shows that LastMode is updated in the procedure
>CrtSetup which is called at initialization and in TextMode *after* setting
>the mode.

>I'm wondering why it's called LastMode at all. The only reason I can think
>of is its use to switch back from graphics mode to text mode, where it's
>indeed the last text mode. So you can say, it's the last text mode that
>was set (though Crt), regardless if it's still active, or a graphics mode
>has been set.

In that case, the on-line help is wrong :
Quote
> Specifying TextMode(LastMode) causes the last active text mode to be
> re-selected.

since that only applies if in a non-text mode.  If in a text mode, it
reselects the current mode.

Quote
>One further remark: I think it might be wise not to fill all bytes with 0,
>but to set the attribute bytes to 7 (or so), because BIOS output does not
>use the TextAttr value as the current attribute, but leaves the attribute
>unchanged. (And when scrolling, it uses the current attribute of the first
>character of the last line for the whole new line, or something equally
>strange.) Therefore, setting all attribute bytes to 0 will cause all BIOS
>output to be invisible.

For that, we'd need either FillWord - doubtless easy enough in ASM - or
to set all bytes to 7 which would fill the screen with dots.

Quote
>Apart from all that, I still can't see any reason for such rather
>compilcated code instead of using a simple BIOS interrupt for its
>designed function...

Originally, I was using Move rather than FillChar, in order to
save/restore the screen; and I doubt if there's a BIOS call for that.  I
didn't find a BIOS call specifically to clear the screen - do you mean
Int 10/06 (or 10/07) with AL=0 or AL large?

BTW, this combination :
        NNTP-Posting-Host: skylla.mi.uni-erlangen.de
        X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
does not generate correct reference lines in headers, Frank  :-(  .

--
John Stockton, Surrey, UK.    j...@merlyn.demon.co.uk    Turnpike v1.12    MIME.
  Web URL: http://www.merlyn.demon.co.uk/ -- includes FAQqish topics and links.

Re:How can I clear the screen without the Crt unit?


Dr John Stockton (j...@merlyn.demon.co.uk) wrote:

Quote
> >One, somewhat more complicated, way of doing it would be
> >  PSeg : array [boolean] of ^Word = (@SegB800, @SegB000);
> >to be accessed by
> >  PScreen := Ptr(PSeg[LastMode=Mono]^,0)
> >(not tested).

> Clever.  It does at least compile (but requires Crt, see Subject line!),

Oh yes, sorry. But then, of course, the discussion about LastMode vs.
ThisMode is pointless, too...

Quote
> In that case, the on-line help is wrong :

Wouldn't be the only place... :-(

But at least the German BP7 help says (translated back by me):

: On every call to TextMode, the current video mode is saved in LastMode.

... which is not completely precise, but correct if one assumes the saving
to happen after setting the mode.

: At the start of the program, LastMode is set to the currently active
: video mode.

... which is definitely correct.

(* BTW: Crt itself does not check LastMode, but the BIOS value at $40:$49
(AFAIR) to decide whether to use SegB000 or SegB800 -- seems it doesn't
trust its own variables... ;-) *)

Quote
> For that, we'd need either FillWord - doubtless easy enough in ASM - or
> to set all bytes to 7 which would fill the screen with dots.

I'd prefer the former... ;-)

Quote
> and I doubt if there's a BIOS call for that.  I
> didn't find a BIOS call specifically to clear the screen - do you mean
> Int 10/06 (or 10/07) with AL=0 or AL large?

Yes, AFAIK, this is documented to clear the window.

Quote
> BTW, this combination :
>         NNTP-Posting-Host: skylla.mi.uni-erlangen.de
>         X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
> does not generate correct reference lines in headers, Frank  :-(  .

I heard so, and I experienced more bugs in TIN. I'm planning to change to
another newsreader when I get around to it, but I've had so many really
important things to do in the last time... :-(

--
Frank Heckenbach, Erlangen, Germany, heck...@mi.uni-erlangen.de
Internet links:        http://home.pages.de/~fjf/links.htm
Turbo Pascal programs: http://home.pages.de/~fjf/programs.htm

Re:How can I clear the screen without the Crt unit?


On 25 Aug 1997 00:30:03 +0300,

Quote
t...@uwasa.fi{omit.No.Emailed.Adverti{*word*224}ts} (Timo Salmi) wrote:
>117. *****
> Q: How can I clear the screen without the Crt unit?

Anything in particular wrong with this simple code?
it works for me.
-------------------------------------------------------------------------------------
Procedure cls; Assembler;
Asm
  MOV AH,0Fh
  INT 10h
  MOV AH,0
  INT 10h
end;

begin
  cls;
end.

Re:How can I clear the screen without the Crt unit?


Quote
Frank Wood wrote:
> I'm a bit out of practice now, but what's wrong with:-

>         write(#12);

> This sends a form feed character to the output device.

Feeds a page if you send it to the printer, accomplishes nothing if send
to standard output.  Note that the topic is about clearing the
*screen*.  ;-)

--
Scott Earnest        | We now return you to our regularly |
set...@ix.netcom.com | scheduled chaos and mayhem. . . .  |

Re:How can I clear the screen without the Crt unit?


In article <340df359.52169...@news.dircon.co.uk>,

Quote
Frank Wood <wood...@dircon.co.uk> wrote:

:I'm a bit out of practice now, but what's wrong with:-
:       write(#12);
:This sends a form feed character to the output device.

Yes, that's exactly what it does. Writes a formfeed character to the
output device. Now why would that clear the screen? Try it and
you'll see that it does not.

   All the best, Timo

....................................................................
Prof. Timo Salmi   Co-moderator of news:comp.archives.msdos.announce
Moderating at ftp:// & http://garbo.uwasa.fi archives  193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa
mailto:t...@uwasa.fi  <http://www.uwasa.fi/~ts>  ; FIN-65101,  Finland

Spam foiling in effect.  My email filter autoresponder will return a
required email password to users not yet in the privileges database.

Re:How can I clear the screen without the Crt unit?


Quote
CBongChan wrote:
> On one of the 26+ messages on this topic, Frank Heckenbach wrote:
> >Apart from all that, I still can't see any reason for such rather
> >compilcated code instead of using a simple BIOS interrupt for its
> >designed function...

> Using his reasoning, we might as well ask:
>   What's wrong with using Clrscr from the CRT unit anyway?

Crt is an odd unit.  Because of the way it's written, if you use the
unit -- you don't even have to call any functions from it, since calls
are made from the initialization section -- the *entire* unit is linked
in.  It's a bit obnoxious when you're trying to write a small, compact
program.

Also, by default, the Crt unit latches the input and output and
redirects them, which requires one code correction or another to fix.

--
Scott Earnest        | We now return you to our regularly |
set...@ix.netcom.com | scheduled chaos and mayhem. . . .  |

Re:How can I clear the screen without the Crt unit?


Quote
>From: Scott Earnest <set...@ix.netcom.com>
>Date: Fri, 05 Sep 1997 05:52:57 -0400
>Message-id: <340FD679.13994...@ix.netcom.com>

>CBongChan wrote:

>> On one of the 26+ messages on this topic, Frank Heckenbach wrote:
>> >Apart from all that, I still can't see any reason for such rather
>> >compilcated code instead of using a simple BIOS interrupt for its
>> >designed function...

>> Using his reasoning, we might as well ask:
>>   What's wrong with using Clrscr from the CRT unit anyway?

>Crt is an odd unit.  Because of the way it's written, if you use the
>unit -- you don't even have to call any functions from it, since calls
>are made from the initialization section -- the *entire* unit is linked
>in.  It's a bit obnoxious when you're trying to write a small, compact
>program.

Oh Wow!  I didn't know that!  One can always learn something from this
newsgroup.

Re:How can I clear the screen without the Crt unit?


Quote
Timo Salmi wrote:

> In article <340df359.52169...@news.dircon.co.uk>,
> Frank Wood <wood...@dircon.co.uk> wrote:
> :I'm a bit out of practice now, but what's wrong with:-
> :  write(#12);
> :This sends a form feed character to the output device.
> Yes, that's exactly what it does. Writes a formfeed character to the
> output device. Now why would that clear the screen? Try it and
> you'll see that it does not.

True... but is the screen not an output device? hehe Sorry, but I had
to put that one in there Timo... You have to be clear on the type of
output device that is being used I suppose... ;-)

Other Threads