video.pp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2005 by Armin Diehl
  4. member of the Free Pascal development team
  5. Video unit for netware libc
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit Video;
  13. interface
  14. {$i videoh.inc}
  15. implementation
  16. uses
  17. Libc;
  18. {$i video.inc}
  19. var
  20. MaxVideoBufSize : DWord;
  21. ScreenHandle : scr_t;
  22. CursorIsHidden : boolean;
  23. procedure SysSetCursorType(NewType: Word);
  24. begin
  25. if newType=crHidden then
  26. begin
  27. Libc.DisableInputCursor (ScreenHandle);
  28. cursorIsHidden := true;
  29. end else
  30. begin
  31. cursorIsHidden := false;
  32. case NewType of
  33. crUnderline: Libc.SetCursorStyle (ScreenHandle,CURSOR_NORMAL);
  34. crHalfBlock: Libc.SetCursorStyle (ScreenHandle,CURSOR_TOP);
  35. crBlock : Libc.SetCursorStyle (ScreenHandle,CURSOR_BLOCK);
  36. end;
  37. Libc.EnableInputCursor (ScreenHandle);
  38. end;
  39. end;
  40. procedure SysInitVideo;
  41. VAR height,width,x,y : WORD;
  42. startline, endline : BYTE;
  43. sType,sColorFlag : dword;
  44. begin
  45. DoneVideo;
  46. Libc.ReturnScreenType (sType,sColorFlag);
  47. ScreenColor:= (sColorFlag > 0);
  48. Libc.GetScreenSize(height,width);
  49. ScreenWidth := width;
  50. ScreenHeight:= height;
  51. { TDrawBuffer only has FVMaxWidth elements
  52. larger values lead to crashes }
  53. if ScreenWidth> FVMaxWidth then
  54. ScreenWidth:=FVMaxWidth;
  55. GetOutputCursorPosition(ScreenHandle,y,x);
  56. CursorX := x;
  57. CursorY := y;
  58. SysSetCursorType (crBlock);
  59. end;
  60. procedure SysDoneVideo;
  61. begin
  62. SetCursorType(crUnderLine);
  63. end;
  64. function SysGetCapabilities: Word;
  65. begin
  66. SysGetCapabilities:=cpColor or cpChangeCursor;
  67. end;
  68. procedure SysSetCursorPos(NewCursorX, NewCursorY: Word);
  69. begin
  70. Libc.PositionInputCursor(ScreenHandle,NewCursorY,NewCursorX);
  71. end;
  72. function SysGetCursorType: Word;
  73. var style : word;
  74. begin
  75. if cursorIsHidden then
  76. begin
  77. SysGetCursorType := crHidden;
  78. exit;
  79. end;
  80. Libc.GetCursorStyle (ScreenHandle,style);
  81. case style of
  82. CURSOR_THICK : SysGetCursorType := crBlock;
  83. CURSOR_BLOCK : SysGetCursorType := crBlock;
  84. CURSOR_TOP : SysGetCursorType := crHalfBlock
  85. else
  86. SysGetCursorType := crUnderline;
  87. end;
  88. end;
  89. procedure SysUpdateScreen(Force: Boolean);
  90. begin
  91. if VideoBuf = nil then
  92. exit;
  93. if (LockUpdateScreen<>0) or (VideoBufSize = 0) then
  94. exit;
  95. if not force then
  96. begin
  97. asm
  98. pushl %esi
  99. pushl %edi
  100. movl VideoBuf,%esi
  101. movl OldVideoBuf,%edi
  102. movl VideoBufSize,%ecx
  103. shrl $2,%ecx
  104. repe
  105. cmpsl
  106. setne force
  107. popl %edi
  108. popl %esi
  109. end;
  110. end;
  111. if Force then
  112. Libc.RestoreScreenArea(ScreenHandle,0,0,ScreenHeight,ScreenWidth,VideoBuf);
  113. end;
  114. Const
  115. SysVideoModeCount = 1;
  116. SysVMD : Array[0..SysVideoModeCount-1] of TVideoMode = (
  117. (Col: 80; Row : 25; Color : True));
  118. Function SysSetVideoMode (Const Mode : TVideoMode) : Boolean;
  119. begin
  120. SysSetVideoMode := ((Mode.Col = 80) AND (Mode.Row = 25) AND (Mode.Color));
  121. end;
  122. Function SysGetVideoModeData (Index : Word; Var Data : TVideoMode) : boolean;
  123. begin
  124. SysGetVideoModeData:=(Index<=SysVideoModeCount);
  125. If SysGetVideoModeData then
  126. Data:=SysVMD[Index];
  127. end;
  128. Function SysGetVideoModeCount : Word;
  129. begin
  130. SysGetVideoModeCount:=SysVideoModeCount;
  131. end;
  132. Const
  133. SysVideoDriver : TVideoDriver = (
  134. InitDriver : @SysInitVideo;
  135. DoneDriver : @SysDoneVideo;
  136. UpdateScreen : @SysUpdateScreen;
  137. ClearScreen : Nil;
  138. SetVideoMode : @SysSetVideoMode;
  139. GetVideoModeCount : @SysGetVideoModeCount;
  140. GetVideoModeData : @SysGetVideoModedata;
  141. SetCursorPos : @SysSetCursorPos;
  142. GetCursorType : @SysGetCursorType;
  143. SetCursorType : @SysSetCursorType;
  144. GetCapabilities : @SysGetCapabilities
  145. );
  146. initialization
  147. VideoBuf := nil;
  148. VideoBufSize := 0;
  149. ScreenHandle := Libc.getscreenhandle;
  150. SetVideoDriver (SysVideoDriver);
  151. end.