Board index » delphi » Clearing Screen Without Using CRT Unit?

Clearing Screen Without Using CRT Unit?

I am a beginner and am using Turbo Pascal 7.0 with DOS on a computer with a
processor speed of 400 MHz.  I simply would like to know how to clear the
screen without using the CRT unit (and thus incurring the "divide by 0" error
message).  In his FAQs (ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip), Timo Salmi
suggests three simple solutions. I have tried all three but cannot get any to
work.

I'll address his first suggestion for clearing the screen, and if someone can
help me make it work, I won't worry about the other two.

Below is a short program that I wrote to test the ClrScreen procedure suggested
in Timo Salmi's FAQs (#117.)  Calling this procedure does indeed clear the
screen, but then I cannot write anything to the screen after that.  According
to Borland's Turbo Pascal "Language Guide" (p. 144), the CRT unit's ClrScr
procedure should clear the screen and also return the cursor to the upper
left-hand corner.  Perhaps Salmi's substitution does not do everything that
ClrScr does.

I have inserted comments in the following to show where Salmi's lines begin and
end.  All that I try to do in this little program is to call the ClrScreen
procedure and then write a new line on the screen.  The output screen dutifully
goes black but then the new line of text does not appear on the screen.  In
fact, the output screen remains blank for all programs until I exit the
compiler and restart it.  What else must I do to write to the screen after
calling the ClrScreen procedure?

Many thanks!
Pat

program clrscreen_tst;

