File: crt.tex

package info (click to toggle)
fpc 1.0.4-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 30,924 kB
  • ctags: 25,487
  • sloc: pascal: 330,437; makefile: 65,491; xml: 8,493; yacc: 2,858; ansic: 2,206; lex: 648; sh: 256; perl: 87; asm: 63; csh: 25; sed: 21
file content (466 lines) | stat: -rw-r--r-- 11,458 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
%
%   $Id: crt.tex,v 1.1.2.1 2000/12/07 23:19:38 michael Exp $
%   This file is part of the FPC documentation.
%   Copyright (C) 1997, by Michael Van Canneyt
%
%   The FPC documentation is free text; you can redistribute it and/or
%   modify it under the terms of the GNU Library General Public License as
%   published by the Free Software Foundation; either version 2 of the
%   License, or (at your option) any later version.
%
%   The FPC Documentation is distributed in the hope that it will be useful,
%   but WITHOUT ANY WARRANTY; without even the implied warranty of
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%   Library General Public License for more details.
%
%   You should have received a copy of the GNU Library General Public
%   License along with the FPC documentation; see the file COPYING.LIB.  If not,
%   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
%   Boston, MA 02111-1307, USA. 
%
\chapter{The CRT unit.}
\label{ch:crtunit}

\FPCexampledir{crtex}
This chapter describes the \var{CRT} unit for Free Pascal, both under \dos
\linux and \windows. The unit was first written for \dos by Florian kl\"ampfl. 
The unit was ported to \linux by Mark May\footnote{Current
e-mail address \textsf{mmay@dnaco.net}}, and enhanced by Micha\"el Van Canneyt
and Peter Vreman. It works on the \linux console, and in xterm and rxvt windows
under X-Windows. The functionality for both is the same, except that under
\linux the use of an early implementation (versions 0.9.1 and earlier of the
compiler) the crt unit automatically cleared the screen at program startup.
This chapter is divided in two sections. 
\begin{itemize}
\item The first section lists the pre-defined constants, types and variables. 
\item The second section describes the functions which appear in the
interface part of the CRT unit.
\end{itemize}
\section{Types, Variables, Constants}
Color definitions :
\begin{verbatim}
  Black = 0;
  Blue = 1;
  Green = 2;
  Cyan = 3;
  Red = 4;
  Magenta = 5;
  Brown = 6;
  LightGray = 7;
  DarkGray = 8;
  LightBlue = 9;
  LightGreen = 10;
  LightCyan = 11;
  LightRed = 12;
  LightMagenta = 13;
  Yellow = 14;
  White = 15;
  Blink = 128;
\end{verbatim}
Miscellaneous constants
\begin{verbatim}
  TextAttr: Byte = $07;
  TextChar: Char = ' ';
  CheckBreak: Boolean = True;
  CheckEOF: Boolean = False;
  CheckSnow: Boolean = False;
  DirectVideo: Boolean = False;
  LastMode: Word = 3;
  WindMin: Word = $0;
  WindMax: Word = $184f;
  ScreenWidth = 80;
  ScreenHeight = 25;
\end{verbatim}
Some variables for compatibility with Turbo Pascal. However, they're not
used by \fpc.
\begin{verbatim}
var
  checkbreak : boolean;
  checkeof : boolean;
  checksnow : boolean;
\end{verbatim}
The following constants define screen modes on a \dos system:
\begin{verbatim}
Const
  bw40 = 0;
  co40 = 1;
  bw80 = 2;
  co80 = 3;
  mono = 7;
\end{verbatim}
The \var{TextAttr} variable controls the attributes with which characters
are written to screen.
\begin{verbatim}
var TextAttr : byte;
\end{verbatim}
The \var{DirectVideo} variable controls the writing to the screen. If it is
\var{True}, the the cursor is set via direct port access. If \var{False},
then the BIOS is used. This is defined under \dos only.
\begin{verbatim}
var DirectVideo : Boolean;
\end{verbatim}
The \var{Lastmode} variable tells you which mode was last selected for the
screen. It is defined on \dos only.
\begin{verbatim}
var lastmode : Word;
\end{verbatim}

% Procedures and functions.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Procedures and Functions}

\begin{procedure}{AssignCrt}
\Declaration
Procedure AssignCrt (Var F: Text);
\Description
\var{AssignCrt} Assigns a file F to the console. Everything written to 
the file F goes to the console instead. If the console contains a window, 
everything is written to the window instead.

