video.inc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. Const
  12. LockUpdateScreen : Integer = 0;
  13. Procedure LockScreenUpdate;
  14. begin
  15. Inc(LockUpdateScreen);
  16. end;
  17. Procedure UnLockScreenUpdate;
  18. begin
  19. If LockUpdateScreen>0 then
  20. Dec(LockUpdateScreen);
  21. end;
  22. Function GetLockScreenCount : integer;
  23. begin
  24. GetLockScreenCount:=LockUpdateScreen;
  25. end;
  26. Var
  27. CurrentVideoDriver : TVideoDriver;
  28. NextVideoMode : TVideoMode;
  29. Const
  30. VideoInitialized : Boolean = False;
  31. DriverInitialized : Boolean = False;
  32. NextVideoModeSet : Boolean = False;
  33. Function SetVideoDriver (Const Driver : TVideoDriver) : Boolean;
  34. { Sets the videodriver to be used }
  35. begin
  36. If Not VideoInitialized then
  37. Begin
  38. CurrentVideoDriver:=Driver;
  39. DriverInitialized:=true;
  40. NextVideoModeSet:=false;
  41. End;
  42. SetVideoDriver:=Not VideoInitialized;
  43. end;
  44. Procedure GetVideoDriver (Var Driver : TVideoDriver);
  45. { Retrieves the current videodriver }
  46. begin
  47. Driver:=CurrentVideoDriver;
  48. end;
  49. { ---------------------------------------------------------------------
  50. External functions that use the video driver.
  51. ---------------------------------------------------------------------}
  52. Procedure FreeVideoBuf;
  53. begin
  54. if (VideoBuf<>Nil) then
  55. begin
  56. FreeMem(VideoBuf);
  57. FreeMem(OldVideoBuf);
  58. VideoBuf:=Nil;
  59. OldVideoBuf:=Nil;
  60. VideoBufSize:=0;
  61. end;
  62. end;
  63. Procedure AssignVideoBuf (OldCols, OldRows : Word);
  64. Var NewVideoBuf,NewOldVideoBuf : PVideoBuf;
  65. S,I,C,R,NewVideoBufSize : Integer;
  66. begin
  67. S:=SizeOf(TVideoCell);
  68. NewVideoBufSize:=ScreenWidth*ScreenHeight*S;
  69. GetMem(NewVideoBuf,NewVideoBufSize);
  70. GetMem(NewOldVideoBuf,NewVideoBufSize);
  71. // Move contents of old videobuffers to new if there are any.
  72. if (VideoBuf<>Nil) then
  73. begin
  74. If (ScreenWidth<OldCols) then
  75. C:=ScreenWidth
  76. else
  77. C:=OldCols;
  78. If (ScreenHeight<OldRows) then
  79. R:=ScreenHeight
  80. else
  81. R:=OldRows;
  82. For I:=0 to R-1 do
  83. begin
  84. Move(VideoBuf^[I*OldCols],NewVideoBuf^[I*ScreenWidth],S*C);
  85. Move(OldVideoBuf^[I*OldCols],NewOldVideoBuf^[I*ScreenWidth],S*C);
  86. end;
  87. end;
  88. FreeVideoBuf;
  89. VideoBufSize:=NewVideoBufSize;
  90. VideoBuf:=NewVideoBuf;
  91. OldVideoBuf:=NewOldVideoBuf;
  92. end;
  93. Procedure InitVideo;
  94. begin
  95. If Not VideoInitialized then
  96. begin
  97. If Assigned(CurrentVideoDriver.InitDriver) then
  98. CurrentVideoDriver.InitDriver;
  99. VideoInitialized:=True;
  100. if NextVideoModeSet then
  101. SetVideoMode(NextVideoMode)
  102. else
  103. AssignVideoBuf(0,0);
  104. ClearScreen;
  105. end;
  106. end;
  107. Procedure DoneVideo;
  108. begin
  109. If VideoInitialized then
  110. begin
  111. If Assigned(CurrentVideoDriver.DoneDriver) then
  112. CurrentVideoDriver.DoneDriver;
  113. FreeVideoBuf;
  114. VideoInitialized:=False;
  115. end;
  116. end;
  117. Procedure UpdateScreen (Force : Boolean);
  118. begin
  119. If (LockUpdateScreen<=0) and
  120. Assigned(CurrentVideoDriver.UpdateScreen) then
  121. CurrentVideoDriver.UpdateScreen(Force);
  122. end;
  123. Procedure ClearScreen;
  124. begin
  125. // Should this not be the current color ?
  126. FillWord(VideoBuf^,VideoBufSize shr 1,$0720);
  127. If Assigned(CurrentVideoDriver.ClearScreen) then
  128. CurrentVideoDriver.ClearScreen
  129. else
  130. UpdateScreen(True);
  131. FillWord(OldVideoBuf^,VideoBufSize shr 1,$0720);
  132. end;
  133. Procedure SetCursorType (NewType : Word);
  134. begin
  135. if Assigned(CurrentVideoDriver.SetCursorType) then
  136. CurrentVideoDriver.SetCursorType(NewType)
  137. end;
  138. Function GetCursorType : Word;
  139. begin
  140. if Assigned(CurrentVideoDriver.GetCursorType) then
  141. GetCursorType:=CurrentVideoDriver.GetCursorType()
  142. else
  143. GetCursorType:=0;
  144. end;
  145. procedure SetCursorPos(NewCursorX, NewCursorY: Word);
  146. begin
  147. If Assigned(CurrentVideoDriver.SetCursorPos) then
  148. CurrentVideoDriver.SetCursorPos(NewCursorX, NewCursorY)
  149. end;
  150. function GetCapabilities: Word;
  151. begin
  152. If Assigned(CurrentVideoDriver.GetCapabilities) then
  153. GetCapabilities:=CurrentVideoDriver.GetCapabilities()
  154. else
  155. GetCapabilities:=0;
  156. end;
  157. { ---------------------------------------------------------------------
  158. General functions
  159. ---------------------------------------------------------------------}
  160. procedure GetVideoMode(var Mode: TVideoMode);
  161. begin
  162. Mode.Col := ScreenWidth;
  163. Mode.Row := ScreenHeight;
  164. Mode.Color := ScreenColor;
  165. end;
  166. Function SetVideoMode(Const Mode: TVideoMode) : Boolean;
  167. Var
  168. OldR,OldC: Word;
  169. begin
  170. SetVideoMode:=DriverInitialized;
  171. if not DriverInitialized then
  172. exit;
  173. If VideoInitialized then
  174. begin
  175. OldC:=ScreenWidth;
  176. OldR:=ScreenHeight;
  177. If Assigned(CurrentVideoDriver.SetVideoMode) then
  178. SetVideoMode:=CurrentVideoDriver.SetVideoMode(Mode)
  179. else
  180. SetVideoMode:=False;
  181. // Assign buffer
  182. If SetVideoMode then
  183. AssignVideoBuf(OldC,Oldr);
  184. end
  185. else
  186. begin
  187. NextVideoMode:=Mode;
  188. NextVideoModeSet:=true;
  189. end;
  190. end;
  191. Function GetVideoModeCount : Word;
  192. begin
  193. If Assigned(CurrentVideoDriver.GetVideoModeCount) then
  194. GetVideoModeCount:=CurrentVideoDriver.GetVideoModeCount()
  195. else
  196. GetVideoModeCount:=1;
  197. end;
  198. Function GetVideoModeData(Index : Word; Var Data: TVideoMode) : Boolean;
  199. begin
  200. If Assigned(CurrentVideoDriver.GetVideoModeData) then
  201. GetVideoModeData:=CurrentVideoDriver.GetVideoModeData(Index,Data)
  202. else
  203. begin
  204. GetVideoModeData:=(Index=0);
  205. If GetVideoModeData then
  206. GetVideoMode(Data);
  207. end
  208. end;
  209. function DefaultErrorHandler(AErrorCode: Longint; AErrorInfo: Pointer): TErrorHandlerReturnValue;
  210. begin
  211. ErrorCode := AErrorCode;
  212. ErrorInfo := AErrorInfo;
  213. DefaultErrorHandler := errAbort; { return error code }
  214. end;
  215. {
  216. $Log$
  217. Revision 1.7 2002-09-07 15:07:46 peter
  218. * old logs removed and tabs fixed
  219. }