(*Salmi's code begins here.*)

(* 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;

 (*Salmi's code ends here.*)

  begin (*main program*)
        ClrScreen;
        Writeln ('Now that the screen has been cleared, can you read this?');
  end. (*main program*)

 

Re:Clearing Screen Without Using CRT Unit?


JRS:  In article <19990508154541.07989.00000...@ng-cl1.aol.com> of Sat,
8 May 1999 19:45:41 in news:comp.lang.pascal.borland, MajicPat

Quote
<majic...@aol.com> wrote:
>I am a beginner and am using Turbo Pascal 7.0 with DOS on a computer with a
>processor speed of 400 MHz.  I simply would like to know how to clear the
>screen without using the CRT unit (and thus incurring the "divide by 0" error
>message).  In his FAQs (ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip), Timo Salmi
>suggests three simple solutions. I have tried all three but cannot get any to
>work.

>I'll address his first suggestion for clearing the screen, and if someone can
>help me make it work, I won't worry about the other two.

>Below is a short program that I wrote to test the ClrScreen procedure suggested
>in Timo Salmi's FAQs (#117.)  Calling this procedure does indeed clear the
>screen, but then I cannot write anything to the screen after that.  According
>to Borland's Turbo Pascal "Language Guide" (p. 144), the CRT unit's ClrScr
>procedure should clear the screen and also return the cursor to the upper
>left-hand corner.  Perhaps Salmi's substitution does not do everything that
>ClrScr does.

On my PII/300 PC in a DOS box, your program does what you want.  What
system software are you using?  Which DOS?  Is it a Win98 machine
emulating DOS?  Is it colour?

What happens if you write characters to the odd or even positions of the
screen area?  One should be gaudy, the other legible.

If you don't mind the cursor ending up on the last line rather than the
first,
     for J := 1 to NumberOfLines do Writeln ;
will clear the screen quickly enough for most purposes at 400 MHz (but
maybe not on the original IBM PC!).

A GoAtXY (TSFAQP#124) should put the cursor at the top, or a direct Int
$10 *should* work:

procedure GoXY(X, Y : byte) { Position Cursor } ; assembler ;
asm  mov ah,$02 ; mov bh,0 ; mov dh,Y ; mov dl,X ;
  { Michael Kennedy says some old systems may need Push BP, Pop BP }
  push BP ; int $10 ; pop BP  end {GoXY} ;

BTW, I expect that your program IS writing to the screen, but in black-
on-black, as alluded to in TSFAQP.

In Timo's code, one should use not FillChar but FillWord, to fill the
screen with character-attribute pairs, where the character is #$20=space
and the attribute is what it needs to be.  The snag is that FillWord is
not available as standard, though it may be easy to write (PS?).

Try Timo's, but filling with #$20 bytes - it should clear the screen to
green, and you may be able to write on it.

When you do find out what the real problem was, please post the
explanation here.

--
 ? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
  Web <URL: http://www.merlyn.demon.co.uk/> - TP/BP/&c. FAQqish topics & links.
  Timo's TurboPascal <A HREF="ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip">FAQ</A>.
  <A HREF="http://www.merlyn.demon.co.uk/clpb-faq.txt">Mini-FAQ</A> of c.l.p.b.

Re:Clearing Screen Without Using CRT Unit?


In article <Qe9aqyAgxLN3E...@merlyn.demon.co.uk>, Dr John Stockton

Quote
<j...@merlyn.demon.co.uk> writes:
>On my PII/300 PC in a DOS box, your program does what you want.  What
>system software are you using?  Which DOS?  Is it a Win98 machine
>emulating DOS?  Is it colour?

Hello John:
    Many thanks for your reply.  You have a lot of ideas that I am looking
forward to trying out tomorrow.  To answer your questions about my setup:
     I am running Windows 98, and in order to make the Turbo Pascal compiler
work correctly, I must exit Windows 98 and go into MS-DOS mode.  I could not
simply run the program while still in Windows, because the display didn't look
right.  That is, many of the characters on the screen were in "gibberish."  And
finally, yes, I am running in color here.

Quote
>What happens if you write characters to the odd or even positions of the
>screen area?  One should be gaudy, the other legible.

    I'm not sure exactly what you mean by the above question.  Other than the
display problem in Windows 98, I have not had any problems with onscreen
characters. In the MS-DOS mode, everything looks good.  After reading your
question, I went back and checked out the "bad" Win98 display of the TP
compiler.  It was not exactly every other character that was illegible, but
indeed there were no two illegible characters in a row (if *that* means
anything.)  The more I exited the compiler and reentered it in Win98, the worse
the display got.

    Again, John, thanks for your generous reply.  I'll give your suggestions a
try tomorrow!

Pat

Re:Clearing Screen Without Using CRT Unit?


Dr John Stockton decided to regale us with

Quote

>In Timo's code, one should use not FillChar but FillWord, to fill the
>screen with character-attribute pairs, where the character is #$20=space
>and the attribute is what it needs to be.  The snag is that FillWord is
>not available as standard, though it may be easy to write (PS?).

There is one problem in that the T/BP FillChar allows the value to be
written to the variable to be any type - indeed an identically
rewritten FillChar using the specifications in the Help File will not
compile as "value does not have a type".

If the user is content to convert what they want for each word to fill
the generic variable Dest, then the following is fine.

As with FillChar, *no* checking is done so it is up to the user to make
sure that Count of *words* is correct.

Procedure FillWord(var Dest; Count, what:word); assembler;
asm
   LES DI,Dest
   MOV CX,Count
   MOV AX,What
   CLD
   REP STOSW
end;

--
Pedt

Re:Clearing Screen Without Using CRT Unit?


   Rather than address the problems you're having with the workarounds,
I'll ask why you consider "curing the symptom" the way to go?  Avoiding
the use of the CRT Unit is hardly justified with the many viable fixes to
the RTE 200 problem.  Building a workaround for each of the useful CRT
functions will be a miserable task - and it's something you really don't
have to do!  Just get one of the appropriate fixes (see the FAQ) and
apply it to your system...
   And since you're a beginner, this is a good time to learn that "curing
the symptom" is seldom the way to tackle the problem.  Doing so
invariably creates more work and difficulty than actually fixing the
problem.  Here you have already encountered the issue, and I assure you
it'll get worse...when you build your first "menu program" and find you
can't use ReadKey, for example.
Quote
> I am a beginner and am using Turbo Pascal 7.0 with DOS on a computer with a
> processor speed of 400 MHz.  I simply would like to know how to clear the
> screen without using the CRT unit (and thus incurring the "divide by 0" error
> message).  In his FAQs (ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip), Timo Salmi
> suggests three simple solutions. I have tried all three but cannot get any to
> work.

> I'll address his first suggestion for clearing the screen, and if someone can
> help me make it work, I won't worry about the other two.

Re:Clearing Screen Without Using CRT Unit?


JRS:  In article <FQltvGAiWSN3Y...@pedt.demon.co.uk> of Sun, 9 May 1999
07:05:22 in news:comp.lang.pascal.borland, Pedt Scragg

Quote
<newsmas...@pedt.demon.co.uk> wrote:
>There is one problem in that the T/BP FillChar allows the value to be
>written to the variable to be any type - indeed an identically
>rewritten FillChar using the specifications in the Help File will not
>compile as "value does not have a type".

>If the user is content to convert what they want for each word to fill
>the generic variable Dest, then the following is fine.

>As with FillChar, *no* checking is done so it is up to the user to make
>sure that Count of *words* is correct.

>Procedure FillWord(var Dest; Count, what:word); assembler;
>asm
>   LES DI,Dest
>   MOV CX,Count
>   MOV AX,What
>   CLD
>   REP STOSW
>end;

Thanks; I have added to pas-opts.htm :

Routine posted 1999-05-09 in c.l.p.b by Pedt Scragg :
    procedure FillWord(var Dest ; Count, What : word) ; assembler ;
    asm  LES DI,Dest ; MOV CX,Count ; MOV AX,What ; CLD ; REP STOSW  end ;
This should be useful in particular for filling the screen buffer, where
What = (TextAttr shl 8) + Ord(Character). It can be tested with, for
example,
    FillWord(Ptr(SegB800, 0)^, 2000, ($2400+Ord('*'))) ;

I must update some programs with it.  

--
 ? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
  Web <URL: http://www.merlyn.demon.co.uk/> - TP/BP/&c. FAQqish topics & links.
  Timo's TurboPascal <A HREF="ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip">FAQ</A>.
  <A HREF="http://www.merlyn.demon.co.uk/clpb-faq.txt">Mini-FAQ</A> of c.l.p.b.

Re:Clearing Screen Without Using CRT Unit?


Quote
> Rather than address the problems you're having with the workarounds,
>I'll ask why you consider "curing the symptom" the way to go?

    I agree.  I'm game.  Let's go for the fix.  

    Which fix do you recommend as being the easiest to install for a person
just beginning to learn Pascal?  The fixes listed  in the FAQs (which I did
read before posting any messages here) all seemed equally daunting and tough to
understand.

      I would also like to hear from any other Turbo Pascal newbies as to their
success  in using  the recommended fixes.

Pat  

Re:Clearing Screen Without Using CRT Unit?


Quote
>If you don't mind the cursor ending up on the last line rather than the
>first,
>     for J := 1 to NumberOfLines do Writeln ;
>will clear the screen quickly enough for most purposes at 400 MHz (but
>maybe not on the original IBM PC!).

>A GoAtXY (TSFAQP#124) should put the cursor at the top, or a direct Int
>$10 *should* work:

Hi John:

     Your suggestion of the looped Writelns along with GoAtXY (with the Tsuntg
unit) worked fine as a substitute for ClrScr for my simple  purposes.  Many
thanks!

Pat

Re:Clearing Screen Without Using CRT Unit?


Quote
MajicPat (majic...@aol.com) wrote:

:     Which fix do you recommend as being the easiest to install for a person
: just beginning to learn Pascal?  The fixes listed  in the FAQs (which I did
: read before posting any messages here) all seemed equally daunting and tough to
: understand.

Have you checked my list in the Runtime Error 200 FAQ ?
See my homepage.

--
Klaus Hartnegg, Institut fuer Biophysik, Hansa-Strasse 9a, D-79104 Freiburg
hartn...@uni-freiburg.de   http://www.brain.uni-freiburg.de/~klaus/

Re:Clearing Screen Without Using CRT Unit?


Quote
> > Rather than address the problems you're having with the workarounds,
> >I'll ask why you consider "curing the symptom" the way to go?

>     I agree.  I'm game.  Let's go for the fix.  

>     Which fix do you recommend as being the easiest to install for a person
> just beginning to learn Pascal?  The fixes listed  in the FAQs (which I did
> read before posting any messages here) all seemed equally daunting and tough to
> understand.

   My choice was to use Roger E. Donais' RDelay Unit, which only requires
inserting "RDelay" before "CRT" in the Uses statement...like this:

Uses RDelay,CRT,Printer;

   This has worked quite nicely for all my programs, without any
difficulty.

Re:Clearing Screen Without Using CRT Unit?


Quote
>>     Which fix do you recommend as being the easiest to install for a person
>> just beginning to learn Pascal?  The fixes listed  in the FAQs (which I did
>> read before posting any messages here) all seemed equally daunting and
>tough to
>> understand.

>   My choice was to use Roger E. Donais' RDelay Unit, which only requires
>inserting "RDelay" before "CRT" in the Uses statement...like this:

>Uses RDelay,CRT,Printer;

>   This has worked quite nicely for all my programs, without any
>difficulty.

Hi Mike:

     Many thanks for the advice.  I already had the Roger E. Donais info
downloaded but I had run into snags trying to get it set up to run.
      After some fooling around with the files, I discovered that my problems
were due to a lack of file-management "skills" more than anything else.  In
order to compile the RDelay.pas, one needs also to have Donais's Util.pas unit
compiled.  In order to compile the Util.pas, one also needs to have Util01.pas
on hand.  My problem was in not fully understanding that the compiler would
only look in the *active* directory for those files.  I kept thinking that it
should be looking among *all* the files in the TP folder ... that the
designated active directory only applied to when you were "manually" opening
files with the compiler.  Not so. ( An elementary mistake?  You bet.  But I'll
also bet that I'm not the only beginner who has committed this screw-up, so
that's why I'm elaborating on it here.)
      After moving the compiled .tpu files to the Units folder, it now appears
that placing RDelay before CRT in the uses clause does indeed eliminate the
Error 200 message.  I haven't given it a thorough test yet, but it sure looks
encouraging thus far.

       Many thanks, Mike!

Pat

Other Threads