video.pas 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. {
  2. $Id$
  3. System independent low-level video interface
  4. Based on Daniel Mantion's interface designs
  5. Copyright (c) 1997 Balazs Scheidler ([email protected])
  6. This library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Library General Public
  8. License as published by the Free Software Foundation; either
  9. version 2 of the License, or (at your option) any later version.
  10. This library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Library General Public License for more details.
  14. You should have received a copy of the GNU Library General Public
  15. License along with this library; if not, write to the Free
  16. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. Todo:
  19. - getting escape sequences from termcap
  20. - implement library on other platforms (OS/2)
  21. ****************************************************************************}
  22. unit Video;
  23. interface
  24. uses
  25. ApiComm;
  26. {$i platform.inc}
  27. type
  28. PVideoMode = ^TVideoMode;
  29. TVideoMode = record
  30. Col,Row : Word;
  31. Color : Boolean;
  32. end;
  33. TVideoModeSelector = function (const VideoMode: TVideoMode; Params: Longint): Boolean;
  34. TVideoCell = Word;
  35. PVideoCell = ^TVideoCell;
  36. TVideoBuf = array[0..32767] of TVideoCell;
  37. PVideoBuf = ^TVideoBuf;
  38. const
  39. { Foreground and background color constants }
  40. Black = 0;
  41. Blue = 1;
  42. Green = 2;
  43. Cyan = 3;
  44. Red = 4;
  45. Magenta = 5;
  46. Brown = 6;
  47. LightGray = 7;
  48. { Foreground color constants }
  49. DarkGray = 8;
  50. LightBlue = 9;
  51. LightGreen = 10;
  52. LightCyan = 11;
  53. LightRed = 12;
  54. LightMagenta = 13;
  55. Yellow = 14;
  56. White = 15;
  57. { Add-in for blinking }
  58. Blink = 128;
  59. { Capabilities bitmask }
  60. cpUnderLine = $0001;
  61. cpBlink = $0002;
  62. cpColor = $0004;
  63. cpChangeFont = $0008;
  64. cpChangeMode = $0010;
  65. cpChangeCursor = $0020;
  66. { Possible cursor types }
  67. crHidden = 0;
  68. crUnderLine = 1;
  69. crBlock = 2;
  70. crHalfBlock = 3;
  71. { Possible error codes }
  72. vioOK = 0;
  73. errVioInit = errVioBase + 1; { Initialization error, shouldn't occur on DOS, but may
  74. on Linux }
  75. errVioNotSupported = errVioBase + 2; { call to an unsupported function }
  76. errVioNoSuchMode = errVioBase + 3; { No such video mode }
  77. const
  78. ScreenWidth : Word = 0;
  79. ScreenHeight : Word = 0;
  80. var
  81. ScreenColor : Boolean;
  82. CursorX,
  83. CursorY : Word;
  84. LockUpdateScreen : Word;
  85. VideoBuf : PVideoBuf;
  86. VideoBufSize : Longint;
  87. CursorLines : Byte;
  88. const
  89. LowAscii : Boolean=true;
  90. procedure InitVideo;
  91. { Initializes the video subsystem }
  92. procedure DoneVideo;
  93. { Deinitializes the video subsystem }
  94. function GetCapabilities: Word;
  95. { Return the capabilities of the current environment }
  96. procedure ClearScreen;
  97. { Clears the screen }
  98. procedure UpdateScreen(Force: Boolean);
  99. { Force specifies whether the whole screen has to be redrawn, or (if target
  100. platform supports it) its parts only }
  101. procedure SetCursorPos(NewCursorX, NewCursorY: Word);
  102. { Position the cursor to the given position }
  103. function GetCursorType: Word;
  104. { Return the cursor type: Hidden, UnderLine or Block }
  105. procedure SetCursorType(NewType: Word);
  106. { Set the cursor to the given type }
  107. function DefaultVideoModeSelector(const VideoMode: TVideoMode; Params: Longint): Boolean;
  108. procedure GetVideoMode(var Mode: TVideoMode);
  109. { Return dimensions of the current video mode }
  110. procedure SetVideoMode(Mode: TVideoMode);
  111. { Set video-mode to have Mode dimensions, may return errVioNoSuchMode }
  112. procedure RegisterVideoMode(Col, Row: Word; Color: Boolean; VideoModeSelector: TVideoModeSelector; Params: Longint);
  113. { Registers a video mode to be selectable by SetVideoMode }
  114. { moved to interface because we need a way to retrieve the modes }
  115. { System independent part }
  116. type
  117. PVideoModeList = ^TVideoModeList;
  118. TVideoModeList = record
  119. Col, Row: Word;
  120. Color: Boolean;
  121. VideoModeSelector: TVideoModeSelector;
  122. Params: Longint;
  123. Next: PVideoModeList;
  124. end;
  125. const
  126. Modes: PVideoModeList = nil;
  127. {$ifdef go32v2}
  128. var
  129. VideoSeg : word;
  130. {$endif go32v2}
  131. implementation
  132. { Include system dependent part }
  133. { must declare TargetEntry and TargetExit procedures
  134. which can be empty of course }
  135. {$i video.inc}
  136. procedure GetVideoMode(var Mode: TVideoMode);
  137. begin
  138. Mode.Col := ScreenWidth;
  139. Mode.Row := ScreenHeight;
  140. Mode.Color := ScreenColor;
  141. end;
  142. procedure SetVideoMode(Mode: TVideoMode);
  143. var
  144. P: PVideoModeList;
  145. begin
  146. P := Modes;
  147. while (P<>Nil) and ((P^.Row <> Mode.Row) or (P^.Col <> Mode.Col) or (P^.Color<>Mode.Color)) do
  148. P := P^.Next;
  149. if P <> nil then begin
  150. DoneVideo;
  151. ScreenWidth:=$ffff;
  152. ScreenHeight:=$ffff;
  153. P^.VideoModeSelector(PVideoMode(P)^, P^.Params);
  154. InitVideo;
  155. end
  156. else begin
  157. ErrorHandler(errVioNoSuchMode, @Mode);
  158. end;
  159. end;
  160. procedure RegisterVideoMode(Col, Row: Word; Color: Boolean; VideoModeSelector: TVideoModeSelector; Params: Longint);
  161. var
  162. P: PVideoModeList;
  163. begin
  164. New(P);
  165. P^.Col := Col;
  166. P^.Row := Row;
  167. P^.Color := Color;
  168. P^.VideoModeSelector := VideoModeSelector;
  169. P^.Params := Params;
  170. P^.Next := Modes;
  171. Modes := P;
  172. end;
  173. var
  174. OldExitProc : pointer;
  175. procedure UnRegisterVideoModes;{$ifdef PPC_BP}far;{$endif}
  176. var
  177. P: PVideoModeList;
  178. begin
  179. ExitProc:=OldExitProc;
  180. TargetExit;
  181. while assigned(modes) do
  182. begin
  183. p:=modes;
  184. modes:=modes^.next;
  185. dispose(p);
  186. end;
  187. end;
  188. begin
  189. RegisterVideoModes;
  190. TargetEntry;
  191. OldExitProc:=ExitProc;
  192. ExitProc:=@UnRegisterVideoModes;
  193. end.
  194. {
  195. $Log$
  196. Revision 1.3 2000-10-04 11:53:31 pierre
  197. Add TargetEntry and TargetExit (merged)
  198. Revision 1.2 2000/09/24 19:52:21 hajny
  199. * max TVideoBuf size extended
  200. Revision 1.1 2000/07/13 06:29:39 michael
  201. + Initial import
  202. }