crt.tex 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. %
  2. % $Id$
  3. % This file is part of the FPC documentation.
  4. % Copyright (C) 1997, by Michael Van Canneyt
  5. %
  6. % The FPC documentation is free text; you can redistribute it and/or
  7. % modify it under the terms of the GNU Library General Public License as
  8. % published by the Free Software Foundation; either version 2 of the
  9. % License, or (at your option) any later version.
  10. %
  11. % The FPC Documentation is distributed in the hope that it will be useful,
  12. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. % Library General Public License for more details.
  15. %
  16. % You should have received a copy of the GNU Library General Public
  17. % License along with the FPC documentation; see the file COPYING.LIB. If not,
  18. % write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. % Boston, MA 02111-1307, USA.
  20. %
  21. \chapter{The CRT unit.}
  22. \label{ch:crtunit}
  23. \FPCexampledir{crtex}
  24. This chapter describes the \var{CRT} unit for Free Pascal, both under \dos
  25. \linux and \windows. The unit was first written for \dos by Florian kl\"ampfl.
  26. The unit was ported to \linux by Mark May\footnote{Current
  27. e-mail address \textsf{[email protected]}}, and enhanced by Micha\"el Van Canneyt
  28. and Peter Vreman. It works on the \linux console, and in xterm and rxvt windows
  29. under X-Windows. The functionality for both is the same, except that under
  30. \linux the use of an early implementation (versions 0.9.1 an earlier of the
  31. compiler) the crt unit automatically cleared the screen at program startup.
  32. This chapter is divided in two sections.
  33. \begin{itemize}
  34. \item The first section lists the pre-defined constants, types and variables.
  35. \item The second section describes the functions which appear in the
  36. interface part of the CRT unit.
  37. \end{itemize}
  38. \section{Types, Variables, Constants}
  39. Color definitions :
  40. \begin{verbatim}
  41. Black = 0;
  42. Blue = 1;
  43. Green = 2;
  44. Cyan = 3;
  45. Red = 4;
  46. Magenta = 5;
  47. Brown = 6;
  48. LightGray = 7;
  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. Blink = 128;
  58. \end{verbatim}
  59. Miscellaneous constants
  60. \begin{verbatim}
  61. TextAttr: Byte = $07;
  62. TextChar: Char = ' ';
  63. CheckBreak: Boolean = True;
  64. CheckEOF: Boolean = False;
  65. CheckSnow: Boolean = False;
  66. DirectVideo: Boolean = False;
  67. LastMode: Word = 3;
  68. WindMin: Word = $0;
  69. WindMax: Word = $184f;
  70. ScreenWidth = 80;
  71. ScreenHeight = 25;
  72. \end{verbatim}
  73. Some variables for compatibility with Turbo Pascal. However, they're not
  74. used by \fpc.
  75. \begin{verbatim}
  76. var
  77. checkbreak : boolean;
  78. checkeof : boolean;
  79. checksnow : boolean;
  80. \end{verbatim}
  81. The following constants define screen modes on a \dos system:
  82. \begin{verbatim}
  83. Const
  84. bw40 = 0;
  85. co40 = 1;
  86. bw80 = 2;
  87. co80 = 3;
  88. mono = 7;
  89. \end{verbatim}
  90. The \var{TextAttr} variable controls the attributes with which characters
  91. are written to screen.
  92. \begin{verbatim}
  93. var TextAttr : byte;
  94. \end{verbatim}
  95. The \var{DirectVideo} variable controls the writing to the screen. If it is
  96. \var{True}, the the cursor is set via direct port access. If \var{False},
  97. then the BIOS is used. This is defined under \dos only.
  98. \begin{verbatim}
  99. var DirectVideo : Boolean;
  100. \end{verbatim}
  101. The \var{Lastmode} variable tells you which mode was last selected for the
  102. screen. It is defined on \dos only.
  103. \begin{verbatim}
  104. var lastmode : Word;
  105. \end{verbatim}
  106. % Procedures and functions.
  107. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  108. \section{Procedures and Functions}
  109. \begin{procedure}{AssignCrt}
  110. \Declaration
  111. Procedure AssignCrt (Var F: Text);
  112. \Description
  113. \var{AssignCrt} Assigns a file F to the console. Everything written to
  114. the file F goes to the console instead. If the console contains a window,
  115. everything is written to the window instead.
  116. \Errors
  117. None.
  118. \SeeAlso
  119. \seep{Window}
  120. \end{procedure}
  121. \FPCexample{ex1}
  122. \begin{procedure}{CursorBig}
  123. \Declaration
  124. Procedure CursorBig ;
  125. \Description
  126. Makes the cursor a big rectangle.
  127. Not implemented on \linux.
  128. \Errors
  129. None.
  130. \SeeAlso
  131. \seep{CursorOn}, \seep{CursorOff}
  132. \end{procedure}
  133. \begin{procedure}{ClrEol}
  134. \Declaration
  135. Procedure ClrEol ;
  136. \Description
  137. ClrEol clears the current line, starting from the cursor position, to the
  138. end of the window. The cursor doesn't move
  139. \Errors
  140. None.
  141. \SeeAlso
  142. \seep{DelLine}, \seep{InsLine}, \seep{ClrScr}
  143. \end{procedure}
  144. \FPCexample{ex9}
  145. \begin{procedure}{ClrScr}
  146. \Declaration
  147. Procedure ClrScr ;
  148. \Description
  149. ClrScr clears the current window (using the current colors),
  150. and sets the cursor in the top left
  151. corner of the current window.
  152. \Errors
  153. None.
  154. \SeeAlso
  155. \seep{Window}
  156. \end{procedure}
  157. \FPCexample{ex8}
  158. \begin{procedure}{CursorOff}
  159. \Declaration
  160. Procedure CursorOff ;
  161. \Description
  162. Switches the cursor off (i.e. the cursor is no
  163. longer visible).
  164. Not implemented on \linux.
  165. \Errors
  166. None.
  167. \SeeAlso
  168. \seep{CursorOn}, \seep{CursorBig}
  169. \end{procedure}
  170. \begin{procedure}{CursorOn}
  171. \Declaration
  172. Procedure CursorOn ;
  173. \Description
  174. Switches the cursor on.
  175. Not implemented on \linux.
  176. \Errors
  177. None.
  178. \SeeAlso
  179. \seep{CursorBig}, \seep{CursorOff}
  180. \end{procedure}
  181. \begin{procedure}{Delay}
  182. \Declaration
  183. Procedure Delay (DTime: Word);
  184. \Description
  185. Delay waits a specified number of milliseconds. The number of specified
  186. seconds is an approximation, and may be off a lot, if system load is high.
  187. \Errors
  188. None
  189. \SeeAlso
  190. \seep{Sound}, \seep{NoSound}
  191. \end{procedure}
  192. \FPCexample{ex15}
  193. \begin{procedure}{DelLine}
  194. \Declaration
  195. Procedure DelLine ;
  196. \Description
  197. DelLine removes the current line. Lines following the current line are
  198. scrolled 1 line up, and an empty line is inserted at the bottom of the
  199. current window. The cursor doesn't move.
  200. \Errors
  201. None.
  202. \SeeAlso
  203. \seep{ClrEol}, \seep{InsLine}, \seep{ClrScr}
  204. \end{procedure}
  205. \FPCexample{ex11}
  206. \begin{procedure}{GotoXY}
  207. \Declaration
  208. Procedure GotoXY (X: Byte; Y: Byte);
  209. \Description
  210. Positions the cursor at \var{(X,Y)}, \var{X} in horizontal, \var{Y} in
  211. vertical direction relative to the origin of the current window. The origin
  212. is located at \var{(1,1)}, the upper-left corner of the window.
  213. \Errors
  214. None.
  215. \SeeAlso
  216. \seef{WhereX}, \seef{WhereY}, \seep{Window}
  217. \end{procedure}
  218. \FPCexample{ex6}
  219. \begin{procedure}{HighVideo}
  220. \Declaration
  221. Procedure HighVideo ;
  222. \Description
  223. HighVideo switches the output to highlighted text. (It sets the high
  224. intensity bit of the video attribute)
  225. \Errors
  226. None.
  227. \SeeAlso
  228. \seep{TextColor}, \seep{TextBackground}, \seep{LowVideo},
  229. \seep{NormVideo}
  230. \end{procedure}
  231. \FPCexample{ex14}
  232. \begin{procedure}{InsLine}
  233. \Declaration
  234. Procedure InsLine ;
  235. \Description
  236. InsLine inserts an empty line at the current cursor position.
  237. Lines following the current line are scrolled 1 line down,
  238. causing the last line to disappear from the window.
  239. The cursor doesn't move.
  240. \Errors
  241. None.
  242. \SeeAlso
  243. \seep{ClrEol}, \seep{DelLine}, \seep{ClrScr}
  244. \end{procedure}
  245. \FPCexample{ex10}
  246. \begin{function}{KeyPressed}
  247. \Declaration
  248. Function KeyPressed : Boolean;
  249. \Description
  250. The Keypressed function scans the keyboard buffer and sees if a key has
  251. been pressed. If this is the case, \var{True} is returned. If not,
  252. \var{False} is returned. The \var{Shift, Alt, Ctrl} keys are not reported.
  253. The key is not removed from the buffer, and can hence still be read after
  254. the KeyPressed function has been called.
  255. \Errors
  256. None.
  257. \SeeAlso
  258. \seef{ReadKey}
  259. \end{function}
  260. \FPCexample{ex2}
  261. \begin{procedure}{LowVideo}
  262. \Declaration
  263. Procedure LowVideo ;
  264. \Description
  265. LowVideo switches the output to non-highlighted text. (It clears the high
  266. intensity bit of the video attribute)
  267. \Errors
  268. None.
  269. \SeeAlso
  270. \seep{TextColor}, \seep{TextBackground}, \seep{HighVideo},
  271. \seep{NormVideo}
  272. \end{procedure}
  273. For an example, see \seep{HighVideo}
  274. \begin{procedure}{NormVideo}
  275. \Declaration
  276. Procedure NormVideo ;
  277. \Description
  278. NormVideo switches the output to the defaults, read at startup. (The
  279. defaults are read from the cursor position at startup)
  280. \Errors
  281. None.
  282. \SeeAlso
  283. \seep{TextColor}, \seep{TextBackground}, \seep{LowVideo},
  284. \seep{HighVideo}
  285. \end{procedure}
  286. For an example, see \seep{HighVideo}
  287. \begin{procedure}{NoSound}
  288. \Declaration
  289. Procedure NoSound ;
  290. \Description
  291. Stops the speaker sound.
  292. This is not supported in \linux
  293. \Errors
  294. None.
  295. \SeeAlso
  296. \seep{Sound}
  297. \end{procedure}
  298. \FPCexample{ex16}
  299. \begin{function}{ReadKey}
  300. \Declaration
  301. Function ReadKey : Char;
  302. \Description
  303. The ReadKey function reads 1 key from the keyboard buffer, and returns this.
  304. If an extended or function key has been pressed, then the zero ASCII code is
  305. returned. You can then read the scan code of the key with a second ReadKey
  306. call.
  307. \textbf{Remark.} Key mappings under Linux can cause the wrong key to be
  308. reported by ReadKey, so caution is needed when using ReadKey.
  309. \Errors
  310. None.
  311. \SeeAlso
  312. \seef{KeyPressed}
  313. \end{function}
  314. \FPCexample{ex3}
  315. \begin{procedure}{Sound}
  316. \Declaration
  317. Procedure Sound (hz : word);
  318. \Description
  319. Sounds the speaker at a frequency of \var{hz}.
  320. This is not supported in \linux
  321. \Errors
  322. None.
  323. \SeeAlso
  324. \seep{NoSound}
  325. \end{procedure}
  326. \begin{procedure}{TextBackground}
  327. \Declaration
  328. Procedure TextBackground (CL: Byte);
  329. \Description
  330. TextBackground sets the background color to \var{CL}. \var{CL} can be one of the
  331. predefined color constants.
  332. \Errors
  333. None.
  334. \SeeAlso
  335. \seep{TextColor}, \seep{HighVideo}, \seep{LowVideo},
  336. \seep{NormVideo}
  337. \end{procedure}
  338. \FPCexample{ex13}
  339. \begin{procedure}{TextColor}
  340. \Declaration
  341. Procedure TextColor (CL: Byte);
  342. \Description
  343. TextColor sets the foreground color to \var{CL}. \var{CL} can be one of the
  344. predefined color constants.
  345. \Errors
  346. None.
  347. \SeeAlso
  348. \seep{TextBackground}, \seep{HighVideo}, \seep{LowVideo},
  349. \seep{NormVideo}
  350. \end{procedure}
  351. \FPCexample{ex12}
  352. \begin{procedure}{TextMode}
  353. \Declaration
  354. procedure TextMode(Mode: Integer);
  355. \Description
  356. \var{TextMode} sets the textmode of the screen (i.e. the number of lines
  357. and columns of the screen). The lower byte is use to set the VGA text mode.
  358. This procedure is only implemented on \dos.
  359. \Errors
  360. None.
  361. \SeeAlso
  362. \seep{Window}
  363. \end{procedure}
  364. \begin{function}{WhereX}
  365. \Declaration
  366. Function WhereX : Byte;
  367. \Description
  368. WhereX returns the current X-coordinate of the cursor, relative to the
  369. current window. The origin is \var{(1,1)}, in the upper-left corner of the
  370. window.
  371. \Errors
  372. None.
  373. \SeeAlso
  374. \seep{GotoXY}, \seef{WhereY}, \seep{Window}
  375. \end{function}
  376. \FPCexample{ex7}
  377. \begin{function}{WhereY}
  378. \Declaration
  379. Function WhereY : Byte;
  380. \Description
  381. WhereY returns the current Y-coordinate of the cursor, relative to the
  382. current window. The origin is \var{(1,1)}, in the upper-left corner of the
  383. window.
  384. \Errors
  385. None.
  386. \SeeAlso
  387. \seep{GotoXY}, \seef{WhereX}, \seep{Window}
  388. \end{function}
  389. \FPCexample{ex7}
  390. \begin{procedure}{Window}
  391. \Declaration
  392. Procedure Window (X1, Y1, X2, Y2: Byte);
  393. \Description
  394. Window creates a window on the screen, to which output will be sent.
  395. \var{(X1,Y1)} are the coordinates of the upper left corner of the window,
  396. \var{(X2,Y2)} are the coordinates of the bottom right corner of the window.
  397. These coordinates are relative to the entire screen, with the top left
  398. corner equal to \var{(1,1)}
  399. Further coordinate operations, except for the next Window call,
  400. are relative to the window's top left corner.
  401. \Errors
  402. None.
  403. \SeeAlso
  404. \seep{GotoXY}, \seef{WhereX}, \seef{WhereY}, \seep{ClrScr}
  405. \end{procedure}
  406. \FPCexample{ex5}