Previous Table of Contents Next


5.2.10.3. CRT Text Basics

There are some general CRT basics to remember in using the procedures for manipulating the screen. There always exists an “active window,” which is the area of the screen that is being manipulated at the particular time. It may be a rectangular section of the screen or, by default, the entire screen. An active window is described by these procedures in terms of Cartesian coordinates. For example, a diagram of an active window is shown here:

  Corner is (1,1)
    +------------------- Increasing X
    |
    |
    |
    |
  Increasing Y

The maximum X and maximum Y are dependent on the size of the active window generated, which can be manipulated.

5.2.10.4. Manipulating the Active Window

Procedures that manipulate the size and appearance of the active window are described here. They include procedures that clear all or parts of the screen and change the text mode and the size of the current active window:

clreol—Clears to the end of current line in the active window
clrscr—Clears the entire window
delline—Deletes the current line in the active window
insline—Inserts a line at the current position
window(x1,y1,x2,y2)—Changes the definition of the current active window
textmode(<TextModeConstant>)—Changes the text mode of the current active window

The first four procedures are described sufficiently. The window() procedure changes the definition of the current active window to (x1,y1) as the top left-hand corner and (x2,y2) as the lower right-hand corner. Incorrectly specified parameters are ignored in the case of all procedures that accept coordinates.

textmode accepts integers that are defined as constants to be BW40, CO40, BW80, and CO80, as the most common ones (BW = black and white, CO = color, 40 = 40×25 screen, 80 = 80×25 screen). In addition, with EGA and VGA cards, a parameter named Font8X8 changes the screen to 43 or 50 line mode when it is added. The default is CO80. A well-behaved program accesses the variable LastMode to store the current mode before changing it. These procedures are shown in Listing 5.40. Note that all attributes are reset when textmode and window are called.

Listing 5.40. A demonstration of active window manipulation.

  program fig40; uses crt;

   var
     origmode: integer;

   procedure screen(inptype: string);
     var
       j: byte;
     begin
       clrscr;
       writeln(‘Text Box (Active Window at 5,5 and 20,20) textmode ’,
                inptype);
       window(5,5,20,20);
       for j := 1 to 40 do
         write(‘Fill!’);
     end;

  begin
    origmode := LastMode;
    textmode(CO80);
    screen(‘CO80’);
    readln;
    textmode(CO40);
    screen(‘CO40’);
    readln;
    textmode(Font8X8 + CO80);
    screen(‘Font8X8 CO80’);
    readln;
    textmode(Font8X8 + CO40);
    screen(‘Font8X8 CO40’);
    readln;
    textmode(origmode);
    writeln(‘Good-Bye and Have a Nice Day!’);
  end.

5.2.10.5. Text Appearance and Position

Procedures to manipulate the appearance and position of text written to the screen are described here. This includes positioning the text as well as color and type of the text and background. Procedures for this case include the following:

gotoxy(x1,y1)—Go to position indicated by
x1,y1, changes definition of “current line”: error is ignored }
textcolor(color)—Sets a foreground color from 0 to 15, as listed below
textbackground(color)—Sets a background color from 0 to 8
highvideo, normvideo—All these, as implied, change intensity of video
lowvideo, byte wherex, wherey—Indicate current position of the cursor (wherex, wherey)

The defaults are normvideo, textcolor(15), and textbackground(0). A demonstration is shown in Listing 5.41. Note that rote screen and color manipulation can get very lengthy in coding; also note that the designations on the colors are defined as constants in the CRT unit to represent each color, either the number as used in this program or the textmode constant seen beside the color block may be used.


Previous Table of Contents Next