home *** CD-ROM | disk | FTP | other *** search
/ Point Programming 1 / PPROG1.ISO / pascal / swag / screen.swg / 0079_Save-Restore Text Screen.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-03-26  |  2.6 KB  |  91 lines

  1. program screen { save screen in file / restore screen from file };
  2.                { only text mode screens }
  3.  
  4.  { no error checking! the video mode and
  5.    (if restoring the screen from a file)
  6.    the content of the file are not checked.
  7.  
  8.    it only moves the video memory to a file
  9.    or from a file to the video memory }
  10.  
  11.  { if the file does not exist: the screen is saved in a new file
  12.      with the given name;
  13.    if the file does exist: the screen is restored from that file
  14.      the file is not deleted. }
  15.  
  16. uses dos;
  17. Const
  18.   NoFAttr : word = $1C; { dir-, volume-, system attributen }
  19.   FAttr   : word = $23; { readonly-, hidden-, archive attributen }
  20. Var
  21.   { bios area }
  22.   mode      : byte absolute $40:$49;  { current video mode }
  23.   columns   : byte absolute $40:$4A;  { number of columns  }
  24.   dispOfs   : word absolute $40:$4E;  { current video page offset }
  25.   CrtPort   : word absolute $40:$63;  { CRT port address }
  26.   lastRow   : byte absolute $40:$84;  { newer bios only: rows on screen-1 }
  27.  
  28.   VidSeg    : word;
  29.   dispSize  : word;
  30.   ScreenF   : file;
  31.   Fname     : string[128];
  32.   Attr      : word;
  33.   Exists    : boolean;
  34.   tel       : word;
  35.  
  36. function GetVidSeg : word;
  37. begin
  38.  if CrtPort = $3D4 then
  39.    GetVidSeg := $B800        { color }
  40.  else
  41.    GetVidSeg := $B000;       { mono  }
  42. end;                         
  43.  
  44. Procedure SaveScreen;
  45. begin
  46.   BlockWrite( ScreenF, mem[ vidseg : dispOfs ], dispSize, tel );
  47. end;
  48.  
  49. Procedure RestoreScreen;
  50. begin
  51.   BlockRead( ScreenF, mem[ vidseg : dispOfs ], dispSize, tel );
  52. end;
  53.  
  54. begin
  55.   VidSeg := GetVidSeg;
  56.   dispSize := columns * (lastRow+1);
  57.  
  58.   if ParamCount > 0 then
  59.   begin
  60.     Fname := FExpand( ParamStr( 1 ) );
  61.     Assign ( ScreenF, Fname );
  62.  
  63.     { ---------------------------------------------------------------------- }
  64.     { does file exist? }
  65.     GetFAttr( ScreenF, Attr );
  66.     if DosError = 0 then
  67.       Exists := ((Attr and NoFAttr) = 0)  { not dir-, volume- or system bit? }
  68.     else
  69.       Exists := False;                    { DosError }
  70.     { ---------------------------------------------------------------------- }
  71.  
  72.     if Exists then
  73.       Reset( ScreenF, 2 )         { open file }
  74.     else
  75.       Rewrite( ScreenF, 2 );      { create new file }
  76.     {}
  77.  
  78.     if IOResult = 0 then       { no error reading or creating file }
  79.     begin
  80.       if Exists then
  81.         RestoreScreen
  82.       else
  83.         SaveScreen;
  84.       Close( ScreenF );
  85.     end   { if IOResult = 0 }
  86.     else  { IOResult <> 0 ! }
  87.       Writeln( 'Error reading or creating file ', Fname );
  88.     { endif IO error Fname }
  89.   end;  { if ParamCount > 0 }
  90. end.
  91.