[comp.lang.pascal] Graphic-screen to disk

S89405079%HSEPM1.HSE.NL@uga.cc.uga.edu (11/16/90)

Hi,

I have a little problem dumping the graphics-screen to disk. The problem is
that when I dump such a screen, all the colors disappear. Does anyone
know what I'm doing wrong?

Edwin Groothuis
S89405079@hsepm1.hse.nl

============================ PROGRAM ==========================
uses       crt,dos,graph;
type       screen_type:array[0..$FFFF] of byte;
var        fil:file of screen_type;
           screen:^screen_type;
           driver,mode:integer;
           i:integer;

begin
  detectgraph(driver,mode);
  initgraph(driver,mode,'');
  for i:=1 to 100 do
    circle(100,100,i);                (* Make something on the screen *)
  screen:=ptr($A000,0000)
  assign(fil,'test');rewrite(fil);write(fil,screen);close(fil);
  clearviewport;
  assign(fil,'test');reset(fil);read(fil,screen);close(fil);
end.

eli@aspasia.gang.umass.edu (Eli Brandt) (11/17/90)

In article <25017@adm.brl.mil> S89405079%HSEPM1.HSE.NL@uga.cc.uga.edu writes:
>Hi,
>
>I have a little problem dumping the graphics-screen to disk. The problem is
>that when I dump such a screen, all the colors disappear. Does anyone
>know what I'm doing wrong?
>
>Edwin Groothuis
>S89405079@hsepm1.hse.nl
>
>============================ PROGRAM ==========================
>uses       crt,dos,graph;
>type       screen_type:array[0..$FFFF] of byte;
>var        fil:file of screen_type;
>           screen:^screen_type;
>           driver,mode:integer;
>           i:integer;
>
>begin
>  detectgraph(driver,mode);
>  initgraph(driver,mode,'');
>  for i:=1 to 100 do
>    circle(100,100,i);                (* Make something on the screen *)
>  screen:=ptr($A000,0000)
>  assign(fil,'test');rewrite(fil);write(fil,screen);close(fil);
>  clearviewport;
>  assign(fil,'test');reset(fil);read(fil,screen);close(fil);
>end.

Well, if you're getting anything, you're presumably in EGA/VGA mode.  These
modes store the frame buffer as 4 bitplanes, all mapped to the A000 segment.
What you get when you read/write depends on the status of the select and
mask registers.  The simplest way to get a screen dump would probably be to
pull each of the four bitplanes in turn, and put them back the same way.
If you don't have a reference for the registers, e-mail me and I'l get back to
you after I've looked it up. :-)

Eli

zhou@brazil.psych.purdue.edu (Albert Zhou) (11/17/90)

	Here is my diagnosis:
	(1) If it is for CGA, the address is obviously wrong. CGA start from
$BA00:0. 
	(2) If it is for EGA or VGA, 64K is far from enough. 
	The best solution is use GetImage, then TP will handle things about
image buffer size and address, and your program will be independent of which
kind of graphics driver your are using.


	The limitation of this solution is that if the size of image buffer
is over 64K, you have to divide the screen into serveral pieces so that each
piece is under 64K.

	If you know the cocrrect address and and size of the video buffer,
you can use Block write, which is probably the fastest.

bobb@vice.ICO.TEK.COM (Bob Beauchaine) (11/17/90)

In article <11492@j.cc.purdue.edu> zhou@brazil.psych.purdue.edu (Albert Zhou) writes:
>
>	Here is my diagnosis:
>	(1) If it is for CGA, the address is obviously wrong. CGA start from
>$BA00:0. 
  Wrong,Wrong,WRONG!  Please try to be accurate when posting to other 
  programmers on the net!  CGA starts at $B800:0.  I use it all the time
  for my assembly language screen drawing routines.

  Bob Beauchaine
  bobb@vice.ICO.TEK.COM

kamal@wpi.WPI.EDU (Kamal Z Zamli) (11/18/90)

In article <6327@vice.ICO.TEK.COM> bobb@vice.ICO.TEK.COM (Bob Beauchaine) writes:
>In article <11492@j.cc.purdue.edu> zhou@brazil.psych.purdue.edu (Albert Zhou) writes:
>>
>>	Here is my diagnosis:
>>	(1) If it is for CGA, the address is obviously wrong. CGA start from
 >>$BA00:0. 
>  Wrong,Wrong,WRONG!  Please try to be accurate when posting to other 
   ^^^^^^^^^^^^^^^^^^
     Isn't it a little harsh.......
     Everybody make mistake......( i guess nobody's perfect)

>  programmers on the net!  CGA starts at $B800:0.  I use it all the time
>  for my assembly language screen drawing routines.
  
 Bob Beauchaine is right CGA start at $B800:$0. 

zhou@brazil.psych.purdue.edu (Albert Zhou) (11/18/90)

Oh boy! You must get confused between text video buffer and graphic video 
buffer. CGA text video buffer starts at $B800:0 while the graphic video
buffer starts at $BA00:0. It is in any DOS manual.

zhou@brazil.psych.purdue.edu (Albert Zhou) (11/18/90)

>>  programmers on the net!  CGA starts at $B800:0.  I use it all the time
>>  for my assembly language screen drawing routines.
>  
> Bob Beauchaine is right CGA start at $B800:$0. 

This is really weird. I've been writing on CGA video buffer since high school.
In text mode you start at $B800:$0. In graphic mode you start at $BA00:$0.
This is also in any DOS manual. What's going on??

efa@iesd.auc.dk (Erik F. Andersen) (11/19/90)

WRONG. The correct address IS $B800:0000 - The DOS manual must be wrong..

zhou@brazil.psych.purdue.edu (Albert Zhou) (11/20/90)

In article <EFA.90Nov19103137@wishart.iesd.auc.dk> efa@iesd.auc.dk (Erik F. Andersen) writes:
>WRONG. The correct address IS $B800:0000 - The DOS manual must be wrong..

Actually neither is wrong. Please run the following program. I am suprised to
see that both addresses store the same image on my CGA. Please let me know
if it works the same on your machine.


uses graph;
type
    buftype1 = array[1..8000] of byte;
    buftype2 = array[1..16000] of byte;
var
   grmode, grdriver : integer;
   MyBuffer1 : buftype1 ABSOLUTE $BA00:0;
   MyBuffer2 : buftype1 ABSOLUTE $BC00:0;
   AnotherBuffer :  buftype2 ABSOLUTE $B800:0;
   x1, x2 : buftype1;
   y : buftype2;
   n : integer;

begin
     grdriver := detect;
     initgraph(grdriver, grmode,'');
     line(0,0,639,199);
     outtextxy(100,100, 'This is $BA00');
     x1 := MyBuffer1;
     x2 := MyBuffer2;
     readln;
     cleardevice;
     readln;
     MyBuffer1 := x1;
     MyBuffer2 :=x2;
     readln;

     cleardevice;
     readln;
     line(0,0,639,199);
     outtextxy(100,100, 'This is $B800');
     y := AnotherBuffer;
     readln;
     cleardevice;
     readln;
     AnotherBuffer := y;
     readln;


end.