video.pp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2005 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. SysSetCursorType (crBlock);
  60. end;
  61. procedure SysDoneVideo;
  62. begin
  63. SetCursorType(crUnderLine);
  64. end;
  65. function SysGetCapabilities: Word;
  66. begin
  67. SysGetCapabilities:=cpColor or cpChangeCursor;
  68. end;
  69. procedure SysSetCursorPos(NewCursorX, NewCursorY: Word);
  70. begin
  71. Libc.PositionInputCursor(ScreenHandle,NewCursorY,NewCursorX);
  72. end;
  73. function SysGetCursorType: Word;
  74. var style : word;
  75. begin
  76. if cursorIsHidden then
  77. begin
  78. SysGetCursorType := crHidden;
  79. exit;
  80. end;
  81. Libc.GetCursorStyle (ScreenHandle,style);
  82. case style of
  83. CURSOR_THICK : SysGetCursorType := crBlock;
  84. CURSOR_BLOCK : SysGetCursorType := crBlock;
  85. CURSOR_TOP : SysGetCursorType := crHalfBlock
  86. else
  87. SysGetCursorType := crUnderline;
  88. end;
  89. end;
  90. procedure SysUpdateScreen(Force: Boolean);
  91. begin
  92. if VideoBuf = nil then
  93. exit;
  94. if (LockUpdateScreen<>0) or (VideoBufSize = 0) then
  95. exit;
  96. if not force then
  97. begin
  98. asm
  99. pushl %esi
  100. pushl %edi
  101. movl VideoBuf,%esi
  102. movl OldVideoBuf,%edi
  103. movl VideoBufSize,%ecx
  104. shrl $2,%ecx
  105. repe
  106. cmpsl
  107. setne force
  108. popl %edi
  109. popl %esi
  110. end;
  111. end;
  112. if Force then
  113. Libc.RestoreScreenArea(ScreenHandle,0,0,ScreenHeight,ScreenWidth,VideoBuf);
  114. end;
  115. Const
  116. SysVideoModeCount = 1;
  117. SysVMD : Array[0..SysVideoModeCount-1] of TVideoMode = (
  118. (Col: 80; Row : 25; Color : True));
  119. Function SysSetVideoMode (Const Mode : TVideoMode) : Boolean;
  120. begin
  121. SysSetVideoMode := ((Mode.Col = 80) AND (Mode.Row = 25) AND (Mode.Color));
  122. end;
  123. Function SysGetVideoModeData (Index : Word; Var Data : TVideoMode) : boolean;
  124. begin
  125. SysGetVideoModeData:=(Index<=SysVideoModeCount);
  126. If SysGetVideoModeData then
  127. Data:=SysVMD[Index];
  128. end;
  129. Function SysGetVideoModeCount : Word;
  130. begin
  131. SysGetVideoModeCount:=SysVideoModeCount;
  132. end;
  133. Const
  134. SysVideoDriver : TVideoDriver = (
  135. InitDriver : @SysInitVideo;
  136. DoneDriver : @SysDoneVideo;
  137. UpdateScreen : @SysUpdateScreen;
  138. ClearScreen : Nil;
  139. SetVideoMode : @SysSetVideoMode;
  140. GetVideoModeCount : @SysGetVideoModeCount;
  141. GetVideoModeData : @SysGetVideoModedata;
  142. SetCursorPos : @SysSetCursorPos;
  143. GetCursorType : @SysGetCursorType;
  144. SetCursorType : @SysSetCursorType;
  145. GetCapabilities : @SysGetCapabilities
  146. );
  147. initialization
  148. VideoBuf := nil;
  149. VideoBufSize := 0;
  150. ScreenHandle := Libc.getscreenhandle;
  151. SetVideoDriver (SysVideoDriver);
  152. end.
  153. {
  154. $Log$
  155. Revision 1.4 2005-01-10 23:34:09 armin
  156. * code cleanup
  157. }