\Errors
None.
\SeeAlso
\seep{Window}
\end{procedure}

\FPCexample{ex1}
 
\begin{procedure}{CursorBig}
\Declaration
Procedure CursorBig ;
\Description
Makes the cursor a big rectangle. 
Not implemented on \linux.
\Errors
None.
\SeeAlso
\seep{CursorOn}, \seep{CursorOff}
\end{procedure}

\begin{procedure}{ClrEol}
\Declaration
Procedure ClrEol ;
\Description
 ClrEol clears the current line, starting from the cursor position, to the
end of the window. The cursor doesn't move
\Errors
None.
\SeeAlso
\seep{DelLine}, \seep{InsLine}, \seep{ClrScr}
\end{procedure}

\FPCexample{ex9}
 
\begin{procedure}{ClrScr}
\Declaration
Procedure ClrScr ;
\Description
 ClrScr clears the current window (using the current colors), 
and sets the cursor in the top left
corner of the current window.
\Errors
None.
\SeeAlso
 \seep{Window} 
\end{procedure}

\FPCexample{ex8}
 
\begin{procedure}{CursorOff}
\Declaration
Procedure CursorOff ;
\Description
Switches the cursor off (i.e. the cursor is no
longer visible). 
Not implemented on \linux.
\Errors
None.
\SeeAlso
\seep{CursorOn}, \seep{CursorBig}
\end{procedure}
\begin{procedure}{CursorOn}
\Declaration
Procedure CursorOn ;
\Description
Switches the cursor on. 
Not implemented on \linux.
\Errors
None.
\SeeAlso
\seep{CursorBig}, \seep{CursorOff}
\end{procedure}
\begin{procedure}{Delay}
\Declaration
Procedure Delay (DTime: Word);
\Description
Delay waits a specified number of milliseconds. The number of specified
seconds is an approximation, and may be off a lot, if system load is high.
\Errors
None
\SeeAlso
\seep{Sound}, \seep{NoSound}
\end{procedure}

\FPCexample{ex15}
 
\begin{procedure}{DelLine}
\Declaration
Procedure DelLine ;
\Description
 DelLine removes the current line. Lines following the current line are 
scrolled 1 line up, and an empty line is inserted at the bottom of the
current window. The cursor doesn't move.
\Errors
None.
\SeeAlso
\seep{ClrEol}, \seep{InsLine}, \seep{ClrScr}
\end{procedure}

\FPCexample{ex11}
 
\begin{procedure}{GotoXY}
\Declaration
Procedure GotoXY (X: Byte; Y: Byte);
\Description
 Positions the cursor at \var{(X,Y)}, \var{X} in horizontal, \var{Y} in
vertical direction relative to the origin of the current window. The origin
is located at \var{(1,1)}, the upper-left corner of the window.

\Errors
None.
\SeeAlso
 \seef{WhereX}, \seef{WhereY}, \seep{Window} 
\end{procedure}

\FPCexample{ex6}
 
\begin{procedure}{HighVideo}
\Declaration
Procedure HighVideo ;
\Description
 HighVideo switches the output to highlighted text. (It sets the high
intensity bit of the video attribute)

\Errors
None.
\SeeAlso
 \seep{TextColor}, \seep{TextBackground}, \seep{LowVideo},
\seep{NormVideo}
\end{procedure}

\FPCexample{ex14}
 
\begin{procedure}{InsLine}
\Declaration
Procedure InsLine ;
\Description
 InsLine inserts an empty line at the current cursor position. 
Lines following the current line are scrolled 1 line down, 
causing the last line to disappear from the window. 
The cursor doesn't move.
\Errors
None.
\SeeAlso
\seep{ClrEol}, \seep{DelLine}, \seep{ClrScr}
\end{procedure}

\FPCexample{ex10}
 
\begin{function}{KeyPressed}
\Declaration
Function KeyPressed  : Boolean;
\Description
 The Keypressed function scans the keyboard buffer and sees if a key has
been pressed. If this is the case, \var{True} is returned. If not,
\var{False} is returned. The \var{Shift, Alt, Ctrl} keys are not reported.
The key is not removed from the buffer, and can hence still be read after
the KeyPressed function has been called.

\Errors
None.
\SeeAlso
\seef{ReadKey}
\end{function}

\FPCexample{ex2}
 
\begin{procedure}{LowVideo}
\Declaration
Procedure LowVideo ;
\Description
 LowVideo switches the output to non-highlighted text. (It clears the high
intensity bit of the video attribute)

