CRT - Turbo Pascal screen and keyboard handling unit

This chapter describes the CRT unit for Free Pascal, both under dos linux and Windows. The unit was first written for dos by Florian klaempfl. The unit was ported to linux by Mark May and enhanced by Michael 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.

There are some caveats when using the CRT unit:

- Programs using the CRT unit will not be usable when input/output is being redirected on the command-line.
- For similar reasons they are not usable as CGI-scripts for use with a webserver.
- The use of the CRT unit and the graph unit may not always be supported.
- On linux or other unix OSes , executing other programs that expect special terminal behaviour (using one of the special functions in the linux unit) will not work. The terminal is set in RAW mode, which will destroy most terminal emulation settings.

Black color attribute
Blue color attribute
Green color attribute
Cyan color attribute
Red color attribute
Magenta color attribute
Brown color attribute
Light gray color attribute
Dark gray color attribute
Light Blue color attribute
Light green color attribute
Light cyan color attribute
Light red color attribute
Light magenta color attribute
Yellow color attribute
White color attribute
Blink attribute
Mask to filter text attribute
The TextAttr variable controls the attributes with which characters are written to screen.
Text character used when filling
Check for CTRL-Break keystroke. Not used.
Check for EOF on standard input. Not used.
Check snow on CGA screens. Not used.
Use direct video access. DOS only
The DirectVideo variable controls the writing to the screen. If it is True, the the cursor is set via direct port access. If False, then the BIOS is used. This is defined under dos only.
Last screen mode.
The Lastmode variable tells you which mode was last selected for the screen. It is defined on DOS only.
Minimum window dimension
Maximum window dimension
Maximum window X size
Maximum window Y size
Minimum window X size
Minimum window Y size
Current screen width
Current screen height.
40 columns black and white screen mode.
40 columns color screen mode.
40 columns color screen mode.
80 columns black and white screen mode.
80 columns color screen mode.
80 columns color screen mode.
Monochrome screen mode (hercules screens)
Internal ROM font mode
Assign file to CRT.
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.
None.
Show big cursor
CursorBig
makes the cursor a big rectangle. Not implemented on unixes.
None.
Clear from cursor position till end of line.
ClrEol
clears the current line, starting from the cursor position, to the end of the window. The cursor doesn't move
None.
Clear current window.
ClrScr
clears the current window (using the current colors), and sets the cursor in the top left corner of the current window.
None.
Hide cursor
CursorOff
switches the cursor off (i.e. the cursor is no longer visible). Not implemented on unixes.
None.
Display cursor
CursorOn
switches the cursor on. Not implemented on unixes.
None.
Delay program execution.
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.
None
Delete line at cursor position.
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.
None.
Set cursor position on screen.
GotoXY
positions the cursor at (X,Y), X in horizontal, Y in vertical direction relative to the origin of the current window. The origin is located at (1,1), the upper-left corner of the window.
None.
Switch to highlighted text mode
HighVideo
switches the output to highlighted text. (It sets the high intensity bit of the video attribute)
None.
Insert an empty line at cursor position
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.
None.
Check if there is a keypress in the keybuffer
Keypressed
scans the keyboard buffer and sees if a key has been pressed. If this is the case, True is returned. If not, False is returned. The 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.
None.
Switch to low intensity colors.

LowVideo switches the output to non-highlighted text. (It clears the high intensity bit of the video attribute)

For an example, see

None.
Return to normal (startup) modus

NormVideo switches the output to the defaults, read at startup. (The defaults are read from the cursor position at startup)

For an example, see

None.
Stop system speaker
NoSound
stops the speaker sound. This call is not supported on all operating systems.
None.
Read key from keybuffer

ReadKey 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.

Key mappings under Linux can cause the wrong key to be reported by ReadKey, so caution is needed when using ReadKey.

None.
Sound system speaker
Sound
sounds the speaker at a frequency of hz. Under Windows, a system sound is played and the frequency parameter is ignored. On other operating systems, this routine may not be implemented.
None.
Set text background
TextBackground
sets the background color to CL. CL can be one of the predefined color constants.
None.
Set text color
TextColor
sets the foreground color to CL. CL can be one of the predefined color constants.
None.
Set screen mode.

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.

None.
Return X (horizontal) cursor position
WhereX
returns the current X-coordinate of the cursor, relative to the current window. The origin is (1,1), in the upper-left corner of the window.
None.
Return Y (vertical) cursor position
WhereY
returns the current Y-coordinate of the cursor, relative to the current window. The origin is (1,1), in the upper-left corner of the window.

None.
Create new window on screen.
Window
creates a window on the screen, to which output will be sent. (X1,Y1) are the coordinates of the upper left corner of the window, (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 (1,1). Further coordinate operations, except for the next Window call, are relative to the window's top left corner.
None.