Board index » delphi » Dumping the screen to a file

Dumping the screen to a file

Hi, here's what I'm trying to do.

I need a way of dumping the screen to a file (like 'int 5' dumps it to the
printer). Once one screen has been dumped, I want to clear the screen, draw
something onto it again and the dump that screen to the file UNDERNEATH the
previous screen.

I know I didn't explain very well but I hope you can help anyway.

--
Jimb...@Hotmail.com
-
it wasn't easy, but nothing never is, no.  -BLUR

Damons rule, Hill and Albarn, Jordan and BLUR

 

Re:Dumping the screen to a file


Jimbahb schrieb:

Quote
> Hi, here's what I'm trying to do.

> I need a way of dumping the screen to a file (like 'int 5' dumps it to the
> printer). Once one screen has been dumped, I want to clear the screen, draw
> something onto it again and the dump that screen to the file UNDERNEATH the
> previous screen.

> I know I didn't explain very well but I hope you can help anyway.

type
  screen = array[0..3999] of byte;
var
  f : file of screen;
  scr : screen absolute $B800:0;  { Assumes we are in text mode }
begin
end.

That's the basic structure. I think you are now able to write the rest
yourself.

Re:Dumping the screen to a file


Quote
Jimbahb wrote:

> Hi, here's what I'm trying to do.

> I need a way of dumping the screen to a file (like 'int 5' dumps it to the
> printer). Once one screen has been dumped, I want to clear the screen, draw
> something onto it again and the dump that screen to the file UNDERNEATH the
> previous screen.

> I know I didn't explain very well but I hope you can help anyway.

Hi
I would do this with a text file because the screen only shows the
text. You can easily access the screen with an array of words which
is located at $b800:000. Look in your help for "absolute". The high
byte contains the char. (Or the low byte? Can't remember)
For the next screen you just leave the file open and wrote it as
a next line. A little example:

-NOT tested-
var Screen : array [0..1999]of Word absolute $b800:000;
    F :Text;
    x,y: Byte;
begin
  Assign(f,'file');
  ReWrite(F);
  {Screen 1}
  for y:=0 to 24 do
    for x:=0 to 79 do
      Write(F,Chr(Hi(Screen[y*80+x])));
  {Clear Screen}
  FillChar(Screen,4000,0);
  {Screen 2}
  for y:=0 to 24 do
    for x:=0 to 79 do
      Write(F,Chr(Hi(Screen[y*80+x])));
  Close(F);
end.

I am sorry, if you meant graphics mode, cause i just talked about
text. If you use graphics mode just use a file of byte.

hth
Spix alias Martin

Re:Dumping the screen to a file


Hi.

Quote
>-NOT tested-

{right ;-) }
Quote
>var Screen : array [0..1999]of Word absolute $b800:000;
>    F :Text;
>    x,y: Byte;
>begin
>  Assign(f,'file');
>  ReWrite(F);
>  {Screen 1}
>  for y:=0 to 24 do
>    for x:=0 to 79 do
>      Write(F,Chr(Hi(Screen[y*80+x])));

{This disturbs me. If you want the screen dumped into a file, you'll have to
dump the COMPLETE screen, not just the chars. The color information byte has
to be copied, too. Even if it's 01110000b all the time (white, on top of
black, not blinking) }

Quote
>  {Clear Screen}
>  FillChar(Screen,4000,0);

{That's illegal. Take SCREEN[0] as first parameter. FillChar begins the
filling_with_rubbish at the address of the 1st parameter}
Quote
>  {Screen 2}
>  for y:=0 to 24 do
>    for x:=0 to 79 do
>      Write(F,Chr(Hi(Screen[y*80+x])));

{The same is for this here: you have to write all the informations back onto
the screen.}

Quote
>  Close(F);
>end.

>I am sorry, if you meant graphics mode, cause i just talked about
>text. If you use graphics mode just use a file of byte.

>hth
>Spix alias Martin

