video.pp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. unit Video;
  15. interface
  16. {$i videoh.inc}
  17. implementation
  18. uses
  19. dos;
  20. {$i video.inc}
  21. {$i nwsys.inc}
  22. var
  23. OldVideoBuf : PVideoBuf;
  24. MaxVideoBufSize : DWord;
  25. VideoBufAllocated: boolean;
  26. procedure InitVideo;
  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 DoneVideo;
  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 GetCapabilities: Word;
  72. begin
  73. GetCapabilities:=cpColor or cpChangeCursor;
  74. end;
  75. procedure SetCursorPos(NewCursorX, NewCursorY: Word);
  76. begin
  77. _GotoXY (NewCursorX, NewCursorY);
  78. end;
  79. function GetCursorType: Word;
  80. var startline, endline : byte;
  81. begin
  82. _GetCursorShape (startline, endline);
  83. CASE startline of
  84. 1 : GetCursorType := crBlock;
  85. 5 : GetCursorType := crHalfBlock
  86. ELSE
  87. GetCursorType := crUnderline;
  88. END;
  89. {crHidden ?}
  90. end;
  91. procedure SetCursorType(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. function DefaultVideoModeSelector(const VideoMode: TVideoMode; Params: Longint): Boolean;
  109. begin
  110. DefaultVideoModeSelector:=true;
  111. end;
  112. procedure ClearScreen;
  113. begin
  114. FillWord(VideoBuf^,VideoBufSize div 2,$0720);
  115. UpdateScreen(true);
  116. end;
  117. procedure UpdateScreen(Force: Boolean);
  118. begin
  119. if (LockUpdateScreen<>0) or (VideoBufSize = 0) then
  120. exit;
  121. if not force then
  122. begin
  123. asm
  124. movl VideoBuf,%esi
  125. movl OldVideoBuf,%edi
  126. movl VideoBufSize,%ecx
  127. shrl $2,%ecx
  128. repe
  129. cmpsl
  130. setne force
  131. end;
  132. end;
  133. if Force then
  134. _CopyToScreenMemory (ScreenHeight, ScreenWidth, VideoBuf, 0, 0);
  135. end;
  136. procedure RegisterVideoModes;
  137. begin
  138. { don't know what to do for netware }
  139. RegisterVideoMode(80, 25, True, @DefaultVideoModeSelector, $00000003);
  140. end;
  141. initialization
  142. VideoBufAllocated := false;
  143. VideoBufSize := 0;
  144. RegisterVideoModes;
  145. finalization
  146. UnRegisterVideoModes;
  147. end.