video.pp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. LockUpdateScreen := 0;
  50. end;
  51. procedure SysDoneVideo;
  52. begin
  53. SetCursorType(crUnderLine);
  54. end;
  55. function SysGetCapabilities: Word;
  56. begin
  57. SysGetCapabilities:=cpColor or cpChangeCursor;
  58. end;
  59. procedure SysSetCursorPos(NewCursorX, NewCursorY: Word);
  60. begin
  61. _GotoXY (NewCursorX, NewCursorY);
  62. end;
  63. function SysGetCursorType: Word;
  64. var startline, endline : byte;
  65. begin
  66. _GetCursorShape (startline, endline);
  67. CASE startline of
  68. 1 : SysGetCursorType := crBlock;
  69. 5 : SysGetCursorType := crHalfBlock
  70. ELSE
  71. SysGetCursorType := crUnderline;
  72. END;
  73. {crHidden ?}
  74. end;
  75. procedure SysSetCursorType(NewType: Word);
  76. begin
  77. if newType=crHidden then
  78. _HideInputCursor
  79. else
  80. begin
  81. case NewType of
  82. crUnderline:
  83. _SetCursorShape (9,$A);
  84. crHalfBlock:
  85. _SetCursorShape (5,$A);
  86. crBlock:
  87. _SetCursorShape (1,$A);
  88. end;
  89. _DisplayInputCursor;
  90. end;
  91. end;
  92. {procedure ClearScreen;
  93. begin
  94. FillWord(VideoBuf^,VideoBufSize div 2,$0720);
  95. UpdateScreen(true);
  96. end;}
  97. procedure SysUpdateScreen(Force: Boolean);
  98. begin
  99. if VideoBuf = nil then exit;
  100. if (LockUpdateScreen<>0) or (VideoBufSize = 0) then
  101. exit;
  102. if not force then
  103. begin
  104. asm
  105. pushl %esi
  106. pushl %edi
  107. movl VideoBuf,%esi
  108. movl OldVideoBuf,%edi
  109. movl VideoBufSize,%ecx
  110. shrl $2,%ecx
  111. repe
  112. cmpsl
  113. setne force
  114. popl %edi
  115. popl %esi
  116. end;
  117. end;
  118. if Force then
  119. _CopyToScreenMemory (ScreenHeight, ScreenWidth, VideoBuf, 0, 0);
  120. end;
  121. Const
  122. SysVideoModeCount = 1;
  123. SysVMD : Array[0..SysVideoModeCount-1] of TVideoMode = (
  124. (Col: 80; Row : 25; Color : True));
  125. Function SysSetVideoMode (Const Mode : TVideoMode) : Boolean;
  126. begin
  127. SysSetVideoMode := ((Mode.Col = 80) AND (Mode.Row = 25) AND (Mode.Color));
  128. end;
  129. Function SysGetVideoModeData (Index : Word; Var Data : TVideoMode) : boolean;
  130. begin
  131. SysGetVideoModeData:=(Index<=SysVideoModeCount);
  132. If SysGetVideoModeData then
  133. Data:=SysVMD[Index];
  134. end;
  135. Function SysGetVideoModeCount : Word;
  136. begin
  137. SysGetVideoModeCount:=SysVideoModeCount;
  138. end;
  139. Const
  140. SysVideoDriver : TVideoDriver = (
  141. InitDriver : @SysInitVideo;
  142. DoneDriver : @SysDoneVideo;
  143. UpdateScreen : @SysUpdateScreen;
  144. ClearScreen : Nil;
  145. SetVideoMode : @SysSetVideoMode;
  146. GetVideoModeCount : @SysGetVideoModeCount;
  147. GetVideoModeData : @SysGetVideoModedata;
  148. SetCursorPos : @SysSetCursorPos;
  149. GetCursorType : @SysGetCursorType;
  150. SetCursorType : @SysSetCursorType;
  151. GetCapabilities : @SysGetCapabilities
  152. );
  153. initialization
  154. VideoBufAllocated := false;
  155. VideoBufSize := 0;
  156. VideoBuf := nil;
  157. SetVideoDriver (SysVideoDriver);
  158. end.