For example...If you buffer a TurboVision program (lets say Turbo Pascal),
then you'd find out that the color informations are missing, and the screen
could not be displayed properly. It'd be b/w, and these times are over now
;-)

bye

Re:Dumping the screen to a file


Winfried Rimbach-Sator schrieb:
Quote

> Hi.

> >-NOT tested-

> {right ;-) }
> >var Screen : array [0..1999]of Word absolute $b800:000;
> >    F :Text;
> >    x,y: Byte;
> >begin
> >  Assign(f,'file');
> >  ReWrite(F);
> >  {Screen 1}
> >  for y:=0 to 24 do
> >    for x:=0 to 79 do
> >      Write(F,Chr(Hi(Screen[y*80+x])));
> {This disturbs me. If you want the screen dumped into a file, you'll have to
> dump the COMPLETE screen, not just the chars. The color information byte has
> to be copied, too. Even if it's 01110000b all the time (white, on top of
> black, not blinking) }

Ok, you're right, i had just forgot it. I didn't mind he wants to use
the file for a later restoring.
Quote

> >  {Clear Screen}
> >  FillChar(Screen,4000,0);
> {That's illegal. Take SCREEN[0] as first parameter. FillChar begins the
> filling_with_rubbish at the address of the 1st parameter}

Under BP7, that works. But I've just seen another error. With that line
I also clear the color information for the chars. Without a SetTextColor
there can't be seen any char written by WriteLn. Euh, perhaps it was
late that day. ;-)

- Show quoted text -

Quote
> >  {Screen 2}
> >  for y:=0 to 24 do
> >    for x:=0 to 79 do
> >      Write(F,Chr(Hi(Screen[y*80+x])));
> {The same is for this here: you have to write all the informations back onto
> the screen.}
> >  Close(F);
> >end.

> >I am sorry, if you meant graphics mode, cause i just talked about
> >text. If you use graphics mode just use a file of byte.

> >hth
> >Spix alias Martin

> For example...If you buffer a TurboVision program (lets say Turbo Pascal),
> then you'd find out that the color informations are missing, and the screen
> could not be displayed properly. It'd be b/w, and these times are over now
> ;-)

Just one of of many errors that day. :-(

Spix

Re:Dumping the screen to a file


Martin Beck schrieb:

Quote
> var Screen : array [0..1999]of Word absolute $b800:000;
>     F :Text;
>     x,y: Byte;

[and so on]

Cumbersome. Look at my reply. It's certainly not perfect, but a bit easier, I
guess. :-)

Re:Dumping the screen to a file


JRS:  In article <3630BAEB.17A99...@rz-online.de> of Fri, 23 Oct 1998
19:20:44 in comp.lang.pascal.borland, Frederic <frede...@rz-online.de>
wrote:

Quote
>type
>  screen = array[0..3999] of byte;
>var
>  f : file of screen;
>  scr : screen absolute $B800:0;  { Assumes we are in text mode }
>begin
>end.

It is unsafe to assume that the screen is set to colour 80*25 mode, Page
0.

TSFAQP #31 refers to this, though AFAICS it assumes Page 0 and a mode no
bigger than 80*50.

Web <URL: http://www.merlyn.demon.co.uk/programs/shower.pas>  includes
code for detecting screen mode, size, page.

Somewhere I have a process, invoked by pressing ScrollLock, which dumps
the current text screen to file, modes and all; and a program for
replaying the data.

--
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:Dumping the screen to a file


Martin Beck <Spi...@t-online.de> wrote in article
<70thk9$8s...@news02.btx.dtag.de>...

Quote
> > >  {Clear Screen}
> > >  FillChar(Screen,4000,0);
> > {That's illegal. Take SCREEN[0] as first parameter. FillChar begins the
> > filling_with_rubbish at the address of the 1st parameter}
> Under BP7, that works. But I've just seen another error. With that line
> I also clear the color information for the chars. Without a SetTextColor
> there can't be seen any char written by WriteLn.

