home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / PACKSCR.ZIP / PSCREEN.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1988-08-21  |  5.8 KB  |  227 lines

  1. {$S-,R-,V-,I-,B-,F-}
  2. {$M 4096,0,10000}
  3.  
  4. {*********************************************************}
  5. {*                  PSCREEN.PAS 5.00                     *}
  6. {*        Copyright (c) TurboPower Software 1988.        *}
  7. {*                 All rights reserved.                  *}
  8. {*********************************************************}
  9.  
  10. program PackedScreenUtility;
  11.   {-Utility for saving and displaying packed screens}
  12.  
  13. uses
  14.   Dos, TpCrt, TpString, TpEdit, TpTsr;
  15.  
  16. type
  17.   String64 = string[64];
  18. const
  19.   ModuleName : string[7] = 'PSCREEN'; {module name for standard interface}
  20.   OurHotKey : Word = $0619;  {Ctrl + LeftShift, 'P'}
  21.   ProgName : string[64] = 'PSCREEN 5.00: A Utility for Saving and Displaying Packed Screens';
  22.   Copyright : string[41] = 'Copyright (c) 1988 by TurboPower Software';
  23.   LoadError : string[25] = 'Unable to install PSCREEN';
  24.   Disable   : Boolean = False;
  25. var
  26.   PWP : PackedWindowPtr;
  27.   Bright,                    {video attributes}
  28.   Dim,
  29.   Border,
  30.   Reverse : Byte;
  31.   MaxRows : Word;
  32.   MaxCols : Word;
  33.   MaxParas : Word;           {maximum space needed for saving the screen}
  34.  
  35.   procedure SetAttributes;
  36.     {-Set the attributes to be used based on the current video mode}
  37.   begin
  38.     case CurrentMode of
  39.      0,                      {BW40}
  40.      2,                      {BW80}
  41.      7 :                     {monochrome}
  42.        begin
  43.          Bright := $F;
  44.          Border := $F;
  45.          Dim := $7;
  46.          Reverse := $70;
  47.         end;
  48.     else                     {color}
  49.      begin
  50.       Bright := $1F;
  51.       Border := $1A;
  52.       Dim := $1B;
  53.       Reverse := $21;
  54.      end;
  55.     end;
  56.     TextAttr := Dim;
  57.   end;
  58.  
  59.   {$F+}
  60.   function GetKey : Word;
  61.     {-}
  62.   var
  63.     ChWord : Word;
  64.   begin
  65.     ChWord := ReadKeyWord;
  66.     {check for Alt-U}
  67.     if ChWord = $1600 then begin
  68.       {translate to ESC and set flag to disable the TSR}
  69.       ChWord := $001B;
  70.       Disable := True;
  71.     end;
  72.     GetKey := ChWord;
  73.   end;
  74.   {$F-}
  75.  
  76.   function GetFileName(var FName : String64) : Boolean;
  77.     {-Prompt for a file name}
  78.   const
  79.     Prompt = 'File to write: ';
  80.   var
  81.     Escaped : Boolean;
  82.   begin
  83.     ForceUpper := True;
  84.     EditSize := CurrentWidth-(Length(Prompt)+4);
  85.     ReadString(Prompt, 2, 3, 64, Bright, Dim, Dim, Escaped, FName);
  86.  
  87.     GetFileName := (Length(FName) <> 0) and not Escaped;
  88.   end;
  89.  
  90.   procedure ErrorMessage(Msg : String);
  91.     {-Display an error message and wait for a keypress}
  92.   const
  93.     PressAnyKey = '. Press any key...';
  94.   begin
  95.     if Length(Msg)+Length(PressAnyKey)+4 <= CurrentWidth then
  96.       Msg := Msg+PressAnyKey;
  97.     FastWrite(Pad(Msg, CurrentWidth-4), 2, 3, Bright);
  98.     if ReadKeyWord = 0 then {};
  99.   end;
  100.  
  101.   {$F+}
  102.   procedure PopupEntryPoint(var Regs : Registers);
  103.     {-This is the entry point for the popup}
  104.   const
  105.     FName : String64 = '';
  106.   var
  107.     SaveXY, SaveSL : Word;   {for saving cursor position and shape}
  108.   begin
  109.     {reinitialize CRT}
  110.     ReInitCrt;
  111.  
  112.     {exit if not in text mode}
  113.     if InTextMode then begin
  114.       {save the screen}
  115.       PWP := PackWindow(1, 1, CurrentWidth, CurrentHeight+1);
  116.       if PWP = nil then
  117.         Exit;
  118.  
  119.       {initialize screen stuff}
  120.       SetAttributes;
  121.       GetCursorState(SaveXY, SaveSL);
  122.  
  123.       {draw our window}
  124.       Window(1, 1, CurrentWidth, 3);
  125.       ClrScr;
  126.       FrameWindow(1, 1, CurrentWidth, 3, Border, Reverse, ' PSCREEN 5.00 ');
  127.  
  128.       {get name of file to save screen in}
  129.       if GetFileName(FName) then begin
  130.         {save the screen}
  131.         WritePackedWindow(PWP, FName);
  132.         if CrtError <> 0 then
  133.           ErrorMessage('Error while writing screen to disk');
  134.       end
  135.       else if Disable then
  136.         Disable := DisableTSR;
  137.  
  138.       {restore cursor and screen}
  139.       RestoreCursorState(SaveXY, SaveSL);
  140.       DisplayPackedWindow(PWP);
  141.       DisposePackedWindow(PWP);
  142.     end;
  143.   end;
  144.   {$F-}
  145.  
  146.   procedure Abort(Msg : string);
  147.     {-Display an error message and halt}
  148.   begin
  149.     WriteLn(Msg);
  150.     Halt(1);
  151.   end;
  152.  
  153.   procedure Initialize;
  154.     {-Initialize and check for command line parameters}
  155.   var
  156.     PWP : PackedWindowPtr;
  157.     FName : String64;
  158.   begin
  159.     {initialize}
  160.     RSgetKeyPtr := @GetKey;
  161.  
  162.     {resident mode if no parameters specified}
  163.     if ParamCount = 0 then
  164.       Exit;
  165.  
  166.     {get the filename and display it}
  167.     FName := ParamStr(1);
  168.     PWP := ReadPackedWindow(FName);
  169.     if PWP = nil then
  170.       Abort('Error reading '+FName);
  171.     DisplayPackedWindow(PWP);
  172.     Halt;
  173.   end;
  174.  
  175. begin
  176.   {see if there is a file to display}
  177.   Initialize;
  178.  
  179.   {signon message}
  180.   HighVideo;
  181.   WriteLn(ProgName, ^M^J, Copyright, ^M^J);
  182.   LowVideo;
  183.  
  184.   {check to see if SideKick is loaded}
  185.   if SideKickLoaded then
  186.     Abort('Can''t be loaded after SideKick!');
  187.  
  188.   {check to see if we're already installed}
  189.   if ModuleInstalled(ModuleName) then
  190.     Abort('PSCREEN is already loaded. Aborting...');
  191.  
  192.   {install the module}
  193.   InstallModule(ModuleName, nil);
  194.  
  195.   {go resident}
  196.   if DefinePop(OurHotKey, @PopupEntryPoint, Ptr(SSeg, SPtr), True) then begin
  197.     WriteLn('PSCREEN loaded. Press Ctrl-LeftShift-P to activate.');
  198.  
  199.     {Enable popups}
  200.     PopupsOn;
  201.  
  202.     {$IFDEF Ver40}
  203.     {restore INT $1B, captured by TPCRT}
  204.     SetIntVec($1B, SaveInt1B);
  205.     {$ENDIF}
  206.  
  207.     {calculate amount of heap space to set aside}
  208.     case EnhancedDisplay of
  209.       EGA : MaxRows := 43;
  210.       VGA : MaxRows := 50;
  211.       else MaxRows := 25;
  212.     end;
  213.     if CurrentWidth > 80 then
  214.       MaxCols := CurrentWidth
  215.     else
  216.       MaxCols := 80;
  217.     MaxParas := (MaxRows*MaxCols*2)+(SizeOf(PackedWindow)-SizeOf(PackedScreen));
  218.     MaxParas := (MaxParas+$F) div 16;
  219.  
  220.     {terminate and stay resident}
  221.     if not TerminateAndStayResident(ParagraphsToKeep+MaxParas, 0) then {} ;
  222.   end;
  223.  
  224.   {if we get here we failed}
  225.   Abort(LoadError);
  226. end.
  227.