crt.tex 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. It works on the \linux console, and in xterm and rxvt windows under
  28. X-Windows. The functionality for both is the same, except that under \linux
  29. 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. \procedure{AssignCrt}{(Var F: Text)}
  107. {
  108. Assigns a file F to the console. Everything written to the file F goes to
  109. the console instead. If the console contains a window, everything is written
  110. to the window instead.
  111. }
  112. {None.}{\seep{Window}}
  113. \latex{\inputlisting{crtex/ex1.pp}}
  114. \html{\input{crtex/ex1.tex}}
  115. \Procedure{BigCursor}{Makes the cursor a big rectangle.
  116. Not implemented on \linux.}
  117. {None.}{\seep{CursorOn}, \seep{CursorOff}}
  118. \Procedure {ClrEol}
  119. { ClrEol clears the current line, starting from the cursor position, to the
  120. end of the window. The cursor doesn't move}
  121. {None.}{\seep{DelLine}, \seep{InsLine}, \seep{ClrScr}}
  122. \latex{\inputlisting{crtex/ex9.pp}}
  123. \html{\input{crtex/ex9.tex}}
  124. \procedure {ClrScr}{}
  125. { ClrScr clears the current window (using the current colors),
  126. and sets the cursor in the top left
  127. corner of the current window.}
  128. {None.}{ \seep{Window} }
  129. \latex{\inputlisting{crtex/ex8.pp}}
  130. \html{\input{crtex/ex8.tex}}
  131. \Procedure{CursorOff}{Switches the cursor off (i.e. the cursor is no
  132. longer visible).
  133. Not implemented on \linux.}
  134. {None.}{\seep{CursorOn}, \seep{BigCursor}}
  135. \Procedure{CursorOn}{Switches the cursor on.
  136. Not implemented on \linux.}
  137. {None.}{\seep{BigCursor}, \seep{CursorOff}}
  138. \procedure{Delay}{(DTime: Word)}
  139. {Delay waits a specified number of milliseconds. The number of specified
  140. seconds is an approximation, and may be off a lot, if system load is high.}
  141. {None}{\seep{Sound}, \seep{NoSound}}
  142. \latex{\inputlisting{crtex/ex15.pp}}
  143. \html{\input{crtex/ex15.tex}}
  144. \Procedure {DelLine}
  145. { DelLine removes the current line. Lines following the current line are
  146. scrolled 1 line up, and an empty line is inserted at the bottom of the
  147. current window. The cursor doesn't move.}
  148. {None.}{\seep{ClrEol}, \seep{InsLine}, \seep{ClrScr}}
  149. \latex{\inputlisting{crtex/ex11.pp}}
  150. \html{\input{crtex/ex11.tex}}
  151. \procedure {GotoXY}{(X: Byte; Y: Byte)}
  152. { Positions the cursor at \var{(X,Y)}, \var{X} in horizontal, \var{Y} in
  153. vertical direction relative to the origin of the current window. The origin
  154. is located at \var{(1,1)}, the upper-left corner of the window.
  155. }
  156. {None.}{ \seef{WhereX}, \seef{WhereY}, \seep{Window} }
  157. \latex{\inputlisting{crtex/ex6.pp}}
  158. \html{\input{crtex/ex6.tex}}
  159. \procedure {HighVideo}{}
  160. { HighVideo switches the output to highlighted text. (It sets the high
  161. intensity bit of the video attribute)
  162. }
  163. {None.}{ \seep{TextColor}, \seep{TextBackground}, \seep{LowVideo},
  164. \seep{NormVideo}}
  165. \latex{\inputlisting{crtex/ex14.pp}}
  166. \html{\input{crtex/ex14.tex}}
  167. \procedure {InsLine}{}
  168. { InsLine inserts an empty line at the current cursor position.
  169. Lines following the current line are scrolled 1 line down,
  170. causing the last line to disappear from the window.
  171. The cursor doesn't move.}
  172. {None.}{\seep{ClrEol}, \seep{DelLine}, \seep{ClrScr}}
  173. \latex{\inputlisting{crtex/ex10.pp}}
  174. \html{\input{crtex/ex10.tex}}
  175. \Function {KeyPressed}{Boolean}
  176. { The Keypressed function scans the keyboard buffer and sees if a key has
  177. been pressed. If this is the case, \var{True} is returned. If not,
  178. \var{False} is returned. The \var{Shift, Alt, Ctrl} keys are not reported.
  179. The key is not removed from the buffer, and can hence still be read after
  180. the KeyPressed function has been called.
  181. }
  182. {None.}{\seef{ReadKey}}
  183. \latex{\inputlisting{crtex/ex2.pp}}
  184. \html{\input{crtex/ex2.tex}}
  185. \Procedure {LowVideo}
  186. { LowVideo switches the output to non-highlighted text. (It clears the high
  187. intensity bit of the video attribute)
  188. }
  189. {None.}{ \seep{TextColor}, \seep{TextBackground}, \seep{HighVideo},
  190. \seep{NormVideo}}
  191. For an example, see \seep{HighVideo}
  192. \Procedure {NormVideo}
  193. { NormVideo switches the output to the defaults, read at startup. (The
  194. defaults are read from the cursor position at startup)
  195. }
  196. {None.}{ \seep{TextColor}, \seep{TextBackground}, \seep{LowVideo},
  197. \seep{HighVideo}}
  198. For an example, see \seep{HighVideo}
  199. \Procedure{NoSound}{
  200. Stops the speaker sound.
  201. This is not supported in \linux}{None.}{\seep{Sound}}
  202. \latex{\inputlisting{crtex/ex16.pp}}
  203. \html{\input{crtex/ex16.tex}}
  204. \Function {ReadKey}{Char}
  205. {
  206. The ReadKey function reads 1 key from the keyboard buffer, and returns this.
  207. If an extended or function key has been pressed, then the zero ASCII code is
  208. returned. You can then read the scan code of the key with a second ReadKey
  209. call.
  210. \textbf{Remark.} Key mappings under Linux can cause the wrong key to be
  211. reported by ReadKey, so caution is needed when using ReadKey.
  212. }
  213. {None.}{\seef{KeyPressed}}
  214. \latex{\inputlisting{crtex/ex3.pp}}
  215. \html{\input{crtex/ex3.tex}}
  216. \procedure{Sound}{(hz : word)}
  217. { Sounds the speaker at a frequency of \var{hz}.
  218. This is not supported in \linux}{None.}{\seep{NoSound}}
  219. \procedure {TextBackground}{(CL: Byte)}
  220. {
  221. TextBackground sets the background color to \var{CL}. \var{CL} can be one of the
  222. predefined color constants.
  223. }
  224. {None.}{ \seep{TextColor}, \seep{HighVideo}, \seep{LowVideo},
  225. \seep{NormVideo}}
  226. \latex{\inputlisting{crtex/ex13.pp}}
  227. \html{\input{crtex/ex13.tex}}
  228. \procedure {TextColor}{(CL: Byte)}
  229. {
  230. TextColor sets the foreground color to \var{CL}. \var{CL} can be one of the
  231. predefined color constants.
  232. }
  233. {None.}{ \seep{TextBackground}, \seep{HighVideo}, \seep{LowVideo},
  234. \seep{NormVideo}}
  235. \latex{\inputlisting{crtex/ex12.pp}}
  236. \html{\input{crtex/ex12.tex}}
  237. \Function {WhereX}{Byte}
  238. {
  239. WhereX returns the current X-coordinate of the cursor, relative to the
  240. current window. The origin is \var{(1,1)}, in the upper-left corner of the
  241. window.
  242. }
  243. {None.}{ \seep{GotoXY}, \seef{WhereY}, \seep{Window} }
  244. \latex{\inputlisting{crtex/ex7.pp}}
  245. \html{\input{crtex/ex7.tex}}
  246. \Function {WhereY}{Byte}
  247. {
  248. WhereY returns the current Y-coordinate of the cursor, relative to the
  249. current window. The origin is \var{(1,1)}, in the upper-left corner of the
  250. window.
  251. }
  252. {None.}{ \seep{GotoXY}, \seef{WhereX}, \seep{Window} }
  253. \latex{\inputlisting{crtex/ex7.pp}}
  254. \html{\input{crtex/ex7.tex}}
  255. \procedure {Window}{(X1, Y1, X2, Y2: Byte)}
  256. { Window creates a window on the screen, to which output will be sent.
  257. \var{(X1,Y1)} are the coordinates of the upper left corner of the window,
  258. \var{(X2,Y2)} are the coordinates of the bottom right corner of the window.
  259. These coordinates are relative to the entire screen, with the top left
  260. corner equal to \var{(1,1)}
  261. Further coordinate operations, except for the next Window call,
  262. are relative to the window's top left corner.
  263. }
  264. {None.}{\seep{GotoXY}, \seef{WhereX}, \seef{WhereY}, \seep{ClrScr}}
  265. \latex{\inputlisting{crtex/ex5.pp}}
  266. \html{\input{crtex/ex5.tex}}
  267. %\procedure {ScrollWindow}{(X1,Y1,X2,Y2 : Byte; Count : Longint)}
  268. %{ ScrollWindow scrolls the contents of the window defined by the upper-left
  269. %\var{(X1,Y1)} and lower-right \var{(X2,Y2)} corners \var{count} lines up if
  270. %\var{count} is positive, it scrolls down if \var{count} is negative.
  271. %The new lines are made blank using the current textcolors.
  272. %}
  273. %{None.}{\seep{Window}, \seep{ClrScr}}
  274. %\function {SaveScreenRegion}{(X1,Y1,X2,Y2, var P : pointer)}{Boolean}
  275. %{SaveScreenRegion writes the the contents of the window defined by the upper-left
  276. %\var{(X1,Y1)} and lower-right \var{(X2,Y2)} corners to the location pointed
  277. %to by \var{P}. If \var{P} is \var{nil} then enough memory is allocated to
  278. %contain the contents of the window.
  279. %
  280. %The contents are written as follows : line per line, column per column,
  281. %first the character on screen is written (1 byte), followed by the text
  282. %attribute (1 byte). The size required is therefore
  283. %\var{(Y2-Y1+1)*(X2-X1+1)*2} bytes.
  284. %
  285. %The function returns \var{False} if it couldn't allocate the required
  286. %memory, \var{True} if the memory was allocated.}{None.}
  287. %{\seep{RestoreScreenRegion}, \seep{Window} }
  288. %\procedure {RestoreScreenRegion}{(X1,Y1,X2,Y2, var P : pointer)}
  289. %{SaveScreenRegion writes the the contents of the memory location pointed to
  290. %by \var{P}, to the window defined by the upper-left \var{(X1,Y1)} and
  291. %lower-right \var{(X2,Y2)} corners.
  292. %
  293. %The contents of \var{P} should be arranged as if they are when written by
  294. %a call to the SaveScreenRegion () function.
  295. %
  296. %The memory pointed to by \var{P} is NOT freed.}{None}
  297. %{\seef{SaveScreenRegion}, \seep{Window} }