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 <M8ibYOAdfDB0E...@merlyn.demon.co.uk> of Wed, 27 Aug 1997
15:21:17 in comp.lang.pascal.borland, Dr John Stockton

Quote
<j...@merlyn.demon.co.uk> wrote:
>In article <5tq94r$...@majakka.uwasa.fi> of Mon, 25 Aug 1997 00:30:03 in
>comp.lang.pascal.borland, Timo Salmi <t...@uwasa.fi{omit.No.Emailed.Advert
>i{*word*224}ts}> wrote:
>> 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;

>It might be nice to have an A2':, done a little more generally:

>var PScreen : pointer ; ScrSize : word ;
>const ScrSeg : array [boolean] of word = (SegB000, SegB800) ;
>...  PScreen := Ptr(ScrSeg[LastMode<>Mono], 0) ;
>     ScrSize := 2*Succ(Lo(WindMax))*Succ(Hi(WindMax)) ;
>     FillChar(PScreen^, ScrSize, 0) ;

>This is UNTESTED, but I have used something like it with a Move in
>http://www.merlyn.demon.co.uk/programs/shower.pas, and that works for
>various screen sizes apart from 80*25 - N.B. 80*50 is easy of access.
>The screen size can also be obtained from data in Seg0400.

TS replied :

Quote
> Thanks John. Would you please test it and repost the whole code. I
> would be pleased to include your addition to the item.

This will take longer than I thought :-(

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.

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

So:

My main point was that, with such a FillChar operating on a properly
calculated position (PScreen) and area (2*Rows*Cols), one can clear any
text screen.

The code came from memories of my SHOWER.PAS; I now see, testing in a
bigger program, that use of Crt.WindMax is not sufficient with TVTOYS to
change modes, though it seems OK in (AFAIR) 40*25, 80*25, 80*50.  Is
Peter Brandstrom still about, I wonder?

I'll have to try the locations in Seg0040, which might do for Mode,
Rows, Cols - alas, I have limited books here, and my only printed
reference is that for the Amstrad PPC640, which is fairly compatible.

But it will take a little longer.

--
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.
  Correct 4-line sig separator is as above, a line comprising "-- " (SoRFC1036)
  Before a reply, quote with ">" / "> ", known to good news readers (SoRFC1036)

 

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


In article <AYjUBGAXhHC0E...@merlyn.demon.co.uk> of Sat, 30 Aug 1997
20:45:27 in comp.lang.pascal.borland, Dr John Stockton

Quote
<j...@merlyn.demon.co.uk> wrote:

In article <M8ibYOAdfDB0E...@merlyn.demon.co.uk> of Wed, 27 Aug 1997
15:21:17 in comp.lang.pascal.borland, Dr John Stockton

Quote
<j...@merlyn.demon.co.uk> wrote:
>In article <5tq94r$...@majakka.uwasa.fi> of Mon, 25 Aug 1997 00:30:03
>>in comp.lang.pascal.borland, Timo Salmi
>><t...@uwasa.fi{omit.No.Emailed.Adverti{*word*224}ts}> wrote:
>> A2: The alternative below writes by direct screen writing a null
>>character to the ordinary 80 x 25 screen and drawing black on black.
>> ...

>It might be nice to have an A2':, done a little more generally:
>> ...
> ...
>My main point was that, with such a FillChar operating on a properly
>calculated position (PScreen) and area (2*Rows*Cols), one can clear any
>text screen.
> ...

This unit seems OK, having been tried in a fair sample of the modes that
TVTOYS and Font8x8 give on a Tandon PacII PC of ?1992 - however, I'd ask
that a few of you scrutinise it and check it on other hardware.
WfWg3.11 would not let it be tested in a windowed DOS box, changing to
full screen.

unit TEST_CLS ;
interface
procedure TestCls ;
implementation

{$IFNDEF VER70}
const Seg0040 = $40 ; SegB000 = $B000 ; SegB800 = $B800 ;
{$ENDIF}

function ThisMode : byte ;
begin ThisMode := Mem[Seg0040:$49] end {ThisMode} ;

function Monochrome : boolean ;
const Mono = {Crt.Mono} 7 ;
MonoSet = [Mono, $56, $57] { $56,$57 are mono on **MY** Tandon PC } ;
begin Monochrome := ThisMode in MonoSet end {Monochrome} ;

procedure TestCls ;
var PScreen : pointer ; ScrSize, ScrSeg : word ; Cols : word ; Rows :
byte ;
begin
if Monochrome then ScrSeg := SegB000 else ScrSeg := SegB800 ;
  PScreen := Ptr(ScrSeg, 0) ;
  Cols := MemW[Seg0040:$4A] ; Rows := Succ(Mem[Seg0040:$84]) ;
  ScrSize := 2 * Cols * Rows ;
  FillChar(PScreen^, ScrSize, 0) ;
  { Writeln(^M'  ScrSeg=', ScrSeg, '':5, Cols, ' * ', Rows,
    ' *2= ', ScrSize, MemW[Seg0040:$4C]:7) ; }
  end {TestCls} ;

BEGIN ;
END.

Again - peoples, please test it in whatever screen modes are safely
accessible to you, and report!  TestCls could be compacted by using
fewer intermediate variables; only ScrSeg seems really needed.  On my
Tandon PC, $4C gives bigger than expected readings, so I don't use it.

--
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.

Other Threads