Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ 3.0r4 - <b>display package</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Display Package

   A full set of high performance screen writing functions is provided in
   the Disp package. The package uses direct screen writing techniques to
   provide text and attribute control, box drawing, screen save and restore
   facilities and many more facilities for the manipulation of text screens.

   The Display package provides fast screen character I/O for the PC and
   true compatibles. The functions comprising the Display package are
   recognizable by the prefix disp_; the header file disp.h must be included
   when using these functions. This section contains an overview of the
   package and its use. For more details on each function refer to the
   individual entry for that function.

Compatibility

   These routines normally write directly into screen memory thereby gaining
   their speed, and are mostly written in assembly language. They are
   suitable for use in text modes only. Although they may work in graphics
   modes their behavior with respect to display attributes will be
   different, many of the functions will not work correctly, and for these

   reasons such use is not recommended. If mixed text and graphics are
   required, the functions contained in the Flash Graphics package should be
   used instead.

   These routines will not work on machines that do not have an IBM-PC
   compatible display or BIOS. For machines that have an IBM compatible
   BIOS, but a display which is not totally IBM compatible, the function
   disp_usebios is provided to force the Display package to do all screen
   access through the BIOS. This option will considerably slow its
   operation.

   The Display package will work correctly with both the ZPM and DOSX
   extenders. It will also work correctly under OS/2.

Display Modes

   The IBM PC supports several different types of display adaptor:
   monochrome, medium resolution color (CGA and MCGA) and high resolution
   color (EGA and VGA). Each of these has, in turn, a number of supported
   screen modes. A full list of the supported display modes can be found

   within the description of the disp_setmode function which follows
   shortly. The current video adaptor and screen mode is ascertained by the
   function disp_open, which must be called to initialize the Display
   package. It is possible for the programmer to discover the current
   display mode via a call to the disp_getmode function. In text modes the
   IBM PC supports 80 column monochrome and 40 and 80 column color displays,
   each with 25 lines. In addition the EGA and VGA adaptors can be
   configured to use the medium resolution character set of the CGA adaptor,
   which allows a 43 line (50 in the case of VGA) display. This latter is
   not a real display mode since it is in fact obtained using the standard
   80 column color mode call, but with special code to set up the character
   set, and modify the number of lines. For this reason there are two
   special functions in the Display package to handle 43 line mode,
   disp_set43 and disp_reset43. All of the mode setting functions need to be
   called before the Display package is set up (with disp_open) in order to
   work correctly. After the display functions are no longer required, a
   call to disp_close will restore the initial cursor type and position, and
   terminate the Display package.

Cursor Size and Position


   The Display package contains a function disp_setcursortype which allows
   the programmer to alter the shape of the hardware text cursor. This
   manipulation of cursor shape is restricted by the design of the hardware
   to being able to specify the scan lines within the character box at which
   the cursor will start and stop. A scan line is one pixel in height. There
   are 8 scan lines to a character in CGA modes and 43/50 line mode, and 14
   in EGA, VGA and monochome modes. Normally the bios carries out an
   automatic conversion in EGA/VGA modes which allows the start and end
   lines to be specified in the same way as for the CGA modes. Thus it is
   only normally necessary to consider whether the display is color or
   monochrome when setting the cursor type. Three macros are defined in
   disp.h which allow the specification of the cursor type to be made
   without reference to the display type. They are:

   DISP_CURSORBLOCK        a full block cursor
   DISP_CURSORHALF         a half block cursor
   DISP_CURSORUL           an underline cursor

   For information on their use refer to the description for

   disp_setcursortype. It is possible to remove the cursor from the display
   using the function disp_hidecursor, and then restore it with the
   complementary function disp_showcursor, These functions are useful for
   temporarily removing the cursor from the screen when displaying help
   messages or menus. Note that these functions can be nested, if
   disp_hidecursor has been called twice then two calls to disp_showcursor
   will be required before the cursor will be displayed.

   Cursor positioning within the Display package is carried out with the
   function disp_move. Care should be taken when mixing Display package
   functions with normal I/O functions such as printf,gets or C++ streams.
   The Display package does not update the hardware cursor position when
   writing to the display screen, and it is therefore essential that
   disp_flush be called prior to the use of any of the normal C functions
   which either write to the display, or obtain input from the user, and
   before the use of any of the C++ stream functions which do likewise.

Display Attributes

   The Display package allows display attributes to be modified. This allows

   inverse video, bright and blinking to be used on both monochrome and
   color displays. In addition separate foreground and background colors can
   be specified on color displays and underline can be used on monochrome
   displays. Three functions are provided for display attribute control. A
   general function disp_setattr, and two specific functions disp_startstand
   and disp_endstand. The latter turn reverse video on and off for
   subsequent disp output operations, while the former allows more general
   attribute control.

   There are a number of macros defined in disp.h for use with the
   disp_setattr function. They are as follows:

   DISP_NORMAL             monochrome:
                           normal video
                           color:
                           white text on a black background

   DISP_NONDISPLAY         monochrome:
                           invisible text
                           color:

                           invisible text on a black background

   DISP_REVERSEVIDEO       monochrome:
                           inverse video
                           color:
                           black text on a white background

   DISP_UNDERLINE          monochrome:
                           underlined text
                           color:
                           blue text on a black background

   For more information see the relevant function descriptions.

