home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / lan / spy / source / screen.pas < prev    next >
Pascal/Delphi Source File  |  1989-10-02  |  6KB  |  176 lines

  1. {$A+,B-,D-,E-,F+,I-,L-,N-,O-,R-,S-,V+}
  2. Unit Screen;
  3. {
  4.   Screen supports fast, adapter independent movement of data to and from page
  5.   zero of a text-mode screen.
  6.  
  7.   Author: Edwin T. Floyd [76067,747]
  8.           9 Adams Park Court
  9.           Columbus, GA 31909
  10.           404-322-0076 (home)
  11.           404-576-3305 (work)
  12.  
  13.   Thanks to Jeff Dunteman and Brian Foley who pioneered much of the code for
  14.   these routines.
  15.  
  16.   This unit is contributed to the public domain.
  17. }
  18. Interface
  19.  
  20. Type
  21.   AdapterType = (None, MDA, CGA, EGAMono, EGAColor, VGAMono, VGAColor,
  22.     MCGAMono, MCGAColor, HercMono, HercPlus, HercInColor);
  23.   FontSize = (Font8, Font14, Font16);
  24.   ScreenSaveHeader =
  25.   { Format of data area used by SaveScreenArea and RestoreScreenArea }
  26.   Record
  27.     Cursor : Word;                 { CursorPosition }
  28.     RowCol1 : Word;                { Upper-left corner }
  29.     RowCol2 : Word;                { Lower-right corner }
  30.     Mode : Byte;                   { Video mode }
  31.     Compressed : Boolean;          { True if screen area is compressed }
  32.     Size : Word;                   { Size of data area that follows }
  33.     { The header is followed by screen data }
  34.   End;
  35.  
  36. Var
  37.   ScreenOfs : Word;                { *Offset of video buffer }
  38.   ScreenSeg : Word;                { *Segment of video buffer }
  39.   DesqViewVersion : Word;          { *0 if DesqView not active }
  40.   ScreenCols : Byte;               { *Number of columns on screen }
  41.   ScreenRows : Byte;               { *Number of rows on screen }
  42.   ScreenAdapterType : AdapterType; { *Adapter type }
  43.   ScreenVideoMode : Byte;          { *Video mode }
  44.   ScreenFontSize : FontSize;       { *Font size }
  45.   BiosVideoMode : Byte Absolute $0040:$0049; { Video Mode byte in Bios data }
  46.   CheckSnow : Boolean;             { If True, wait for retrace on CGA }
  47.   DirectVideo : Boolean;           { If False, use BIOS }
  48.   {
  49.     Fields marked with "*" are set by GetBiosInfo. In a TSR, if
  50.     ScreenVideoMode <> BiosVideoMode, you should GetBiosInfo again.
  51.   }
  52.  
  53. Procedure GetBiosInfo;
  54. { Get information on current video adapter }
  55.  
  56. Procedure FillWord(Var Dest; Count, Value : Word);
  57. { Like FillChar, only with words (faster than FillChar) }
  58.  
  59. Function CursorPosition : Word;
  60. { Returns current cursor position on page 0.  Hi=Row, Lo=Col base 1. }
  61.  
  62. Procedure SetCursorPosition(RowCol : Word);
  63. { Sets cursor position }
  64.  
  65. Procedure PutWord(RowCol, Value : Word);
  66. { Write a word (Hi=Attribute, Lo=Character) to screen at indicated position }
  67.  
  68. Procedure PutWords(Var Source; RowCol, Count : Word);
  69. { Copy words to screen beginning at indicated position up to end of row }
  70.  
  71. Procedure GetWords(Var Dest; RowCol, Count : Word);
  72. { Copy words from screen beginning at indicated position up to end of row }
  73.  
  74. Function ScreenAreaSize(X1, Y1, X2, Y2 : Byte) : Word;
  75. { Returns the number of bytes required by SaveScreenArea. }
  76.  
  77. Procedure SaveScreenArea(Var Dest; X1, Y1, X2, Y2 : Byte);
  78. { Save a rectangular area of screen.  Coordinates set 1 defines upper-left
  79.   corner, 2 defines lower right corner, top row: X1=1, left col: Y1=1.
  80.   Save area format is described by ScreenSaveHeader above. }
  81.  
  82. Procedure RestoreScreenArea(Var Source);
  83. { Restore a previously saved rectangular area of screen }
  84.  
  85. Implementation
  86. Type
  87.   ScreenSaveArea = Record
  88.     Header : ScreenSaveHeader;
  89.     Data : Array[0..30000] Of Word;
  90.   End;
  91.  
  92. Procedure GetBiosInfo;
  93. External;
  94.  
  95. Procedure FillWord(Var Dest; Count, Value : Word);
  96. External;
  97.  
  98. Function CursorPosition : Word;
  99. External;
  100.  
  101. Procedure SetCursorPosition(RowCol : Word);
  102. External;
  103.  
  104. Procedure PutWord(RowCol, Value : Word);
  105. External;
  106.  
  107. Procedure PutWords(Var Source; RowCol, Count : Word);
  108. External;
  109.  
  110. Procedure GetWords(Var Dest; RowCol, Count : Word);
  111. External;
  112.  
  113. {$L SCREEN.OBJ }
  114.  
  115. Function ScreenAreaSize(X1, Y1, X2, Y2 : Byte) : Word;
  116. Begin
  117.   If X2 > ScreenCols Then X2 := ScreenCols;
  118.   If Y2 > ScreenRows Then Y2 := ScreenRows;
  119.   If (X1 > X2) Or (Y1 > Y2) Then ScreenAreaSize := SizeOf(ScreenSaveHeader)
  120.   Else ScreenAreaSize := SizeOf(ScreenSaveHeader)
  121.     + Succ(X2-X1) * Succ(Y2-Y1) * 2;
  122. End;
  123.  
  124. Procedure SaveScreenArea(Var Dest; X1, Y1, X2, Y2 : Byte);
  125. Var
  126.   SaveArea : ScreenSaveArea Absolute Dest;
  127.   LenPerRow, RowCount, i, j : Word;
  128. Begin
  129.   If X2 > ScreenCols Then X2 := ScreenCols;
  130.   If Y2 > ScreenRows Then Y2 := ScreenRows;
  131.   If X1 > X2 Then LenPerRow := 0 Else LenPerRow := Succ(X2-X1);
  132.   If Y1 > Y2 Then RowCount := 0 Else RowCount := Succ(Y2-Y1);
  133.   With SaveArea, Header Do Begin
  134.     Cursor := CursorPosition;
  135.     RowCol1 := Y1 Shl 8 + X1;
  136.     RowCol2 := Y2 Shl 8 + X2;
  137.     Mode := ScreenVideoMode;
  138.     Compressed := False;
  139.     Size := LenPerRow * RowCount * 2;
  140.     If Size > 0 Then Begin
  141.       j := 0;
  142.       For i := Y1 To Y2 Do Begin
  143.         GetWords(Data[j], i Shl 8 + X1, LenPerRow);
  144.         Inc(j, LenPerRow);
  145.       End;
  146.       If Not DirectVideo Then SetCursorPosition(Cursor);
  147.     End;
  148.   End;
  149. End;
  150.  
  151. Procedure RestoreScreenArea(Var Source);
  152. Var
  153.   SaveArea : ScreenSaveArea Absolute Source;
  154.   LenPerRow, X1, Y1, Y2, i, j : Word;
  155. Begin
  156.   With SaveArea, Header Do Begin
  157.     If Size > 0 Then Begin
  158.       X1 := Lo(RowCol1);
  159.       Y1 := Hi(RowCol1);
  160.       Y2 := Hi(RowCol2);
  161.       LenPerRow := Succ(Lo(RowCol2) - X1);
  162.       j := 0;
  163.       For i := Y1 To Y2 Do Begin
  164.         PutWords(Data[j], i Shl 8 + X1, LenPerRow);
  165.         Inc(j, LenPerRow);
  166.       End;
  167.     End;
  168.     SetCursorPosition(Cursor);
  169.   End;
  170. End;
  171.  
  172. Begin
  173.   DirectVideo := True;
  174.   GetBiosInfo;
  175.   CheckSnow := (ScreenAdapterType = CGA) And (ScreenSeg = $B800);
  176. End.