2
0

crt.tex 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. This chapter describes the \var{CRT} unit for Free Pascal, both under \dos
  23. and \linux. The unit was first written for \dos by Florian kl\"ampfl.
  24. The unit was ported to \linux by Mark May\footnote{Current
  25. e-mail address \textsf{[email protected]}}, and enhanced by Micha\"el Van Canneyt
  26. It works on the \linux console, and in xterm and rxvt windows under
  27. X-Windows. The functionality for both is the same, except that under \linux
  28. the use of an early implementation (versions 0.9.1 an earlier of the
  29. compiler) the crt unit automatically cleared the screen at program startup.
  30. This chapter is divided in two sections.
  31. \begin{itemize}
  32. \item The first section lists the pre-defined constants, types and variables.
  33. \item The second section describes the functions which appear in the
  34. interface part of the CRT unit.
  35. \end{itemize}
  36. \section{Types, Variables, Constants}
  37. Color definitions :
  38. \begin{verbatim}
  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. DarkGray = 8;
  48. LightBlue = 9;
  49. LightGreen = 10;
  50. LightCyan = 11;
  51. LightRed = 12;
  52. LightMagenta = 13;
  53. Yellow = 14;
  54. White = 15;
  55. Blink = 128;
  56. \end{verbatim}
  57. Miscellaneous constants
  58. \begin{verbatim}
  59. TextAttr: Byte = $07;
  60. TextChar: Char = ' ';
  61. CheckBreak: Boolean = True;
  62. CheckEOF: Boolean = False;
  63. CheckSnow: Boolean = False;
  64. DirectVideo: Boolean = False;
  65. LastMode: Word = 3;
  66. WindMin: Word = $0;
  67. WindMax: Word = $184f;
  68. ScreenWidth = 80;
  69. ScreenHeight = 25;
  70. \end{verbatim}
  71. Some variables for compatibility with Turbo Pascal. However, they're not
  72. used by \fpk.
  73. \begin{verbatim}
  74. var
  75. checkbreak : boolean;
  76. checkeof : boolean;
  77. checksnow : boolean;
  78. \end{verbatim}
  79. The following constants define screen modes on a \dos system:
  80. \begin{verbatim}
  81. Const
  82. bw40 = 0;
  83. co40 = 1;
  84. bw80 = 2;
  85. co80 = 3;
  86. mono = 7;
  87. \end{verbatim}
  88. The \var{TextAttr} variable controls the attributes with which characters
  89. are written to screen.
  90. \begin{verbatim}
  91. var TextAttr : byte;
  92. \end{verbatim}
  93. The \var{DirectVideo} variable controls the writing to the screen. If it is
  94. \var{True}, the the cursor is set via direct port access. If \var{False},
  95. then the BIOS is used. This is defined under \dos only.
  96. \begin{verbatim}
  97. var DirectVideo : Boolean;
  98. \end{verbatim}
  99. The \var{Lastmode} variable tells you which mode was last selected for the
  100. screen. It is defined on \dos only.
  101. \begin{verbatim}
  102. var lastmode : Word;
  103. \end{verbatim}
  104. \section{Procedures and Functions}
  105. \procedure{AssignCrt}{(Var F: Text)}
  106. {
  107. Assigns a file F to the console. Everything written to the file F goes to
  108. the console instead. If the console contains a window, everything is written
  109. to the window instead.
  110. }
  111. {None.}{\seep{Window}}
  112. \input{crtex/ex1.tex}
  113. \procedure{Delay}{(DTime: Word)}
  114. {Delay waits a specified number of milliseconds. The number of specified
  115. seconds is a approximation, and may be off a lot, if system load is high.}
  116. {None}{\seep{Sound}, \seep{NoSound}}
  117. \input{crtex/ex15.tex}
  118. \procedure {TextColor}{(CL: Byte)}
  119. {
  120. TextColor sets the foreground color to \var{CL}. \var{CL} can be one of the
  121. predefined color constants.
  122. }
  123. {None.}{ \seep{TextBackground}, \seep{HighVideo}, \seep{LowVideo},
  124. \seep{NormVideo}}
  125. \input{crtex/ex12.tex}
  126. \procedure {TextBackground}{(CL: Byte)}
  127. {
  128. TextBackground sets the background color to \var{CL}. \var{CL} can be one of the
  129. predefined color constants.
  130. }
  131. {None.}{ \seep{TextColor}, \seep{HighVideo}, \seep{LowVideo},
  132. \seep{NormVideo}}
  133. \input{crtex/ex13.tex}
  134. \procedure {HighVideo}{}
  135. { HighVideo switches the output to highlighted text. (It sets the high
  136. intensity bit of the video attribute)
  137. }
  138. {None.}{ \seep{TextColor}, \seep{TextBackground}, \seep{LowVideo},
  139. \seep{NormVideo}}
  140. \input{crtex/ex14.tex}
  141. \Procedure {LowVideo}
  142. { LowVideo switches the output to non-highlighted text. (It clears the high
  143. intensity bit of the video attribute)
  144. }
  145. {None.}{ \seep{TextColor}, \seep{TextBackground}, \seep{HighVideo},
  146. \seep{NormVideo}}
  147. For an example, see \seep{HighVideo}
  148. \Procedure {NormVideo}
  149. { NormVideo switches the output to the defaults, read at startup. (The
  150. defaults are read from the cursor position at startup)
  151. }
  152. {None.}{ \seep{TextColor}, \seep{TextBackground}, \seep{LowVideo},
  153. \seep{HighVideo}}
  154. For an example, see \seep{HighVideo}
  155. \Procedure{BigCursor}{Makes the cursor a big rectangle.
  156. Not implemented on \linux.}
  157. {None.}{\seep{CursorOn}, \seep{CursorOff}}
  158. \Procedure{CursorOn}{Switches the cursor on.
  159. Not implemented on \linux.}
  160. {None.}{\seep{BigCursor}, \seep{CursorOff}}
  161. \Procedure{CursorOff}{Switches the cursor off (i.e. the cursor is no
  162. longer visible).
  163. Not implemented on \linux.}
  164. {None.}{\seep{CursorOn}, \seep{BigCursor}}
  165. \procedure {GotoXY}{(X: Byte; Y: Byte)}
  166. { Positions the cursor at \var{(X,Y)}, \var{X} in horizontal, \var{Y} in
  167. vertical direction relative to the origin of the current window. The origin
  168. is located at \var{(1,1)}, the upper-left corner of the window.
  169. }
  170. {None.}{ \seef{WhereX}, \seef{WhereY}, \seep{Window} }
  171. \input{crtex/ex6.tex}
  172. \Function {WhereX}{Byte}
  173. {
  174. WhereX returns the current X-coordinate of the cursor, relative to the
  175. current window. The origin is \var{(1,1)}, in the upper-left corner of the
  176. window.
  177. }
  178. {None.}{ \seep{GotoXY}, \seef{WhereY}, \seep{Window} }
  179. \input{crtex/ex7.tex}
  180. \Function {WhereY}{Byte}
  181. {
  182. WhereY returns the current Y-coordinate of the cursor, relative to the
  183. current window. The origin is \var{(1,1)}, in the upper-left corner of the
  184. window.
  185. }
  186. {None.}{ \seep{GotoXY}, \seef{WhereX}, \seep{Window} }
  187. \input{crtex/ex7.tex}
  188. \procedure {Window}{(X1, Y1, X2, Y2: Byte)}
  189. { Window creates a window on the screen, to which output will be sent.
  190. \var{(X1,Y1)} are the coordinates of the upper left corner of the window,
  191. \var{(X2,Y2)} are the coordinates of the bottom right corner of the window.
  192. These coordinates are relative to the entire screen, with the top left
  193. corner equal to \var{(1,1)}
  194. Further coordinate operations, except for the next Window call,
  195. are relative to the window's top left corner.
  196. }
  197. {None.}{\seep{GotoXY}, \seef{WhereX}, \seef{WhereY}, \seep{ClrScr}}
  198. \input{crtex/ex5.tex}
  199. \procedure {ClrScr}{}
  200. { ClrScr clears the current window (using the current colors),
  201. and sets the cursor in the top left
  202. corner of the current window.}
  203. {None.}{ \seep{Window} }
  204. \input{crtex/ex8.tex}
  205. %\procedure {ScrollWindow}{(X1,Y1,X2,Y2 : Byte; Count : Longint)}
  206. %{ ScrollWindow scrolls the contents of the window defined by the upper-left
  207. %\var{(X1,Y1)} and lower-right \var{(X2,Y2)} corners \var{count} lines up if
  208. %\var{count} is positive, it scrolls down if \var{count} is negative.
  209. %The new lines are made blank using the current textcolors.
  210. %}
  211. %{None.}{\seep{Window}, \seep{ClrScr}}
  212. %\function {SaveScreenRegion}{(X1,Y1,X2,Y2, var P : pointer)}{Boolean}
  213. %{SaveScreenRegion writes the the contents of the window defined by the upper-left
  214. %\var{(X1,Y1)} and lower-right \var{(X2,Y2)} corners to the location pointed
  215. %to by \var{P}. If \var{P} is \var{nil} then enough memory is allocated to
  216. %contain the contents of the window.
  217. %
  218. %The contents are written as follows : line per line, column per column,
  219. %first the character on screen is written (1 byte), followed by the text
  220. %attribute (1 byte). The size required is therefore
  221. %\var{(Y2-Y1+1)*(X2-X1+1)*2} bytes.
  222. %
  223. %The function returns \var{False} if it couldn't allocate the required
  224. %memory, \var{True} if the memory was allocated.}{None.}
  225. %{\seep{RestoreScreenRegion}, \seep{Window} }
  226. %\procedure {RestoreScreenRegion}{(X1,Y1,X2,Y2, var P : pointer)}
  227. %{SaveScreenRegion writes the the contents of the memory location pointed to
  228. %by \var{P}, to the window defined by the upper-left \var{(X1,Y1)} and
  229. %lower-right \var{(X2,Y2)} corners.
  230. %
  231. %The contents of \var{P} should be arranged as if they are when written by
  232. %a call to the SaveScreenRegion () function.
  233. %
  234. %The memory pointed to by \var{P} is NOT freed.}{None}
  235. %{\seef{SaveScreenRegion}, \seep{Window} }
  236. \Procedure {ClrEol}
  237. { ClrEol clears the current line, starting from the cursor position, to the
  238. end of the window. The cursor doesn't move}
  239. {None.}{\seep{DelLine}, \seep{InsLine}, \seep{ClrScr}}
  240. \input{crtex/ex9.tex}
  241. \Procedure {DelLine}
  242. { DelLine removes the current line. Lines following the current line are
  243. scrolled 1 line up, and an empty line is inserted at the bottom of the
  244. current window. The cursor doesn't move.}
  245. {None.}{\seep{ClrEol}, \seep{InsLine}, \seep{ClrScr}}
  246. \input{crtex/ex11.tex}
  247. \procedure {InsLine}{}
  248. { InsLine inserts an empty line at the current cursor position.
  249. Lines following the current line are scrolled 1 line down,
  250. causing the last line to disappear from the window.
  251. The cursor doesn't move.}
  252. {None.}{\seep{ClrEol}, \seep{DelLine}, \seep{ClrScr}}
  253. \input{crtex/ex10.tex}
  254. \Function {KeyPressed}{Boolean}
  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} 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. }
  261. {None.}{\seef{ReadKey}}
  262. \input{crtex/ex2.tex}
  263. \Function {ReadKey}{Char}
  264. {
  265. The ReadKey function reads 1 key from the keyboard buffer, and returns this.
  266. If an extended or function key has been pressed, then the zero ASCII code is
  267. returned. You can then read the scan code of the key with a second ReadKey
  268. call.
  269. \textbf{Remark.} Key mappings under Linux can cause the wrong key to be
  270. reported by ReadKey, so caution is needed when using ReadKey.
  271. }
  272. {None.}{\seef{KeyPressed}}
  273. \input{crtex/ex3.tex}
  274. \procedure{Sound}{(hz : word)}
  275. { Sounds the speaker at a frequency of \var{hz}.
  276. This is not supported in \linux}{None.}{\seep{NoSound}}
  277. \Procedure{NoSound}{
  278. Stops the speaker sound.
  279. This is not supported in \linux}{None.}{\seep{Sound}}
  280. \input{crtex/ex16.tex}