crt.tex 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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. This chapter describes the \var{CRT} unit for Free Pascal, both under \dos
  24. and \linux. The unit was first written for \dos by Florian kl\"ampfl.
  25. The unit was ported to \linux by Mark May\footnote{Current
  26. e-mail address \textsf{[email protected]}}, and enhanced by Micha\"el Van Canneyt
  27. and Peter Vreman. It works on the \linux console, and in xterm and rxvt windows
  28. under X-Windows. The functionality for both is the same, except that under
  29. \linux the use of an early implementation (versions 0.9.1 an earlier of the
  30. compiler) the crt unit automatically cleared the screen at program startup.
  31. This chapter is divided in two sections.
  32. \begin{itemize}
  33. \item The first section lists the pre-defined constants, types and variables.
  34. \item The second section describes the functions which appear in the
  35. interface part of the CRT unit.
  36. \end{itemize}
  37. \section{Types, Variables, Constants}
  38. Color definitions :
  39. \begin{verbatim}
  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. DarkGray = 8;
  49. LightBlue = 9;
  50. LightGreen = 10;
  51. LightCyan = 11;
  52. LightRed = 12;
  53. LightMagenta = 13;
  54. Yellow = 14;
  55. White = 15;
  56. Blink = 128;
  57. \end{verbatim}
  58. Miscellaneous constants
  59. \begin{verbatim}
  60. TextAttr: Byte = $07;
  61. TextChar: Char = ' ';
  62. CheckBreak: Boolean = True;
  63. CheckEOF: Boolean = False;
  64. CheckSnow: Boolean = False;
  65. DirectVideo: Boolean = False;
  66. LastMode: Word = 3;
  67. WindMin: Word = $0;
  68. WindMax: Word = $184f;
  69. ScreenWidth = 80;
  70. ScreenHeight = 25;
  71. \end{verbatim}
  72. Some variables for compatibility with Turbo Pascal. However, they're not
  73. used by \fpc.
  74. \begin{verbatim}
  75. var
  76. checkbreak : boolean;
  77. checkeof : boolean;
  78. checksnow : boolean;
  79. \end{verbatim}
  80. The following constants define screen modes on a \dos system:
  81. \begin{verbatim}
  82. Const
  83. bw40 = 0;
  84. co40 = 1;
  85. bw80 = 2;
  86. co80 = 3;
  87. mono = 7;
  88. \end{verbatim}
  89. The \var{TextAttr} variable controls the attributes with which characters
  90. are written to screen.
  91. \begin{verbatim}
  92. var TextAttr : byte;
  93. \end{verbatim}
  94. The \var{DirectVideo} variable controls the writing to the screen. If it is
  95. \var{True}, the the cursor is set via direct port access. If \var{False},
  96. then the BIOS is used. This is defined under \dos only.
  97. \begin{verbatim}
  98. var DirectVideo : Boolean;
  99. \end{verbatim}
  100. The \var{Lastmode} variable tells you which mode was last selected for the
  101. screen. It is defined on \dos only.
  102. \begin{verbatim}
  103. var lastmode : Word;
  104. \end{verbatim}
  105. \section{Procedures and Functions}
  106. \begin{procedure}{AssignCrt}
  107. \Declaration
  108. Procedure AssignCrt (Var F: Text);
  109. \Description
  110. Assigns a file F to the console. Everything written to the file F goes to
  111. the console instead. If the console contains a window, everything is written
  112. to the window instead.
  113. \Errors
  114. None.
  115. \SeeAlso
  116. \seep{Window}
  117. \end{procedure}
  118. \latex{\lstinputlisting{crtex/ex1.pp}}
  119. \html{\input{crtex/ex1.tex}}
  120. \begin{procedure}{BigCursor}
  121. \Declaration
  122. Procedure BigCursor ;
  123. \Description
  124. Makes the cursor a big rectangle.
  125. Not implemented on \linux.
  126. \Errors
  127. None.
  128. \SeeAlso
  129. \seep{CursorOn}, \seep{CursorOff}
  130. \end{procedure}
  131. \begin{procedure}{ClrEol}
  132. \Declaration
  133. Procedure ClrEol ;
  134. \Description
  135. ClrEol clears the current line, starting from the cursor position, to the
  136. end of the window. The cursor doesn't move
  137. \Errors
  138. None.
  139. \SeeAlso
  140. \seep{DelLine}, \seep{InsLine}, \seep{ClrScr}
  141. \end{procedure}
  142. \latex{\lstinputlisting{crtex/ex9.pp}}
  143. \html{\input{crtex/ex9.tex}}
  144. \begin{procedure}{ClrScr}
  145. \Declaration
  146. Procedure ClrScr ;
  147. \Description
  148. ClrScr clears the current window (using the current colors),
  149. and sets the cursor in the top left
  150. corner of the current window.
  151. \Errors
  152. None.
  153. \SeeAlso
  154. \seep{Window}
  155. \end{procedure}
  156. \latex{\lstinputlisting{crtex/ex8.pp}}
  157. \html{\input{crtex/ex8.tex}}
  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{BigCursor}
  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{BigCursor}, \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. \latex{\lstinputlisting{crtex/ex15.pp}}
  193. \html{\input{crtex/ex15.tex}}
  194. \begin{procedure}{DelLine}
  195. \Declaration
  196. Procedure DelLine ;
  197. \Description
  198. DelLine removes the current line. Lines following the current line are
  199. scrolled 1 line up, and an empty line is inserted at the bottom of the
  200. current window. The cursor doesn't move.
  201. \Errors
  202. None.
  203. \SeeAlso
  204. \seep{ClrEol}, \seep{InsLine}, \seep{ClrScr}
  205. \end{procedure}
  206. \latex{\lstinputlisting{crtex/ex11.pp}}
  207. \html{\input{crtex/ex11.tex}}
  208. \begin{procedure}{GotoXY}
  209. \Declaration
  210. Procedure GotoXY (X: Byte; Y: Byte);
  211. \Description
  212. Positions the cursor at \var{(X,Y)}, \var{X} in horizontal, \var{Y} in
  213. vertical direction relative to the origin of the current window. The origin
  214. is located at \var{(1,1)}, the upper-left corner of the window.
  215. \Errors
  216. None.
  217. \SeeAlso
  218. \seef{WhereX}, \seef{WhereY}, \seep{Window}
  219. \end{procedure}
  220. \latex{\lstinputlisting{crtex/ex6.pp}}
  221. \html{\input{crtex/ex6.tex}}
  222. \begin{procedure}{HighVideo}
  223. \Declaration
  224. Procedure HighVideo ;
  225. \Description
  226. HighVideo switches the output to highlighted text. (It sets the high
  227. intensity bit of the video attribute)
  228. \Errors
  229. None.
  230. \SeeAlso
  231. \seep{TextColor}, \seep{TextBackground}, \seep{LowVideo},
  232. \seep{NormVideo}
  233. \end{procedure}
  234. \latex{\lstinputlisting{crtex/ex14.pp}}
  235. \html{\input{crtex/ex14.tex}}
  236. \begin{procedure}{InsLine}
  237. \Declaration
  238. Procedure InsLine ;
  239. \Description
  240. InsLine inserts an empty line at the current cursor position.
  241. Lines following the current line are scrolled 1 line down,
  242. causing the last line to disappear from the window.
  243. The cursor doesn't move.
  244. \Errors
  245. None.
  246. \SeeAlso
  247. \seep{ClrEol}, \seep{DelLine}, \seep{ClrScr}
  248. \end{procedure}
  249. \latex{\lstinputlisting{crtex/ex10.pp}}
  250. \html{\input{crtex/ex10.tex}}
  251. \begin{function}{KeyPressed}
  252. \Declaration
  253. Function KeyPressed : Boolean;
  254. \Description
  255. The Keypressed function scans the keyboard buffer and sees if a key has
  256. been pressed. If this is the case, \var{True} is returned. If not,
  257. \var{False} is returned. The \var{Shift, Alt, Ctrl} keys are not reported.
  258. The key is not removed from the buffer, and can hence still be read after
  259. the KeyPressed function has been called.
  260. \Errors
  261. None.
  262. \SeeAlso
  263. \seef{ReadKey}
  264. \end{function}
  265. \latex{\lstinputlisting{crtex/ex2.pp}}
  266. \html{\input{crtex/ex2.tex}}
  267. \begin{procedure}{LowVideo}
  268. \Declaration
  269. Procedure LowVideo ;
  270. \Description
  271. LowVideo switches the output to non-highlighted text. (It clears the high
  272. intensity bit of the video attribute)
  273. \Errors
  274. None.
  275. \SeeAlso
  276. \seep{TextColor}, \seep{TextBackground}, \seep{HighVideo},
  277. \seep{NormVideo}
  278. \end{procedure}
  279. For an example, see \seep{HighVideo}
  280. \begin{procedure}{NormVideo}
  281. \Declaration
  282. Procedure NormVideo ;
  283. \Description
  284. NormVideo switches the output to the defaults, read at startup. (The
  285. defaults are read from the cursor position at startup)
  286. \Errors
  287. None.
  288. \SeeAlso
  289. \seep{TextColor}, \seep{TextBackground}, \seep{LowVideo},
  290. \seep{HighVideo}
  291. \end{procedure}
  292. For an example, see \seep{HighVideo}
  293. \begin{procedure}{NoSound}
  294. \Declaration
  295. Procedure NoSound ;
  296. \Description
  297. Stops the speaker sound.
  298. This is not supported in \linux
  299. \Errors
  300. None.
  301. \SeeAlso
  302. \seep{Sound}
  303. \end{procedure}
  304. \latex{\lstinputlisting{crtex/ex16.pp}}
  305. \html{\input{crtex/ex16.tex}}
  306. \begin{function}{ReadKey}
  307. \Declaration
  308. Function ReadKey : Char;
  309. \Description
  310. The ReadKey function reads 1 key from the keyboard buffer, and returns this.
  311. If an extended or function key has been pressed, then the zero ASCII code is
  312. returned. You can then read the scan code of the key with a second ReadKey
  313. call.
  314. \textbf{Remark.} Key mappings under Linux can cause the wrong key to be
  315. reported by ReadKey, so caution is needed when using ReadKey.
  316. \Errors
  317. None.
  318. \SeeAlso
  319. \seef{KeyPressed}
  320. \end{function}
  321. \latex{\lstinputlisting{crtex/ex3.pp}}
  322. \html{\input{crtex/ex3.tex}}
  323. \begin{procedure}{Sound}
  324. \Declaration
  325. Procedure Sound (hz : word);
  326. \Description
  327. Sounds the speaker at a frequency of \var{hz}.
  328. This is not supported in \linux
  329. \Errors
  330. None.
  331. \SeeAlso
  332. \seep{NoSound}
  333. \end{procedure}
  334. \begin{procedure}{TextBackground}
  335. \Declaration
  336. Procedure TextBackground (CL: Byte);
  337. \Description
  338. TextBackground sets the background color to \var{CL}. \var{CL} can be one of the
  339. predefined color constants.
  340. \Errors
  341. None.
  342. \SeeAlso
  343. \seep{TextColor}, \seep{HighVideo}, \seep{LowVideo},
  344. \seep{NormVideo}
  345. \end{procedure}
  346. \latex{\lstinputlisting{crtex/ex13.pp}}
  347. \html{\input{crtex/ex13.tex}}
  348. \begin{procedure}{TextColor}
  349. \Declaration
  350. Procedure TextColor (CL: Byte);
  351. \Description
  352. TextColor sets the foreground color to \var{CL}. \var{CL} can be one of the
  353. predefined color constants.
  354. \Errors
  355. None.
  356. \SeeAlso
  357. \seep{TextBackground}, \seep{HighVideo}, \seep{LowVideo},
  358. \seep{NormVideo}
  359. \end{procedure}
  360. \latex{\lstinputlisting{crtex/ex12.pp}}
  361. \html{\input{crtex/ex12.tex}}
  362. \begin{function}{WhereX}
  363. \Declaration
  364. Function WhereX : Byte;
  365. \Description
  366. WhereX returns the current X-coordinate of the cursor, relative to the
  367. current window. The origin is \var{(1,1)}, in the upper-left corner of the
  368. window.
  369. \Errors
  370. None.
  371. \SeeAlso
  372. \seep{GotoXY}, \seef{WhereY}, \seep{Window}
  373. \end{function}
  374. \latex{\lstinputlisting{crtex/ex7.pp}}
  375. \html{\input{crtex/ex7.tex}}
  376. \begin{function}{WhereY}
  377. \Declaration
  378. Function WhereY : Byte;
  379. \Description
  380. WhereY returns the current Y-coordinate of the cursor, relative to the
  381. current window. The origin is \var{(1,1)}, in the upper-left corner of the
  382. window.
  383. \Errors
  384. None.
  385. \SeeAlso
  386. \seep{GotoXY}, \seef{WhereX}, \seep{Window}
  387. \end{function}
  388. \latex{\lstinputlisting{crtex/ex7.pp}}
  389. \html{\input{crtex/ex7.tex}}
  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. \latex{\lstinputlisting{crtex/ex5.pp}}
  407. \html{\input{crtex/ex5.tex}}