24.1 Constants, Type and variables

Constants

The following constants describe colors that can be used as foreground and background colors.
 Black         = 0;
 Blue          = 1;
 Green         = 2;
 Cyan          = 3;
 Red           = 4;
 Magenta       = 5;
 Brown         = 6;
 LightGray     = 7;
The following color constants can be used as foreground colors only:
 DarkGray      = 8;
 LightBlue     = 9;
 LightGreen    = 10;
 LightCyan     = 11;
 LightRed      = 12;
 LightMagenta  = 13;
 Yellow        = 14;
 White         = 15;
The foreground and background color can be combined to a color attribute with the following code:
 Attr:=ForeGroundColor + (BackGroundColor shl 4);
The color attribute can be logically or-ed with the blink attribute to produce a blinking character:
 Blink         = 128;
But not all drivers may support this.

The following constants describe the capabilities of a certain video mode:

 cpUnderLine     = $0001;
 cpBlink         = $0002;
 cpColor         = $0004;
 cpChangeFont    = $0008;
 cpChangeMode    = $0010;
 cpChangeCursor  = $0020;
The following constants describe the various supported cursor modes:
 crHidden        = 0;
 crUnderLine     = 1;
 crBlock         = 2;
 crHalfBlock     = 3;
When a video function needs to report an error condition, the following constants are used:
 vioOK              = 0;
 errVioBase         = 1000;
 errVioInit         = errVioBase + 1; { Initialization error}
 errVioNotSupported = errVioBase + 2; { Unsupported function }
 errVioNoSuchMode   = errVioBase + 3; { No such video mode }
The following constants can be read to get some information about the current screen:
 ScreenWidth     : Word = 0;  { Width of the screen, in characters  }
 ScreenHeight    : Word = 0;  { Height of the screen, in characters }
 LowAscii        : Boolean = true;
 NoExtendedFrame : Boolean = false;
 FVMaxWidth      = 132;
The error-handling code uses the following constants:
 errOk              = 0;
 ErrorCode: Longint = ErrOK;
 ErrorInfo: Pointer = nil;
 ErrorHandler: TErrorHandler = DefaultErrorHandler;
The ErrorHandler variable can be set to a custom-error handling function. It is set by default to the DefaultErrorHandler (884) function.

Types

The TVideoMode record describes a videomode. Its fields are self-explaining: Col,Row describe the number of columns and rows on the screen for this mode. Color is True if this mode supports colors, or False if not.
   PVideoMode = ^TVideoMode;
   TVideoMode = record
     Col,Row : Word;
     Color   : Boolean;
   end;
TVideoCell describes one character on the screen. One of the bytes contains the color attribute with which the character is drawn on the screen, and the other byte contains the ASCII code of the character to be drawn. The exact position of the different bytes in the record is operating system specific. On most little-endian systems, the high byte represents the color attribute, while the low-byte represents the ASCII code of the character to be drawn.
 TVideoCell = Word;
 PVideoCell = ^TVideoCell;
The TVideoBuf and PVideoBuf are two types used to represent the screen.
 TVideoBuf = array[0..32759] of TVideoCell;
 PVideoBuf = ^TVideoBuf;
The following type is used when reporting error conditions:
 TErrorHandlerReturnValue = (errRetry, errAbort, errContinue);
Here, errRetry means retry the operation, errAbort abort and return error code and errContinue means abort without returning an errorcode.

The TErrorHandler function is used to register an own error handling function. It should be used when installing a custom error handling function, and must return one of the above values.

 TErrorHandler =
   function (Code: Longint; Info: Pointer): TErrorHandlerReturnValue;
Code should contain the error code for the error condition, and the Info parameter may contain any data type specific to the error code passed to the function.

The TVideoDriver record can be used to install a custom video driver, with the SetVideoDriver (894) call:

 TVideoDriver = Record
   InitDriver        : Procedure;
   DoneDriver        : Procedure;
   UpdateScreen      : Procedure(Force : Boolean);
   ClearScreen       : Procedure;
   SetVideoMode      : Function (Const Mode : TVideoMode) : Boolean;
   GetVideoModeCount : Function : Word;
   GetVideoModeData  : Function(Index : Word; Var Data : TVideoMode) : Boolean;
   SetCursorPos      : procedure (NewCursorX, NewCursorY: Word);
   GetCursorType     : function : Word;
   SetCursorType     : procedure (NewType: Word);
   GetCapabilities   : Function : Word;
 end;

Variables

The following variables contain information about the current screen status:
 ScreenColor      : Boolean;
 CursorX, CursorY : Word;
ScreenColor indicates whether the current screen supports colors. CursorX,CursorY contain the current cursor position.

The following variable forms the heart of the Video unit: The VideoBuf array represents the physical screen. Writing to this array and calling UpdateScreen (895) will write the actual characters to the screen.

 VideoBuf     : PVideoBuf;
 OldVideoBuf  : PVideoBuf;
 VideoBufSize : Longint;
The OldVideoBuf contains the state of the video screen after the last screen update. The UpdateScreen (895) function uses this array to decide which characters on screen should be updated, and which not.

Note that the OldVideoBuf array may be ignored by some drivers, so it should not be used. The Array is in the interface section of the video unit mainly so drivers that need it can make use of it.