Actually, it's not clearing the color information, it's setting it to Black
on Black. This is called Stealth Text Mode, pretty sneaky, huh!? =)

As for the FillChar(Screen...) thing, "Screen" and "Screen[ 0 ]" both refer
to the same location, since you've defined it as

   var Screen : array [0..1999]of Word absolute $b800:000;

ie, it's an array of words, and "absolute" means it starts at that specific
address, the beginning of video memory. "Screen" refers to the array, and
"Screen[ 0 ]" refers to the first word, and FillChar doesn't really care
either way. If Screen were a pointer, Winifried would be correct.

-tf

Re:Dumping the screen to a file


*** A Draft addition to item #31 ***

 A2: Here is an answer to the variant "How can I dump the screen
into a file?"
  {$M 16384,4002,4002}
  {$S+}  (* Turn the stack overflow checking on *)
  uses Crt;
  type ScreenType = record
                      ChrAndAttr : array [1..4000] of byte;
                      CursX, CursY : byte;
                    end;
  type ScreenPtrType = ^ScreenType;
  var ColorScreen    : ScreenType Absolute $B800:$0000;
      SavedScreenPtr : ScreenPtrType;
      ScreenFile     : file of ScreenType;
  begin
    {... Save the screen into a file ...}
    New (SavedScreenPtr);
    Assign (ScreenFile, 'SAVESCR.DAT');
    {$I-} Rewrite(ScreenFile); {$I+}
    if IOResult <> 0 then begin
      writeln ('The screen storage file could not be opened');
      halt(1);
    end;
    SavedScreenPtr^.ChrAndAttr := ColorScreen.ChrAndAttr;
    SavedScreenPtr^.CursX := WhereX;
    SavedScreenPtr^.CursY := WhereY;
    write (ScreenFile, SavedScreenPtr^);
    Close(ScreenFile);
    Dispose (SavedScreenPtr);
    {}
    {... The simple demo ...}
    ClrScr;
    writeln ('A simple demo storing and restoring the color text screen');
    writeln ('By Prof. Timo Salmi, t...@uwasa.fi');
    writeln;
    writeln ('This will disappear and the original reappear.');
    writeln; write ('Press <-'''); readln;
    {}
    {... Read the screen from the file ...}
    {... Note that this could be in a separate program! ...}
    New (SavedScreenPtr);
    {$I-} reset(ScreenFile); {$I+}
    read (ScreenFile, SavedScreenPtr^);
    Close(ScreenFile);
    Erase(ScreenFile);  (* Always close first *)
    ColorScreen.ChrAndAttr := SavedScreenPtr^.ChrAndAttr;
    GotoXY(SavedScreenPtr^.CursX,SavedScreenPtr^.CursY);
    Dispose (SavedScreenPtr);
  end.
------------------------------------------------------------------------

   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.
Advice on spam foiling at http://www.uwasa.fi/~ts/info/spamfoil.html

Re:Dumping the screen to a file


In comp.lang.pascal.borland, Timo Salmi uttered:
Quote
>*** A Draft addition to item #31 ***

> A2: Here is an answer to the variant "How can I dump the screen
>into a file?"
>  {$M 16384,4002,4002}
>  {$S+}  (* Turn the stack overflow checking on *)
>  uses Crt;
>  type ScreenType = record
>                      ChrAndAttr : array [1..4000] of byte;

                                              ^^^^
Perhaps you should add that this is for 80x25 text only and different
figures will be needed for 80x43 (6880) and 80x50 (8000) wityh a simiar
increase in the heap reserved.

Incidentally, should the heap figures in this instance be 4008 as the
heap manager uses a granularity of 8 ?
--
Pedt Scragg

No-one is completely useless, they can always be a bad example.

Re:Dumping the screen to a file


In article <QO1IoCAgCsN2Y...@pedt.demon.co.uk>,
Pedt Scragg  <newsmas...@pedt.demon.co.uk> wrote:
:In comp.lang.pascal.borland, Timo Salmi uttered:
:> A2: Here is an answer to the variant "How can I dump the screen
:>into a file?"
:>  {$M 16384,4002,4002}

:>                      ChrAndAttr : array [1..4000] of byte;
:                                              ^^^^
:Perhaps you should add that this is for 80x25 text only and different
:figures will be needed for 80x43 (6880) and 80x50 (8000) wityh a simiar
:increase in the heap reserved.

That's in fact stated earlier in the item #31 (but not in the
included part).

:Incidentally, should the heap figures in this instance be 4008 as the
:heap manager uses a granularity of 8 ?

That's a very good catch, Pedt. Thanks.

   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.
Advice on spam foiling at http://www.uwasa.fi/~ts/info/spamfoil.html

Re:Dumping the screen to a file


JRS:  In article <715ri6$...@majakka.uwasa.fi> of Wed, 28 Oct 1998 03:21:10
in comp.lang.pascal.borland, Timo Salmi <t...@uwasa.fi> wrote:

Quote
>*** A Draft addition to item #31 ***

> A2: Here is an answer to the variant "How can I dump the screen
>into a file?"

Doubtless the existing A2 will be incremented.

Quote
>  {$M 16384,4002,4002}
>  {$S+}  (* Turn the stack overflow checking on *)

             Ensure                             :-)   should be on anyway!

Quote
>  uses Crt;

Caveat (warning)?

Quote
>  type ScreenType = record
>                      ChrAndAttr : array [1..4000] of byte;

