home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / tptools.zip / ALLINST.ZIP / SINST.PAS < prev   
Pascal/Delphi Source File  |  1987-12-21  |  8KB  |  246 lines

  1. {                          SINST.PAS
  2.                        Editor Toolbox 4.0
  3.              Copyright (c) 1985, 87 by Borland International, Inc.            }
  4.  
  5. {$I-}
  6. {$R-}
  7. {$V-}
  8. {$S-}
  9.  
  10. unit SInst;
  11. {-Fast screen writing routines for installation programs}
  12.  
  13. interface
  14.  
  15. uses
  16.   Crt,                      {screen routines - standard unit}
  17.   Dos;                      {dos calls - standard unit}
  18.  
  19. const
  20.   Defnorows = 25;             {Default number of rows/physical screen}
  21.   Defnocols = 80;             {Default number of cols/physical screen}
  22.   HiddenCursor = $2000;       {scan lines for a hidden cursor}
  23.  
  24. type
  25.   ScreenBuffer = array[0..1999] of Word; {Structure of video memory}
  26.  
  27.   WindowRec =
  28.   record
  29.     TopRow, LeftCol, Width, Height : Byte;
  30.     Contents : array[0..1999] of Integer;
  31.   end;
  32.  
  33.   WindowPtr = ^WindowRec;
  34.  
  35. var
  36.   ScreenAdr : Word;           {Base address of video memory}
  37.   PhyScrCols : Integer;       {Columns per screen row}
  38.   RetraceMode : Boolean;      {Check for snow on color cards?}
  39.   NormalCursor : Word;          {Scan lines for normal blinking cursor}
  40.   PhyscrRows : Word;          {No. lines/physical screen}
  41.   InitScreenMode : Byte;      {Video mode on entry to the program}
  42.   LoColor,                    {LOw video}
  43.   TiColor,                    {TItle / high video}
  44.   ChColor,                    {CHanged keystrokes}
  45.   EdColor,                    {keystroke being EDited / reverse video}
  46.   CfColor : Byte;             {ConFlicting keystrokes}
  47.  
  48.   procedure EdFastWrite(St : String; Row, Col, Attr : Word);
  49.     {-Writes St at Row,Col in Attr (video attribute) without snow}
  50.  
  51.   procedure EdChangeAttribute(Number, Row, Col, Attr : Word);
  52.     {-Changes Number video attributes to Attr starting at Row,Col}
  53.  
  54.   procedure EdMoveFromScreen(var Source, Dest; Length : Word);
  55.     {-Moves Length words from Source (video memory) to Dest without snow}
  56.  
  57.   procedure EdMoveToScreen(var Source, Dest; Length : Word);
  58.     {-Moves Length words from Source to Dest (video memory) without snow}
  59.  
  60.   procedure EdSetCursor(ScanLines : Word);
  61.    {-Change the scan lines of the hardware cursor}
  62.  
  63.   procedure RestoreScreen;
  64.     {-Clean up screen at end of program}
  65.  
  66.   procedure SetColor(TheColor : Byte);
  67.     {-set both textcolor and textbackground}
  68.  
  69.   procedure MakeBox(Left, Top, Right, Bottom, Attr : Byte);
  70.     {-Draw a box on the screen}
  71.  
  72.   procedure SaveWindow(var WP : WindowPtr; Left, Top, Right, Bottom : Byte; Alloc : Boolean);
  73.     {-Save a window}
  74.  
  75.   procedure RestoreWindow(var WP : WindowPtr; DeAlloc : Boolean);
  76.     {-Restore a previously saved window and dispose of memory allocated to it}
  77.  
  78.   {==========================================================================}
  79.  
  80. implementation
  81.  
  82.   {$L SINST}
  83.  
  84.   procedure EdFastWrite(St : String; Row, Col, Attr : Word); external;
  85.   procedure EdChangeAttribute(Number, Row, Col, Attr : Word); external;
  86.   procedure EdMoveFromScreen(var Source, Dest; Length : Word); external;
  87.   procedure EdMoveToScreen(var Source, Dest; Length : Word); external;
  88.   procedure EdSetCursor(ScanLines : Word); external;
  89.  
  90.   procedure RestoreScreen;
  91.     {-Clean up screen at end of program}
  92.   begin                       {RestoreScreen}
  93.     NormVideo;
  94.     ClrScr;
  95.   end;                        {RestoreScreen}
  96.  
  97.   procedure SetColor(TheColor : Byte);
  98.     {-Set both textcolor and textbackground}
  99.   begin
  100.     TextColor(TheColor and $F);
  101.     TextBackground(TheColor shr 4);
  102.   end;                        {SetColor}
  103.  
  104.   procedure MakeBox(Left, Top, Right, Bottom, Attr : Byte);
  105.     {-Draw a box on the screen}
  106.   var
  107.     Row : Byte;
  108.     Span : String[80];
  109.     SLen : Byte absolute Span;
  110.   const
  111.     Upright : string[1] = #179;
  112.   begin                       {MakeBox}
  113.     SLen := Pred(Right-Left);
  114.     FillChar(Span[1], SLen, #196);
  115.     {Top}
  116.     EdFastWrite( #218+Span+#191, Top, Left, Attr);
  117.     {Bottom}
  118.     EdFastWrite(#192+Span+#217, Bottom, Left, Attr);
  119.     {Middle}
  120.     for Row := Succ(Top) to Pred(Bottom) do begin
  121.       EdFastWrite(Upright, Row, Left, Attr);
  122.       EdFastWrite(UpRight, Row, Right, Attr);
  123.     end;
  124.   end;                        {MakeBox}
  125.  
  126.   procedure SaveWindow(var WP : WindowPtr; Left, Top, Right, Bottom : Byte; Alloc : Boolean);
  127.     {-Save a window}
  128.   var
  129.     Ofst : Word;
  130.     W, H, I : Integer;
  131.   begin                       {SaveWindow}
  132.     W := Succ(Right-Left);
  133.     H := Succ(Bottom-Top);
  134.     if Alloc then
  135.       GetMem(WP, (W*H) shl 1 + 4);
  136.     with WP^ do begin
  137.       Width := W;
  138.       Height := H;
  139.       TopRow := Top;
  140.       LeftCol := Left;
  141.       for I := 0 to Pred(H) do begin
  142.         Ofst := ( ((Pred(Top)+I) * 80) + Pred(Left) ) shl 1;
  143.         EdMoveFromScreen(Mem[ScreenAdr:Ofst], Contents[I*W], W);
  144.       end;
  145.     end;
  146.   end;                        {SaveWindow}
  147.  
  148.    procedure RestoreWindow(var WP : WindowPtr; DeAlloc : Boolean);
  149.      {-Restore a previously saved window and dispose of memory allocated to it}
  150.    var
  151.      I : Integer;
  152.      Ofst : Word;
  153.    begin                      {RestoreWindow}
  154.      with WP^ do begin
  155.        for I := 0 to Pred(Height) do begin
  156.          Ofst := ( ((Pred(TopRow)+I) * 80) + Pred(LeftCol) ) shl 1;
  157.          EdMoveToScreen(Contents[I*Width], Mem[ScreenAdr:Ofst], Width);
  158.        end;
  159.        if DeAlloc then begin
  160.          Freemem(WP, (Width*Height) shl 1 + 4);
  161.          WP := Nil;
  162.        end;
  163.      end;
  164.    end;                       {RestoreWindow}
  165.  
  166.   procedure EdGetScreenMode;
  167.     {-determine screen address and colors}
  168.   var
  169.     regs:Registers;
  170.  
  171.     procedure ChooseColorSet(Mono : Boolean);
  172.     begin
  173.       if Mono then begin
  174.         LoColor := $07;
  175.         TiColor := $0F;
  176.         ChColor := $0F;
  177.         EdColor := $70;
  178.         CfColor := $70;
  179.       end
  180.       else begin
  181.         LoColor := $07;
  182.         TiColor := $0E;
  183.         ChColor := $0F;
  184.         EdColor := $1E;
  185.         CfColor := $4F;
  186.       end;
  187.     end;
  188.  
  189.     function EdEgaPresent : Boolean;
  190.       {-Return True if an EGA card is installed and selected}
  191.     var
  192.       regs:Registers;
  193.  
  194.     begin                     {EdEgaPresent}
  195.       with Regs do begin
  196.         Ah := $12;
  197.         Bl := $10;
  198.         Cx := $FFFF;
  199.         Intr($10, Regs);
  200.         EdEgaPresent := (Cx <> $FFFF);
  201.       end;
  202.     end;                      {EdEgaPresent}
  203.  
  204.   begin                       {EdGetScreenMode}
  205.  
  206.     PhyscrCols := Defnocols;  {Number of columns on the screen}
  207.     PhyscrRows := Defnorows;
  208.  
  209.     with Regs do begin
  210.       {Get current screen mode}
  211.       Ax := $0F00;
  212.       Intr($10, Regs);
  213.       InitScreenMode := Al;
  214.  
  215.       {Set screen mode to appropriate 80 column mode if necessary}
  216.       case InitScreenMode of
  217.         0..1 : begin
  218.                  {Switch from BW40 to BW80 or CO40 to CO80}
  219.                  Ah := 0;
  220.                  InitScreenMode := InitScreenMode + 2;
  221.                  Al := InitScreenMode;
  222.                  Intr($10, Regs);
  223.                end;
  224.       end;
  225.     end;
  226.  
  227.     Retracemode := (InitScreenMode <> 7);
  228.  
  229.     if Retracemode then begin
  230.       {Color card}
  231.       Screenadr := $B800;
  232.       NormalCursor := $0607;
  233.       Retracemode := not EdEgaPresent;
  234.       ChooseColorSet(InitScreenMode <> 3)
  235.     end else begin
  236.       {Monochrome}
  237.       Screenadr := $B000;
  238.       NormalCursor := $0B0C;
  239.       ChooseColorSet(True);
  240.     end;
  241.   end;                        {EdGetScreenMode}
  242.  
  243. begin
  244.   EdGetScreenMode;
  245. end.
  246.