video.pas 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. Common;
  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..3999] 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. {$i video.inc}
  134. procedure GetVideoMode(var Mode: TVideoMode);
  135. begin
  136. Mode.Col := ScreenWidth;
  137. Mode.Row := ScreenHeight;
  138. Mode.Color := ScreenColor;
  139. end;
  140. procedure SetVideoMode(Mode: TVideoMode);
  141. var
  142. P: PVideoModeList;
  143. begin
  144. P := Modes;
  145. while (P<>Nil) and ((P^.Row <> Mode.Row) or (P^.Col <> Mode.Col) or (P^.Color<>Mode.Color)) do
  146. P := P^.Next;
  147. if P <> nil then begin
  148. DoneVideo;
  149. ScreenWidth:=$ffff;
  150. ScreenHeight:=$ffff;
  151. P^.VideoModeSelector(PVideoMode(P)^, P^.Params);
  152. InitVideo;
  153. end
  154. else begin
  155. ErrorHandler(errVioNoSuchMode, @Mode);
  156. end;
  157. end;
  158. procedure RegisterVideoMode(Col, Row: Word; Color: Boolean; VideoModeSelector: TVideoModeSelector; Params: Longint);
  159. var
  160. P: PVideoModeList;
  161. begin
  162. New(P);
  163. P^.Col := Col;
  164. P^.Row := Row;
  165. P^.Color := Color;
  166. P^.VideoModeSelector := VideoModeSelector;
  167. P^.Params := Params;
  168. P^.Next := Modes;
  169. Modes := P;
  170. end;
  171. var
  172. OldExitProc : pointer;
  173. procedure UnRegisterVideoModes;{$ifdef PPC_BP}far;{$endif}
  174. var
  175. P: PVideoModeList;
  176. begin
  177. ExitProc:=OldExitProc;
  178. while assigned(modes) do
  179. begin
  180. p:=modes;
  181. modes:=modes^.next;
  182. dispose(p);
  183. end;
  184. end;
  185. begin
  186. RegisterVideoModes;
  187. OldExitProc:=ExitProc;
  188. ExitProc:=@UnRegisterVideoModes;
  189. end.
  190. {
  191. $Log$
  192. Revision 1.2 2000-02-06 14:28:19 florian
  193. * mouse support for vesa resolutions under go32v2, needs currently the define
  194. custommouse
  195. Revision 1.1 2000/01/06 01:20:31 peter
  196. * moved out of packages/ back to topdir
  197. Revision 1.1 1999/12/23 19:36:47 peter
  198. * place unitfiles in target dirs
  199. Revision 1.1 1999/11/24 23:36:37 peter
  200. * moved to packages dir
  201. Revision 1.9 1999/03/14 22:15:48 florian
  202. * my last changes doesn't work correctly, fixed more
  203. the screen height calculation works incorrect in 80x50 mode
  204. Revision 1.8 1999/03/14 17:43:00 florian
  205. + 80x50 mode support added
  206. * some bugs in VESA mode support removed
  207. Revision 1.7 1999/03/13 17:34:01 florian
  208. * again SetVideoMode fixed
  209. Revision 1.6 1999/03/13 17:30:47 florian
  210. * endless loop in SetVideoMode fixed
  211. Revision 1.5 1999/02/22 12:46:15 peter
  212. + lowascii boolean if ascii < #32 is handled correctly
  213. Revision 1.4 1998/12/23 22:41:08 peter
  214. + color consts
  215. Revision 1.3 1998/12/11 00:13:18 peter
  216. + SetMouseXY
  217. * use far for exitproc procedure
  218. Revision 1.2 1998/12/08 10:09:56 peter
  219. * unregister videomodes at the end
  220. Revision 1.1 1998/12/04 12:48:24 peter
  221. * moved some dirs
  222. Revision 1.14 1998/11/01 20:29:10 peter
  223. + lockupdatescreen counter to not let updatescreen() update
  224. Revision 1.13 1998/10/28 21:18:23 peter
  225. * more fixes
  226. Revision 1.12 1998/10/28 00:02:07 peter
  227. + mouse
  228. + video.clearscreen, video.videobufsize
  229. Revision 1.11 1998/10/27 11:24:20 peter
  230. * fixed the log
  231. Date Version Who Comments
  232. 07/06/97 0.1 bazsi Initial implementation
  233. Console mode (Linux) ready
  234. 07/28/97 0.2 bazsi Linux on foreign terminals ready
  235. 08/27/97 0.3 bazsi Noone else did it, so I did it: DOS support
  236. (I had to boot DOS... ;-(
  237. Mode-switching implemented
  238. 07/28/97 0.3.1 bazsi added support for terminfo. remote terminal
  239. support is broken now
  240. }