video.pas 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. ****************************************************************************}
  21. unit Video;
  22. interface
  23. uses
  24. ApiComm;
  25. {$i platform.inc}
  26. type
  27. PVideoMode = ^TVideoMode;
  28. TVideoMode = record
  29. Col,Row : Word;
  30. Color : Boolean;
  31. end;
  32. TVideoModeSelector = function (const VideoMode: TVideoMode; Params: Longint): Boolean;
  33. TVideoCell = Word;
  34. PVideoCell = ^TVideoCell;
  35. TVideoBuf = array[0..32759] of TVideoCell;
  36. PVideoBuf = ^TVideoBuf;
  37. const
  38. { Foreground and background color constants }
  39. Black = 0;
  40. Blue = 1;
  41. Green = 2;
  42. Cyan = 3;
  43. Red = 4;
  44. Magenta = 5;
  45. Brown = 6;
  46. LightGray = 7;
  47. { Foreground color constants }
  48. DarkGray = 8;
  49. LightBlue = 9;
  50. LightGreen = 10;
  51. LightCyan = 11;
  52. LightRed = 12;
  53. LightMagenta = 13;
  54. Yellow = 14;
  55. White = 15;
  56. { Add-in for blinking }
  57. Blink = 128;
  58. { Capabilities bitmask }
  59. cpUnderLine = $0001;
  60. cpBlink = $0002;
  61. cpColor = $0004;
  62. cpChangeFont = $0008;
  63. cpChangeMode = $0010;
  64. cpChangeCursor = $0020;
  65. { Possible cursor types }
  66. crHidden = 0;
  67. crUnderLine = 1;
  68. crBlock = 2;
  69. crHalfBlock = 3;
  70. { Possible error codes }
  71. vioOK = 0;
  72. errVioInit = errVioBase + 1; { Initialization error, shouldn't occur on DOS, but may
  73. on Linux }
  74. errVioNotSupported = errVioBase + 2; { call to an unsupported function }
  75. errVioNoSuchMode = errVioBase + 3; { No such video mode }
  76. const
  77. ScreenWidth : Word = 0;
  78. ScreenHeight : Word = 0;
  79. var
  80. ScreenColor : Boolean;
  81. CursorX,
  82. CursorY : Word;
  83. LockUpdateScreen : Word;
  84. VideoBuf : PVideoBuf;
  85. VideoBufSize : Longint;
  86. CursorLines : Byte;
  87. const
  88. LowAscii : Boolean = true;
  89. NoExtendedFrame : Boolean = false;
  90. FVMaxWidth = 132;
  91. procedure InitVideo;
  92. { Initializes the video subsystem }
  93. procedure DoneVideo;
  94. { Deinitializes the video subsystem }
  95. function GetCapabilities: Word;
  96. { Return the capabilities of the current environment }
  97. procedure ClearScreen;
  98. { Clears the screen }
  99. procedure UpdateScreen(Force: Boolean);
  100. { Force specifies whether the whole screen has to be redrawn, or (if target
  101. platform supports it) its parts only }
  102. procedure SetCursorPos(NewCursorX, NewCursorY: Word);
  103. { Position the cursor to the given position }
  104. function GetCursorType: Word;
  105. { Return the cursor type: Hidden, UnderLine or Block }
  106. procedure SetCursorType(NewType: Word);
  107. { Set the cursor to the given type }
  108. function DefaultVideoModeSelector(const VideoMode: TVideoMode; Params: Longint): Boolean;
  109. procedure GetVideoMode(var Mode: TVideoMode);
  110. { Return dimensions of the current video mode }
  111. procedure SetVideoMode(Mode: TVideoMode);
  112. { Set video-mode to have Mode dimensions, may return errVioNoSuchMode }
  113. procedure RegisterVideoMode(Col, Row: Word; Color: Boolean; VideoModeSelector: TVideoModeSelector; Params: Longint);
  114. { Registers a video mode to be selectable by SetVideoMode }
  115. { moved to interface because we need a way to retrieve the modes }
  116. { System independent part }
  117. type
  118. PVideoModeList = ^TVideoModeList;
  119. TVideoModeList = record
  120. Col, Row: Word;
  121. Color: Boolean;
  122. VideoModeSelector: TVideoModeSelector;
  123. Params: Longint;
  124. Next: PVideoModeList;
  125. end;
  126. const
  127. Modes: PVideoModeList = nil;
  128. {$ifdef go32v2}
  129. var
  130. VideoSeg : word;
  131. {$endif go32v2}
  132. implementation
  133. { Include system dependent part }
  134. { must declare TargetEntry and TargetExit procedures
  135. which can be empty of course }
  136. {$i video.inc}
  137. procedure GetVideoMode(var Mode: TVideoMode);
  138. begin
  139. Mode.Col := ScreenWidth;
  140. Mode.Row := ScreenHeight;
  141. Mode.Color := ScreenColor;
  142. end;
  143. procedure SetVideoMode(Mode: TVideoMode);
  144. var
  145. P: PVideoModeList;
  146. begin
  147. P := Modes;
  148. while (P<>Nil) and ((P^.Row <> Mode.Row) or (P^.Col <> Mode.Col) or (P^.Color<>Mode.Color)) do
  149. P := P^.Next;
  150. if P <> nil then begin
  151. DoneVideo;
  152. ScreenWidth:=$ffff;
  153. ScreenHeight:=$ffff;
  154. P^.VideoModeSelector(PVideoMode(P)^, P^.Params);
  155. InitVideo;
  156. end
  157. else begin
  158. ErrorHandler(errVioNoSuchMode, @Mode);
  159. end;
  160. end;
  161. procedure RegisterVideoMode(Col, Row: Word; Color: Boolean; VideoModeSelector: TVideoModeSelector; Params: Longint);
  162. var
  163. P: PVideoModeList;
  164. begin
  165. New(P);
  166. P^.Col := Col;
  167. P^.Row := Row;
  168. P^.Color := Color;
  169. P^.VideoModeSelector := VideoModeSelector;
  170. P^.Params := Params;
  171. P^.Next := Modes;
  172. Modes := P;
  173. end;
  174. var
  175. OldExitProc : pointer;
  176. procedure UnRegisterVideoModes;{$ifdef PPC_BP}far;{$endif}
  177. var
  178. P: PVideoModeList;
  179. begin
  180. ExitProc:=OldExitProc;
  181. TargetExit;
  182. while assigned(modes) do
  183. begin
  184. p:=modes;
  185. modes:=modes^.next;
  186. dispose(p);
  187. end;
  188. end;
  189. begin
  190. RegisterVideoModes;
  191. TargetEntry;
  192. OldExitProc:=ExitProc;
  193. ExitProc:=@UnRegisterVideoModes;
  194. end.
  195. {
  196. $Log$
  197. Revision 1.6 2000-11-13 17:22:22 pierre
  198. merge NoExtendedFrame
  199. Revision 1.1.2.4 2000/11/09 08:49:22 pierre
  200. + NoExtendedFrame for terminals with only one graphic set
  201. Revision 1.5 2000/10/15 20:50:17 hajny
  202. * TVideoBuf again TP-compatible
  203. Revision 1.4 2000/10/15 09:22:40 peter
  204. * FVMaxWidth
  205. Revision 1.3 2000/10/04 11:53:31 pierre
  206. Add TargetEntry and TargetExit (merged)
  207. Revision 1.2 2000/09/24 19:52:21 hajny
  208. * max TVideoBuf size extended
  209. Revision 1.1 2000/07/13 06:29:39 michael
  210. + Initial import
  211. }