video.pp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2004 by Armin Diehl
  5. member of the Free Pascal development team
  6. Video unit for netware libc
  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. unit Video;
  14. interface
  15. {$i videoh.inc}
  16. implementation
  17. uses
  18. Libc;
  19. {$i video.inc}
  20. var
  21. MaxVideoBufSize : DWord;
  22. ScreenHandle : scr_t;
  23. CursorIsHidden : boolean;
  24. procedure SysSetCursorType(NewType: Word);
  25. begin
  26. if newType=crHidden then
  27. begin
  28. Libc.DisableInputCursor (ScreenHandle);
  29. cursorIsHidden := true;
  30. end else
  31. begin
  32. cursorIsHidden := false;
  33. case NewType of
  34. crUnderline: Libc.SetCursorStyle (ScreenHandle,CURSOR_NORMAL);
  35. crHalfBlock: Libc.SetCursorStyle (ScreenHandle,CURSOR_TOP);
  36. crBlock : Libc.SetCursorStyle (ScreenHandle,CURSOR_BLOCK);
  37. end;
  38. Libc.EnableInputCursor (ScreenHandle);
  39. end;
  40. end;
  41. procedure SysInitVideo;
  42. VAR height,width,x,y : WORD;
  43. startline, endline : BYTE;
  44. sType,sColorFlag : dword;
  45. begin
  46. DoneVideo;
  47. Libc.ReturnScreenType (sType,sColorFlag);
  48. ScreenColor:= (sColorFlag > 0);
  49. Libc.GetScreenSize(height,width);
  50. ScreenWidth := width;
  51. ScreenHeight:= height;
  52. { TDrawBuffer only has FVMaxWidth elements
  53. larger values lead to crashes }
  54. if ScreenWidth> FVMaxWidth then
  55. ScreenWidth:=FVMaxWidth;
  56. GetOutputCursorPosition(ScreenHandle,y,x);
  57. CursorX := x;
  58. CursorY := y;
  59. (* done in video.inc
  60. { allocate back buffer }
  61. MaxVideoBufSize:= ScreenWidth * ScreenHeight * 2;
  62. VideoBufSize := ScreenWidth * ScreenHeight * 2;
  63. GetMem(VideoBuf,MaxVideoBufSize);
  64. GetMem(OldVideoBuf,MaxVideoBufSize);
  65. *)
  66. {grab current screen contents}
  67. // Libc.SaveFullScreen (ScreenHandle,VideoBuf);
  68. // Move (VideoBuf^, OldVideoBuf^, MaxVideoBufSize);
  69. // LockUpdateScreen := 0;
  70. SysSetCursorType (crBlock);
  71. end;
  72. procedure SysDoneVideo;
  73. begin
  74. SetCursorType(crUnderLine);
  75. end;
  76. function SysGetCapabilities: Word;
  77. begin
  78. SysGetCapabilities:=cpColor or cpChangeCursor;
  79. end;
  80. procedure SysSetCursorPos(NewCursorX, NewCursorY: Word);
  81. begin
  82. Libc.PositionInputCursor(ScreenHandle,NewCursorY,NewCursorX);
  83. end;
  84. function SysGetCursorType: Word;
  85. var style : word;
  86. begin
  87. if cursorIsHidden then
  88. begin
  89. SysGetCursorType := crHidden;
  90. exit;
  91. end;
  92. Libc.GetCursorStyle (ScreenHandle,style);
  93. case style of
  94. //CURSOR_NORMAL : SysGetCursorType := crUnderline;
  95. CURSOR_THICK : SysGetCursorType := crBlock;
  96. CURSOR_BLOCK : SysGetCursorType := crBlock;
  97. CURSOR_TOP : SysGetCursorType := crHalfBlock
  98. else
  99. SysGetCursorType := crUnderline;
  100. end;
  101. end;
  102. procedure SysUpdateScreen(Force: Boolean);
  103. begin
  104. {$ifdef debug}
  105. if VideoBuf = nil then
  106. begin
  107. __ConsolePrintf ('Fatal: Video buff accessed after DoneVideo');
  108. exit;
  109. end;
  110. {$endif}
  111. if (LockUpdateScreen<>0) or (VideoBufSize = 0) then
  112. exit;
  113. if not force then
  114. begin
  115. asm
  116. pushl %esi
  117. pushl %edi
  118. movl VideoBuf,%esi
  119. movl OldVideoBuf,%edi
  120. movl VideoBufSize,%ecx
  121. shrl $2,%ecx
  122. repe
  123. cmpsl
  124. setne force
  125. popl %edi
  126. popl %esi
  127. end;
  128. end;
  129. if Force then
  130. Libc.RestoreScreenArea(ScreenHandle,0,0,ScreenHeight,ScreenWidth,VideoBuf);
  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. VideoBuf := nil;
  166. VideoBufSize := 0;
  167. ScreenHandle := Libc.getscreenhandle;
  168. SetVideoDriver (SysVideoDriver);
  169. end.