{--------------------------------------------------------------}
{                         GraphFiler                           }
{                                                              }
{            Graphics file I/O demonstration program           }
{                                                              }
{                             by Jeff Duntemann                }
{                             Turbo Pascal V3.0                }
{                             Last update 1/31/86              }
{                                                              }
{    From the book, COMPLETE TURBO PASCAL, by Jeff Duntemann   }
{    Scott, Foresman & Co. (c) 1986,1987  ISBN 0-673-18600-8   }
{--------------------------------------------------------------}

PROGRAM GraphFiler;

TYPE
  String80 = String[80];

VAR
  I         : Integer;
  ErrorCode : Integer;


PROCEDURE GSave(GName : String80; VAR IOR : Integer);

TYPE
  ScreenBuff = ARRAY[0..16383] OF Byte;

VAR
  GBuff : ScreenBuff ABSOLUTE $B800 : 0;
  GFile : File;

BEGIN
  Assign(GFile,GName);
  Rewrite(GFile,16384);
  BlockWrite(GFile,GBuff,1);
  IOR := IOResult;
  Close(GFile)
END;


PROCEDURE GLoad(GName : String80; VAR IOR : Integer);

TYPE
  ScreenBuff = ARRAY[0..16383] OF Byte;

VAR
  GBuff : ScreenBuff ABSOLUTE $B800 : 0;
  GFile : File;

BEGIN
  Assign(GFile,GName);
  {$I-} Reset(GFile,16384); {$I+}
  IOR := IOResult;
  IF IOR = 0 THEN
    BEGIN
      BlockRead(GFile,GBuff,1);
      Close(GFile)
    END
END;


BEGIN  { GraphFiler MAIN }
  ClrScr;
  HiResColor(15);                  { Use white as foreground color }
  HiRes;                           { Clears graphics screen }
  TextColor(1);
  FOR I := 0 TO 199 DO             { Draw lines }
    IF I MOD 5 = 0 THEN Draw(0,0,640,I,1);
  GSave('LINES.PIC',ErrorCode);    { Save graphics image to a file }
  Write('Press RETURN to clear screeen and re-load image: ');
  Readln;
  HiRes;                           { Clears graphics screen }
  GLoad('LINES.PIC',ErrorCode);    { Load saved file into display buffer }
  Readln
END.