\Errors
None.
\SeeAlso
 \seep{TextColor}, \seep{TextBackground}, \seep{HighVideo},
\seep{NormVideo}
\end{procedure}
For an example, see \seep{HighVideo}
\begin{procedure}{NormVideo}
\Declaration
Procedure NormVideo ;
\Description
 NormVideo switches the output to the defaults, read at startup. (The
defaults are read from the cursor position at startup)

\Errors
None.
\SeeAlso
 \seep{TextColor}, \seep{TextBackground}, \seep{LowVideo},
\seep{HighVideo}
\end{procedure}
For an example, see \seep{HighVideo}
\begin{procedure}{NoSound}
\Declaration
Procedure NoSound ;
\Description

Stops the speaker sound.
This is not supported in \linux
\Errors
None.
\SeeAlso
\seep{Sound}
\end{procedure}

\FPCexample{ex16}
 
\begin{function}{ReadKey}
\Declaration
Function ReadKey  : Char;
\Description

The ReadKey function reads 1 key from the keyboard buffer, and returns this.
If an extended or function key has been pressed, then the zero ASCII code is 
returned. You can then read the scan code of the key with a second ReadKey
call.
\textbf{Remark.} Key mappings under Linux can cause the wrong key to be
reported by ReadKey, so caution is needed when using ReadKey.  

\Errors
None.
\SeeAlso
\seef{KeyPressed}
\end{function}


\FPCexample{ex3}


\begin{procedure}{Sound}
\Declaration
Procedure Sound (hz : word);
\Description
 Sounds the speaker at a frequency of \var{hz}.
This is not supported in \linux
\Errors
None.
\SeeAlso
\seep{NoSound}
\end{procedure}

\begin{procedure}{TextBackground}
\Declaration
Procedure TextBackground (CL: Byte);
\Description

TextBackground sets the background color to \var{CL}. \var{CL} can be one of the
predefined color constants.

\Errors
None.
\SeeAlso
 \seep{TextColor}, \seep{HighVideo}, \seep{LowVideo},
\seep{NormVideo}
\end{procedure}

\FPCexample{ex13}
 
\begin{procedure}{TextColor}
\Declaration
Procedure TextColor (CL: Byte);
\Description

TextColor sets the foreground color to \var{CL}. \var{CL} can be one of the
predefined color constants.

\Errors
None.
\SeeAlso
 \seep{TextBackground}, \seep{HighVideo}, \seep{LowVideo},
\seep{NormVideo}
\end{procedure}

\FPCexample{ex12}

\begin{procedure}{TextMode}
\Declaration
procedure TextMode(Mode: Integer);
\Description
\var{TextMode} sets the textmode of the screen (i.e. the number of lines
and columns of the screen). The lower byte is use to set the VGA text mode.

This procedure is only implemented on \dos.
\Errors
None.
\SeeAlso
\seep{Window}
\end{procedure}
 
\begin{function}{WhereX}
\Declaration
Function WhereX  : Byte;
\Description

WhereX returns the current X-coordinate of the cursor, relative to the
current window. The origin is \var{(1,1)}, in the upper-left corner of the
window.

\Errors
None.
\SeeAlso
 \seep{GotoXY}, \seef{WhereY}, \seep{Window} 
\end{function}

\FPCexample{ex7}
 
\begin{function}{WhereY}
\Declaration
Function WhereY  : Byte;
\Description

WhereY returns the current Y-coordinate of the cursor, relative to the
current window. The origin is \var{(1,1)}, in the upper-left corner of the
window.

\Errors
None.
\SeeAlso
 \seep{GotoXY}, \seef{WhereX}, \seep{Window} 
\end{function}

\FPCexample{ex7}
 
\begin{procedure}{Window}
\Declaration
Procedure Window (X1, Y1, X2, Y2: Byte);
\Description
 Window creates a window on the screen, to which output will be sent.
\var{(X1,Y1)} are the coordinates of the upper left corner of the window,
\var{(X2,Y2)} are the coordinates of the bottom right corner of the window.
These coordinates are relative to the entire screen, with the top left
corner equal to \var{(1,1)}
Further coordinate operations, except for the next Window call,
are relative to the window's top left corner.

\Errors
None.
\SeeAlso
\seep{GotoXY}, \seef{WhereX}, \seef{WhereY}, \seep{ClrScr}
\end{procedure}


\FPCexample{ex5}