video.pp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Florian Klaempfl
  5. member of the Free Pascal development team
  6. Video unit for netware
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. { 2001/04/16 armin: first version for netware
  14. 2002/02/26 armin: changes for current fpc }
  15. unit Video;
  16. interface
  17. {$i videoh.inc}
  18. implementation
  19. uses
  20. dos;
  21. {$i video.inc}
  22. {$i nwsys.inc}
  23. var
  24. MaxVideoBufSize : DWord;
  25. VideoBufAllocated: boolean;
  26. procedure SysInitVideo;
  27. VAR height,width : WORD;
  28. startline, endline : BYTE;
  29. begin
  30. DoneVideo;
  31. ScreenColor:= (_IsColorMonitor <> 0);
  32. _GetSizeOfScreen (height, width);
  33. ScreenWidth := width;
  34. ScreenHeight:= height;
  35. { TDrawBuffer only has FVMaxWidth elements
  36. larger values lead to crashes }
  37. if ScreenWidth> FVMaxWidth then
  38. ScreenWidth:=FVMaxWidth;
  39. CursorX := _wherex;
  40. CursorY := _wherey;
  41. _GetCursorShape (startline,endline);
  42. {if not ConsoleCursorInfo.bvisible then
  43. CursorLines:=0
  44. else
  45. CursorLines:=ConsoleCursorInfo.dwSize;}
  46. { allocate back buffer }
  47. MaxVideoBufSize:= ScreenWidth * ScreenHeight * 2;
  48. VideoBufSize := ScreenWidth * ScreenHeight * 2;
  49. GetMem(VideoBuf,MaxVideoBufSize);
  50. GetMem(OldVideoBuf,MaxVideoBufSize);
  51. VideoBufAllocated := true;
  52. {grab current screen contents}
  53. _CopyFromScreenMemory (ScreenHeight, ScreenWidth, VideoBuf, 0, 0);
  54. Move (VideoBuf^, OldVideoBuf^, MaxVideoBufSize);
  55. LockUpdateScreen := 0;
  56. {ClearScreen; not needed PM }
  57. end;
  58. procedure SysDoneVideo;
  59. begin
  60. { ClearScreen; also not needed PM }
  61. SetCursorType(crUnderLine);
  62. { SetCursorPos(0,0); also not needed PM }
  63. if videoBufAllocated then
  64. begin
  65. FreeMem(VideoBuf,MaxVideoBufSize);
  66. FreeMem(OldVideoBuf,MaxVideoBufSize);
  67. videoBufAllocated := false;
  68. end;
  69. VideoBufSize:=0;
  70. end;
  71. function SysGetCapabilities: Word;
  72. begin
  73. SysGetCapabilities:=cpColor or cpChangeCursor;
  74. end;
  75. procedure SysSetCursorPos(NewCursorX, NewCursorY: Word);
  76. begin
  77. _GotoXY (NewCursorX, NewCursorY);
  78. end;
  79. function SysGetCursorType: Word;
  80. var startline, endline : byte;
  81. begin
  82. _GetCursorShape (startline, endline);
  83. CASE startline of
  84. 1 : SysGetCursorType := crBlock;
  85. 5 : SysGetCursorType := crHalfBlock
  86. ELSE
  87. SysGetCursorType := crUnderline;
  88. END;
  89. {crHidden ?}
  90. end;
  91. procedure SysSetCursorType(NewType: Word);
  92. begin
  93. if newType=crHidden then
  94. _HideInputCursor
  95. else
  96. begin
  97. case NewType of
  98. crUnderline:
  99. _SetCursorShape (9,$A);
  100. crHalfBlock:
  101. _SetCursorShape (5,$A);
  102. crBlock:
  103. _SetCursorShape (1,$A);
  104. end;
  105. _DisplayInputCursor;
  106. end;
  107. end;
  108. {procedure ClearScreen;
  109. begin
  110. FillWord(VideoBuf^,VideoBufSize div 2,$0720);
  111. UpdateScreen(true);
  112. end;}
  113. procedure SysUpdateScreen(Force: Boolean);
  114. begin
  115. if (LockUpdateScreen<>0) or (VideoBufSize = 0) then
  116. exit;
  117. if not force then
  118. begin
  119. asm
  120. movl VideoBuf,%esi
  121. movl OldVideoBuf,%edi
  122. movl VideoBufSize,%ecx
  123. shrl $2,%ecx
  124. repe
  125. cmpsl
  126. setne force
  127. end;
  128. end;
  129. if Force then
  130. _CopyToScreenMemory (ScreenHeight, ScreenWidth, VideoBuf, 0, 0);
  131. end;
  132. Const
  133. SysVideoModeCount = 1;
  134. SysVMD : Array[0..SysVideoModeCount-1] of TVideoMode = (
  135. (Col: 80; Row : 25; Color : True));
  136. Function SysSetVideoMode (Const Mode : TVideoMode) : Boolean;
  137. begin
  138. SysSetVideoMode := ((Mode.Col = 80) AND (Mode.Row = 25) AND (Mode.Color));
  139. end;
  140. Function SysGetVideoModeData (Index : Word; Var Data : TVideoMode) : boolean;
  141. begin
  142. SysGetVideoModeData:=(Index<=SysVideoModeCount);
  143. If SysGetVideoModeData then
  144. Data:=SysVMD[Index];
  145. end;
  146. Function SysGetVideoModeCount : Word;
  147. begin
  148. SysGetVideoModeCount:=SysVideoModeCount;
  149. end;
  150. Const
  151. SysVideoDriver : TVideoDriver = (
  152. InitDriver : @SysInitVideo;
  153. DoneDriver : @SysDoneVideo;
  154. UpdateScreen : @SysUpdateScreen;
  155. ClearScreen : Nil;
  156. SetVideoMode : @SysSetVideoMode;
  157. GetVideoModeCount : @SysGetVideoModeCount;
  158. GetVideoModeData : @SysGetVideoModedata;
  159. SetCursorPos : @SysSetCursorPos;
  160. GetCursorType : @SysGetCursorType;
  161. SetCursorType : @SysSetCursorType;
  162. GetCapabilities : @SysGetCapabilities
  163. );
  164. initialization
  165. VideoBufAllocated := false;
  166. VideoBufSize := 0;
  167. SetVideoDriver (SysVideoDriver);
  168. end.