4000 :-(

Quote
>    SavedScreenPtr^.ChrAndAttr := ColorScreen.ChrAndAttr;
>    SavedScreenPtr^.CursX := WhereX;
>    SavedScreenPtr^.CursY := WhereY;

with SavedScreenPtr^ do begin ... end ; ?

Quote
>    {... The simple demo ...}
>    writeln ('A simple demo storing and restoring the color text screen');

                                                       ^^^^^  :-(

Quote
>    {... Read the screen from the file ...}
>    {... Note that this could be in a separate program! ...}

(* For demo, the existing screen could be a good test *)

I think the "80*25 colour only" warning needs repeating.  You might insert
"80*25" and "Page 0" in the above Writeln?

=

I wrote a procedure to snapshot any text screen, repeatedly, to a file; and
a means of invoking it by pressing Scroll-Lock (generally an unused key);
and a program to play back the file.  The purpose was to simplify taking
screenshots of a working program with a real photographer and a good camera;
the program could be run and snapshotted to file when required, the file
reviewed, and the photographer then allowed to photograph the display at his
leisure.

It saves and restores the video mode with each snap; it may not save the
cursor, though it should.  The effect of playing back on another PC which
does not implement the mode is explicitly left for the user to worry about.

I intend to put it in <URL: http://www.merlyn.demon.co.uk/programs/> ere
long, after a few mods and checks.

--
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:Dumping the screen to a file


In article <b496CVAruxN2E...@merlyn.demon.co.uk>,
  Dr John Stockton <j...@merlyn.demon.co.uk> wrote:

Quote
> JRS:  In article <715ri6$...@majakka.uwasa.fi> of Wed, 28 Oct 1998 03:21:10
> in comp.lang.pascal.borland, Timo Salmi <t...@uwasa.fi> wrote:
> >*** A Draft addition to item #31 ***

> > A2: Here is an answer to the variant "How can I dump the screen
> >into a file?"

> Doubtless the existing A2 will be incremented.

<snip>

Quote
> >    SavedScreenPtr^.ChrAndAttr := ColorScreen.ChrAndAttr;
> >    SavedScreenPtr^.CursX := WhereX;
> >    SavedScreenPtr^.CursY := WhereY;
> with SavedScreenPtr^ do begin ... end ; ?

Yes & no!

This is what TP6 generates for the above,

TEST.24:  SavedScreenPtr^.ChrAndAttr := ColorScreen.ChrAnd
  013C BF0000         mov    di,0000
  013F B800B8         mov    ax,B800
  0142 50             push   ax
  0143 57             push   di
  0144 C43E4400       les    di,[TEST.SAVEDSCREENPTR]
  0148 06             push   es
  0149 57             push   di
  014A 68A00F         push   0FA0
  014D 9A68083860     call   6038:0868
TEST.25:  SavedScreenPtr^.CursX := WhereX;
  0152 9A4A02D45F     call   far CRT.WHEREX
  0157 C43E4400       les    di,[TEST.SAVEDSCREENPTR]
  015B 268885A00F     mov    es:[di+0FA0],al
TEST.26:  SavedScreenPtr^.CursY := WhereY;
  0160 9A5602D45F     call   far CRT.WHEREY
  0165 C43E4400       les    di,[TEST.SAVEDSCREENPTR]
  0169 268885A10F     mov    es:[di+0FA1],al

and with "WITH"

TEST.27:  with SavedScreenPtr^ do
  016E C43E4400       les    di,[TEST.SAVEDSCREENPTR]
  0172 897EFC         mov    [bp-04],di
  0175 8C46FE         mov    [bp-02],es
TEST.29:  ChrAndAttr := ColorScreen.ChrAndAttr;
  0178 BF0000         mov    di,0000
  017B B800B8         mov    ax,B800
  017E 50             push   ax
  017F 57             push   di
  0180 C47EFC         les    di,[bp-04]
  0183 06             push   es
  0184 57             push   di
  0185 68A00F         push   0FA0
  0188 9A68083860     call   6038:0868
TEST.30:  CursX := WhereX;
  018D 9A4A02D45F     call   far CRT.WHEREX
  0192 C47EFC         les    di,[bp-04]
  0195 268885A00F     mov    es:[di+0FA0],al
TEST.31:  CursY := WhereY;
  019A 9A5602D45F     call   far CRT.WHEREY
  019F C47EFC         les    di,[bp-04]
  01A2 268885A10F     mov    es:[di+0FA1],al

Or in other words, in this case NOT using "WITH" gives shorter code than using
it!

<snip>

Robert
--
Robert AH Prins
prin...@williscorroon.com

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    

Re:Dumping the screen to a file


In article <718382$ga...@nnrp1.dejanews.com>,
Robert AH Prins  <prin...@williscorroon.com> wrote:
:In article <b496CVAruxN2E...@merlyn.demon.co.uk>,
:  Dr John Stockton <j...@merlyn.demon.co.uk> wrote:
:> JRS:  In article <715ri6$...@majakka.uwasa.fi> of Wed, 28 Oct 1998 03:21:10
:> in comp.lang.pascal.borland, Timo Salmi <t...@uwasa.fi> wrote:
:> >*** A Draft addition to item #31 ***

:> >    SavedScreenPtr^.CursY := WhereY;
:> with SavedScreenPtr^ do begin ... end ; ?
:Yes & no!

:Or in other words, in this case NOT using "WITH" gives shorter code than using
:it!

It also is a question of styles. In  this one John and I have of old
slightly different preferences. I find using SavedScreenPtr^.CursY
:= WhereY; a bit easier to understand even if I have no big problem
with the with either.

P.S. Thanks, John, for your useful comments (as always) on the
draft.

   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.
Advice on spam foiling at http://www.uwasa.fi/~ts/info/spamfoil.html

Re:Dumping the screen to a file


In comp.lang.pascal.borland, Timo Salmi uttered:

<snip about screen size>

Quote
>That's in fact stated earlier in the item #31 (but not in the
>included part).

Apologies, I should have re-read it first but I wonder if it needs to be
re-iterated in this answer as well.

--
Pedt Scragg

No-one is completely useless, they can always be a bad example.

Go to page: [1] [2]

Other Threads