Input and Output Functions

   The Display package has a full complement of output functions, disp_putc,
   disp_puts and disp_printf. These functions output at the current position
   set by disp_move. This may not be the same location as the hardware
   cursor unless you have previously called disp_usebios to force output to

   go through the BIOS. If you require the position of the hardware cursor
   to be updated to reflect the position of the next Display package output,
   you must call disp_flush to update the position. All output using these
   functions will use the current attribute as set by disp_setattr. If no
   call to disp_setattr has been made, the default attribute is DISP_NORMAL.

   In addition to these output functions there are two further functions
   disp_peekw and disp_pokew. These functions allow direct access to the
   video display. The disp_peekw function reads a combined character and
   attribute code from the specified display coordinates as an unsigned
   short. The attribute is returned in the high byte and the character in
   the low byte. The character can be obtained by casting the returned value
   to a char or by value&0xff. The attribute can be obtained using value>>8.
   The disp_pokew function places the supplied combined character and
   attribute, again as an unsigned short, at the requested display
   coordinates. The combined character and attribute is obtained using the
   following expression:

       attribute*256+character


   Finally there are the functions disp_eeol and disp_eeop which erase to
   the end of the current line, or to the end of the screen, respectively.
   These functions use the currently set attribute, and it should again be
   remembered that they erase from the current print position and not
   necessarily from the position of the hardware cursor. A convenient method
   of clearing the display screen completely is to use a disp_move(0,0)
   followed by a disp_eeop().

   The reason that the hardware cursor is not set to the current print
   position is that to do so would considerably slow down output if a BIOS
   call to move the hardware cursor were to be issued after each character
   is written. Thus, the hardware cursor is only updated when disp_flush is
   called.

Box Functions

   The Display package provides four functions for manipulating rectangular
   areas (boxes) of the display screen. These functions together allow the
   development of high performance windowing or menu systems. The
   disp_peekbox and disp_pokebox functions allow the contents of rectangular

   areas of the screen to be read into or written from a user provided
   buffer. These functions allow a portion of the display to be temporarily
   saved in a buffer, and restored intact later. The disp_box function uses
   the IBM box drawing characters to draw a border around a rectangular area
   of screen. The function disp_fillbox allows a section of the screen to be
   filled with a particular character and attribute combination.

Global Variables

   A number of global variables are initialized when the Display package is
   opened with a call to the disp_open function described below. The current
   status of these globals can be tested in your program. These globals,
   listed below, should be treated as read only.

   Globals declared in disp.h:

   unsigned char disp_mono       0 if color and 1 if monochrome.
   unsigned char disp_snowycga   !=0 if snowy IBM CGA.
   unsigned char disp_mode       Current display mode.
                                 See disp_setmode().

   unsigned char disp_inited     !=0 if Display package open.
   unsigned char disp_ega        !=0 if IBM EGA or VGA.
   unsigned disp_base            Segment of video display RAM
                                 (MDA = 0B000) (Color = 0B800)

   Globals not declared in disp.h (extern declaration required):

   int disp_activepage           currently active display page.
   int disp_numrows              No. of display rows.
   int disp_numcols              No. of display columns.
   int disp_cursorrow            Row of cursor position.
   int disp_cursorcol            Col. of cursor position.
   int disp_cursortype           current cursor type.
                                 See disp_setcursortype()

   The following is an example of the use of some of the Display package
   functions. The normal procedure in using the Display package is as
   follows:

   1. Set the display mode via a call to disp_mode or disp_set43 if the

   current mode is not desired.

   2. Call disp_open to open the Display package.

   3. Set up the display attributes required using disp_setattr.

   4. Set up the cursor type, if required, using disp_setcursortype.

   5. Use disp_printf etc.

   6. Before getting user input (gets, getche) or using a standard C library
   function which writes to stdin (printf, putc, puts) if this is not
   redirected, call disp_flush to update the cursor position.

   7. Close the Display package with a call to disp_close.

   For further explanation of individual functions, see their respective
   descriptions.

   #include <disp.h>

   #include <conio.h>
   #include <stdlib.h>

   char *string = "Blinking Example String";
   int cursor = ((6*256)+11);

   int main()
   {
       char ch;

       disp_open();
       disp_startstand();
       disp_printf("String displayed after call to ");
       diap_printf("disp_startstand\n");
       disp_endstand();
       disp_setattr(DISP_BLINK | DISP_NORMAL);
       disp_printf("%s\n",string);
       disp_setattr(DISP_INTENSITY | DISP_NORMAL);
       disp_printf("Attribute set to High Intensity\n");
       disp_setattr(DISP_NORMAL);

       disp_usebios();
       disp_printf("String displayed using BIOS\n");
       disp_printf("Change cursor size, Press any key: ");
       disp_setcursortype(cursor);
       disp_flush();
       ch = getch();
       disp_close();
       return EXIT_SUCCESS;
   }

   Refer to the chapter Other C Tools for a helpful example of the use of the
   Display package for producing pop up menus.





Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson