Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ screen(HW) — OpenDesktop 2.0.0a

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

console(M)

ioctl(S)

keyboard(HW)

keymap(M)

mapkey(M)

mapchan(M)

multiscreen(M)

scancode(HW)

setcolor(C)

stty(C)

systty(M)

vidi(C)

termcap(M)

tty(M)


 screen(HW)                      19 June 1992                      screen(HW)


 Name

    screen - tty [01-n], color, monochrome, ega, vga display adapter and
    video monitor

 Description

    The tty [01-n] device files provide character I/O between the system and
    the video display monitor and keyboard.  Each file corresponds to a
    separate teletype device.  Although there is a maximum of 12 screens, the
    exact number available (n) depends upon the amount of memory in the com-
    puter.  The screens are modeled after a 25-line, 80-column ASCII termi-
    nal, unless specified otherwise.

    System error messages from the kernel are written to /dev/console, which
    is normally the current multiscreen.  If the /dev/console is the default
    output device for system error messages, and the display being used is
    switched to graphics mode, console messages are not displayed.  When the
    video device returns to text mode, a notice message is displayed and the
    text of the kernel error can be recovered from usr/adm/messages.

    Although all tty[01-n] devices may be open concurrently, only one of the
    corresponding devices can be active at any given time.  The active device
    displays its own screen and takes sole possession of the keyboard.  It is
    an error to attempt to access the color, monochrome, ega, or vga file
    when no corresponding adapter exists or no multiscreens are associated
    with it.

    To get to the next consecutive screen, enter CtrlPrtSc.  Any active
    screen may be selected by entering AltFn, where Fn is one of the function
    keys.  For example, F1 refers to the tty01 device.

    Code examples are included in the section ``Examples'' to help program-
    mers use the ioctls documented here.

 Control modes

    Multiscreens can be reassigned to different adapters (in multi-adapter
    systems) with these ioctls :

    SWAPMONO          Selects the monochrome display as the output device for
                      the multiscreen.

    SWAPCGA           Selects the regular color display as the output device
                      for the multiscreen.

    SWAPEGA           Selects the enhanced color display as the output device
                      for the multiscreen.

    SWAPVGA           Selects the video graphics array color display as the
                      output device for the multiscreen.

    To find out which display adapter type is currently attached to the mul-
    tiscreen, you can use ioctl(S) with the following request:

    CONSCURRENT      Returns the display adapter type currently associated
                      with the multiscreen.  The return value can be one of:
                      MONO, CGA, EGA, or VGA.

 Display modes

    The following ioctls can be used to change the video display mode:

    SWB80x25           Selects 80x25 black and white text display mode.
                        (MONO, CGA, EGA, VGA)

    SWC80x25           Selects 80x25 color text display mode.  (CGA, EGA,
                        VGA)

    SWB40x25           Selects 40x25 black and white text display mode.
                        (MONO, CGA, EGA, VGA)

    SWC40x25           Selects 40x25 color text display mode.  (CGA, EGA,
                        VGA)

    SWBG320            Selects 320x200 black and white graphics display
                        mode.  (CGA, EGA, VGA)

    SWCG320            Selects 320x200 color graphics display mode.  (CGA,
                        EGA, VGA)

    SWBG640            Selects 640x200 black and white graphics display
                        mode.  (CGA, EGA, VGA)

    SWEGAMONO80x25     Selects EGA (Enhanced Graphics Adapter) mode 7 - emu-
                        lates support provided by the monochrome display.
                        (EGA, VGA)

    SWEGAMONOAPA       Selects EGA support for 640x350 graphics display mode
                        EGA (mode F).  (EGA with mono monitor)

    SWENHMONOAPA2     Selects EGA mode F*.  (EGA with mono monitor)

    SWENHB40x25        Selects enhanced EGA support for 40x25 black and
                        white text display mode.  (EGA, VGA)

    SWENHC40x25        Selects enhanced EGA support for the 40x25 color text
                        display mode.  (EGA, VGA)

    SWENHB80x25        Selects enhanced EGA support for 80x25 black and
                        white text display mode.  (EGA, VGA)

    SWENHC80x25        Selects enhanced EGA support for 80x25 color text
                        display mode.  (EGA, VGA)

    SWENHB80x43        Selects enhanced EGA support for 80x43 black and
                        white text display mode.  (EGA, VGA)

    SWENHC80x43        Selects enhanced EGA support for 80x43 color text
                        display mode.  (EGA, VGA)

    SWCG320D          Selects EGA support for 320x200 graphics display
                        mode.  (EGA mode D.)  (EGA, VGA)

    SWCG640E          Selects EGA support for 640x200 graphics display mode
                        EGA (mode E).  (EGA, VGA)

    SWCG640x350        Selects EGA support for 640x350 graphics display mode
                        EGA (mode 10).  (EGA, VGA)

    SWENHCG640        Selects EGA mode 10*.  (EGA, VGA)

    SWMCAMODE          Reinitializes the monochrome adapter.  (MONO)

    SWVGA40x25         Selects VGA support for the 40x25 color text display
                        mode (VGA mode 1+).  (VGA)

    SWVGA80x25         Selects VGA support for the 80x25 black and white
                        text display mode (VGA mode 2+).  (VGA)

    SWVGAM80x25        Selects VGA mode 7+ - emulates support provided by
                        the monochrome display.  (VGA with mono monitor)

    SWVGA11            Selects VGA support for the 640x480 graphics display
                        mode (VGA mode 11).  (VGA)

    SWVGA12            Selects VGA support for the 640x480 graphics display
                        mode (VGA mode 12).  (VGA)

    SWVGA13            Selects VGA support for the 320x200 graphics display
                        mode (VGA mode 13).  (VGA)

    Switching to an invalid display mode for a display device will result in
    an error.

 Getting display modes

    The following ioctl( ) requests are provided to obtain information about
    the current display modes:

    CONSGET          Returns the current display mode setting for current
                      display adapter.  (All)

    CGAGET           Returns the current display mode setting of the color
                      graphics adapter.  (CGA only)

    EGAGET           Returns the current display mode setting of the
                      enhanced graphics adapter.  (EGA only)

    MCAGET           Returns the current display mode setting of the mono-
                      chrome adapter.  (MONO only)

    VGAGET           Returns the current display mode of the video graphics
                      adapters.  (VGA only)

    CONSGETINFO      Returns structure vidinfo (below).  Size of structure
                      (first field) must be filled in by user.

                      struct vid_info
                      {
                        short   size;            /* must be first field          */
                        short   m_num;           /* multiscreen number, 0 based  */
                        ushort  mv_row, mv_col;  /* cursor position              */
                        ushort  mv_rsz, mv_csz;  /* text screen size             */
                        struct  colors mv_norm,  /* normal attributes            */
                                       mv_rev,   /* reverse video attributes     */
                                       mv_grfc;  /* graphic character attributes */
                        uchar_t mv_ovscan;       /* border color                 */
                        uchar_t mk_keylock;      /* caps/num/scroll lock         */
                      };

    CONS6845INFO     Returns structure m6845info (below).  Size of struc-
                      ture (first field) must be filled in by user.

                      struct m6845_info
                      {
                        short   size;          /* must be first field        */
                        ushort  screen_top;    /* offset of screen in video  */
                        ushort  cursor_type;   /* cursor shape               */
                      };

    CONSADP           Returns number of the multiscreen displayed on adaptor
                      associated with that multiscreen.

    GIOATTR          Return value of ioctl is 6845-style attribute byte in
                      effect.

    GIOCOLOR         Return value of ioctl is 0 or 2 depending on whether
                      the device supports color.

    GIOSCRNMAP       Gets the 256-byte screen map table, which is the map-
                      ping of ASCII values (0-256) onto the PC video ROM font
                      characters (0-256). Note that control characters (ASCII
                      values less than hex 20) have control functions and do
                      not display ROM characters (for example, ^J is new-
                      line).

                      This is often used to map the low font values that nor-
                      mally correspond to ASCII control values to higher
                      ASCII values, thus displaying the desired ROM charac-
                      ters.

    PIOSCRNMAP       Puts the 256-byte screen map table (see GIOSCRNMAP).

    GIOKEYMAP        See keyboard(HW).

    GIOFONT8Xn       Gets font, where n is 8, 14, and 16.  Argument is a
                      pointer to a font table.  Size of 8X8 font table is
                      8X256 bytes, 8X14 is 14X256 bytes, etc.

    PIOFONT8Xn       Puts font, where n is 8, 14, and 16.  Argument is a
                      pointer to a font table.  Size of 8X8 font table is
                      8X256 bytes, 8X14 is 14X256 bytes, etc.

 Memory mapping modes

    The ioctl(S) routine is used to map the display memory of the various de-
    vices into the user's data space.

    Note that the MAP* ioctls map the memory associated with the current
    mode.  You must put the adapter into the desired mode before performing
    mapping, or the pointers returned will not be appropriate.  Refer to your
    hardware manual for details on various displays, adapters, and control-
    lers.

    These ioctl() requests can be used to map the display memory:

    MAPCONS           Maps the display memory of the adapter currently being
                      used into the user's data space.  (All)

    MAPMONO           Maps the monochrome adapter's display memory into the
                      user's data space.  (MONO only)

    MAPCGA            Maps the color adapter's display memory into the user's
                      data space.  (CGA only)

    MAPEGA            Maps the enhanced graphics adapter's display memory
                      into the user's data space.  (EGA only)

    MAPVGA            Maps the video graphics adapter's display memory into
                      the user's data space.  (VGA only)

    For example, the following code can be used to acquire a pointer to the
    start of the user data space associated with the color graphics adapter
    display memory:

       char *dp;
       int retval;
               .
               .
               .
       /* fd is a file descriptor for a multiscreen device */
       retval = ioctl (fd, MAPCONS,0L);
       dp = (char *) retval;
               .
               .
               .

    Note that when the display memory is mapped into the user space, the
    adapter's m6845 start address registers are not set.  The start address
    can be reset in two ways, so that the start address of the display memory
    corresponds to the upper left hand corner of the screen:

    1.  Switch modes with an ioctl().  (The ``switch'' can be to the present
        mode).  See the ``Display modes'' section of this manual page.

    2.  Change the start address high and low addresses with the
        in-on-port/out-on-port ioctl().

    The in-on-port/out-on-port ioctl() can also be used to determine the
    current value in the start address register, and then set up a pointer to
    the offset in the mapped-in data space.

    MAPCLASS         Package ioctl that gives I/O privileges to an arbitrary
                      list of ports and maps an arbitrary frame buffer into
                      the user's address space identified by a string found
                      in the struct vidclass vidclasslist[].  For example:

                      char *
                      ioctl(fd, MAP_CLASS, video_class_name)
                      char *video_class_name;

                      This returns a pointer to the frame buffer. See
                      /etc/conf/pack.d/cn/class.h for descriptions of the
                      existing classes. Note that the link kit must be
                      installed in order to find this file.  (The class.h
                      file is normally generated by mkdev graphics.)

    EGAIOPRIVL
    VGAIOPRIVL       These add the list of I/O ports found on standard EGA
                      and VGA cards into the process' TSS I/O permission bit-
                      map.  This allows the process to access the EGA I/O
                      ports directly from user space with 386 IN and OUT
                      instructions.  (See sample code under ``Examples''.)
                      I/O instructions executed in this manner are somewhat
                      slower than I/O instructions executed when the I/O
                      privilege level is raised to 3 (see instruction timings
                      in Intel's 80386 Programmer's Reference Manual.)

                      A process' I/O privilege level can be set, allowing for
                      the faster execution of I/O instructions with the
                      sysi86() subfunction V86SCIOPL:

                         sysi86 (SI86V86, V86SCIOPL, 0x3000)

                      This sets the I/O privilege to 3 as described above.
                      Only the super user can do this.

    KDDISPTYPE        This call returns display information to the user.  The
                      argument expected is the buffer address of a structure
                      of type kddisparam into which display information is
                      returned to the user.  The kddisparam structure is
                      defined as follows:

                      struct kd_disparam
                             {
                                long type;    /* display type */
                                char *addr;   /* display memory address */
                             }

                      Possible values for the type field include:

                      KDMONO for the IBM monochrome display adapter

                      KDHERCULES for the Hercules monochrome graphics
                      adapter

                      KDCGA for the IBM color graphics adapter

                      KDEGA for the IBM enhanced graphics adapter

                      KDVGA for the IBM video graphics adapter

    KDDISPINFO        Returns struct kddispinfo, which contains adapter type
                      and physical address of frame buffer, as follows:

                      struct kd_dispinfo{
                              char *vaddr;          /* memory address */
                              paddr_t physaddr;     /* memory address */
                              unsigned long size;   /* memory size */
                      }

    KIOCSOUND         Starts sound generation.  Turns on sound.  The arg is
                      the period of the bell tone in units of 840.3
                      nanoseconds. A value of 0 turns off the sound.  This is
                      useful for generating tones while in graphics mode.

    KDGETLED          Gets keyboard LED status.  The argument is a pointer to
                      a character.  The character will be filled with a
                      Boolean combination of the following values:

                      0x10    Caps lock and Scroll lock are on
                      0x11    Scroll lock and Num lock are on
                      0x04    Scroll lock is on
                      0x02    Num lock is on
                      0x01    Caps lock is on

    KDSETLED          Sets keyboard LED status. The argument is a character
                      whose value is the Boolean combination of the values
                      listed under ``KDGETLED''.

    KDMKTONE          (See KIOCSOUND.)  The argument is a 32 bit value, with
                      the lower 16 bits set to the frequency and the upper 16
                      bits set to the duration (in milliseconds).

    KDSETMODE         Sets console in text or graphics mode.  The argument is
                      of type integer, which should contain one of the fol-
                      lowing values:

                      KDTEXT (sets console to text mode)
                      KDGRAPHICS     (sets console in graphics mode)

                      Note, the user is responsible for programming the
                      color/graphics adapter registers for the appropriate
                      graphical state.

    KDGETMODE         Gets current mode of console.  Returns integer argument
                      containing either KDTEXT or KDGRAPHICS as defined in
                      the KDSETMODE ioctl description.

    KDENABIO          Enable in's and out's to video adaptor ports.  No argu-
                      ment.

    KDDISABIO         Disable in's and out's to video adaptor ports.  No
                      argument.

    KDGKBTYPE         Always returns 0.

    KIOCINFO          Always returns 0x6B64.

    VTSETMODE        Sets the virtual terminal mode.  The argument is a
                      pointer to a vtmode structure, as defined below.

    VTGETMODE        Determines what mode the active virtual terminal is
                      currently in, either VTAUTO or VTPROCESS.  The argu-
                      ment to the ioctl is the address of the following type
                      of structure:

                      struct vt_mode {
                             char     mode;   /* VT mode */
                             char     waitv;  /* if !=0, vt hangs on writes when not active */
                             short    relsig; /* signal to use for release request */
                             short    acqsig; /* signal to use for display acquired */
                             short    frsig;  /* signal to use for forced release */
                             }

                             #define  VT_AUTO       0x00    /* automatic VT switching */
                             #define  VT_PROCESS    0x01    /* process controls switching */

                      The vtmode structure will be filled in with the
                      current value for each field.

    VTRELDISP        Tells the virtual terminal manager whether the display
                      has been released by the process.

                      0       release refused
                      1       release acknowledged
                      2       acquire acknowledged

    VTACTIVATE       Makes the multiscreen number specified in the argument
                      the active multiscreen.  The video driver will cause a
                      switch to occur in the same manner as if a hotkey
                      sequence had been typed at the keyboard.  If the speci-
                      fied multiscreen is not open or does not exist, the
                      call will fail and errno will be set to EINVAL.

 Graphics adapter port I/O

    You can use ioctl(S) to read or write a byte from or to the graphics
    adapter port.  The arg parameter of the ioctl call uses the portioarg
    data structure:

       struct port_io_arg {
               struct port_io_struct args[4];
       };

    As shown above, the portioarg structure points to an array of four
    portiostruct data structures. The portiostruct structure has the fol-
    lowing format:

       struct port_io_struct {
               char dir;    /* direction flag (in vs. out) */
               unsigned short port;   /* port address */
               char data;   /* byte of data */
       };

    You may specify one, two, three, or four of the portiostruct structures
    in the array for one ioctl call. The value of dir can be either
    INONPORT to specify a byte being input to the graphics adapter port or
    OUTONPORT to specify a byte being output to the graphics adapter port.
    port is an integer specifying the port address of the desired graphics
    adapter port.  data is the byte of data being input or output as speci-
    fied by the call.

    If you are not using any of the portiostruct structures, load the port
    with 0, and leave the unused structures at the end of the array.  Refer
    to hardware manuals for port addresses and functions for the various
    adapters.

    You can use the following ioctl(S) commands to input or output a byte on
    the graphics adapter port:

    CONSIO            Inputs or outputs a byte on the current graphics
                      adapter port as specified.  (All)

    MCAIO             Inputs or outputs a byte on the monochrome adapter port
                      as specified.  (MONO only)

    CGAIO             Inputs or outputs a byte on the color graphics adapter
                      port as specified.  (CGA only)

    EGAIO             Inputs or outputs a byte on the enhanced graphics
                      adapter port as specified.  (EGA only)

    VGAIO             Inputs or outputs a byte on the video graphics array
                      adapter port as specified.  (VGA only) To input a byte
                      on any of the graphics adapter ports, load dir with
                      INONPORT and load port with the port address of the
                      graphics adapter. The byte input from the graphics
                      adapter port will be returned in data.

    To output a byte, load dir with OUTONPORT, load port with the port
    address of the graphics adapter, and load data with the byte you want
    output to the graphics adapter port.

 Function keys

    ioctl(S) can be used to define or obtain the current definition of a
    function key.  The arg parameter of the ioctl call uses the fkeyarg data
    structure:

       struct fkeyarg {
               unsigned short keynum;
               char keydef [MAXFK];
               char flen;
       }

    You can use the following ioctl(S) request to assign function key defini-
    tions:

    SETLOCKLOCK       Toggles the Caps Lock and Num Lock keys to be either
                      global to all the multiscreens, or local to each indi-
                      vidual multiscreen.  To make the Caps Lock global (its
                      default), set the arg parameter to 1.  To make the Caps
                      Lock local to each screen, set the arg parameter to 0.

 ANSI screen attribute sequences

    The following character sequences are defined by ANSI X3.64-1979 and may
    be used to control and modify the screen display.  Each n is replaced by
    the appropriate ASCII number (decimal) to produce the desired effect.
    The last column is for termcap(M) codes, where ``n/a'' means not applica-
    ble.

    The use of 7 or 8 bit characters in the escape sequence is a valid invo-
    cation for each action defined. For example the ANSI ED command can be
    invoked via the ``ESC[n J'' (0x1b-0x5b-n-0x4a, 7 bit chars) sequence or
    the ``CSInJ'' (0x9b-n-0x4n, 8 bit chars) sequence.

    _________________________________________________________________________


    ISO             Sequence      Action                            Termcap
                                                                    Code
    _________________________________________________________________________
    ED              CSInJ         Erases  all  or  part  of   a        cd
    (Erase in                     display.   n=0:  erases  from
    Display)                      active  position  to  end  of
                                  display.   n=1:  erases  from
                                  the beginning of  display  to
                                  active position.  n=2: erases
                                  entire display.
    EL              CSInK         Erases all or part of a line.        ce
    (Erase in                     n=0: erases from active posi-
    Line)                         tion to end  of  line.   n=1:
                                  erases from beginning of line
                                  to  active  position.    n=2:
                                  erases entire line.
    ECH             CSInX         Erases n characters.                 n/a
    (Erase
    Character)
    CBT             CSInZ         Moves active position back  n        bt
    (Cursor                       tab stops.
    Backward
    Tabulation)
    SU              CSInS         Scrolls screen up n lines,           sf
    (Scroll                       introducing new blank lines
    Up)                           at bottom.


    SD              CSInT         Scrolls screen down n lines,         sr
    (Scroll                       introducing new blank lines
    Down)                         at top.

    CUP             CSIm;nH       Moves active position to             cm
    (Cursor                       location m (vertical) and n
    Position)                     (horizontal).
    HVP             CSIm;nf       Moves  active   position   to        n/a
    (Horizontal                   location  m  (vertical) and n
    & Vertical                    (horizontal).
    Position)
    CUU             CSInA         Moves active  position  up  n      up (ku)
    (Cursor Up)                   number of lines.
    CUD             CSInB         Moves active position down n       do (kd)
    (Cursor                       number of lines.
    Down)
    CUF             CSInC         Moves   active   position   n      nd (kr)
    (Cursor                       spaces to the right.
    Forward)
    CUB             CSInD         Moves   active   position   n      bs (kl)
    (Cursor                       spaces backward.
    Backward)
    HPA             CSIn          Moves  active   position   to        n/a
    (Horizontal                   column given by n.
    Position
    Absolute)
    HPR             CSIna         Moves active position n char-        n/a
    (Horizontal                   acters to the right.
    Position
    Relative)
    VPA             CSInd         Moves active position to line        n/a
    (Vertical                     given by n.
    Position
    Absolute)

    VPR             CSIne         Moves active position down  n        n/a
    (Vertical                     number of lines.
    Position
    Relative)
    IL              CSInL         Inserts n new, blank lines.          al
    (Insert
    Line)
    ICH             CSIn@         Inserts n blank places for  n        ic
    (Insert                       characters.
    Character)
    DL              CSInM         Deletes n lines.                     dl
    (Delete
    Line)
    DCH             CSInP         Deletes n number  of  charac-        dc
    (Delete                       ters.
    Character)
    CPL             CSInF         Moves  active   position   to        n/a
    (Cursor to                    beginning  of  line,  n lines
    Previous                      up.
    Line)
    CNL             CSInE         Moves  active   position   to        n/a
    (Cursor                       beginning  of  line,  n lines
    Next                          down.
    Line)
    SGR             CSInm         Character attributes, as sum-        n/a
    (Select                       marized  in  the chart below.
    Graphic                       Up to three attributes can be
    Rendition)                    specified in the form:
                                            CSI n1; n2; n3 m
                                  (See   list   of   parameters
                                  below.)

    SM              CSI2h         Locks keyboard.  Ignores key-        n/a
    (Set Mode)                    board  input  until unlocked.
                                  Characters are not saved.
    MC              CSI2i         Sends   screen    to    host.        n/a
    (Media                        Current  screen  contents are
    Copy)                         sent to the application.
    RM              CSI2l         Unlocks keyboard.  Re-enables        n/a
    (Reset                        keyboard input.
    Mode)


    Select Graphic Rendition (SGR) Chart

    _________________________________________________________________________
    n                             Meaning
    _________________________________________________________________________
    0                             all attributes off (normal display)
    1                             bold intensity (or light color)
    4                             underscore on (if hardware supports it)
    5                             blink on (if hardware supports it)
    7                             reverse video
    8                             sets blank (non-display)
    10                            selects the primary font
    11                            selects the first alternate font; lets
                                  ASCII characters less than 32 be displayed
                                  as ROM characters
    12                            selects a second alternate font; toggles
                                  high bit of extended ASCII code before
                                  displaying as ROM characters
    30                            black foreground
    31                            red foreground
    32                            green foreground
    33                            brown foreground
    34                            blue foreground
    35                            magenta foreground
    36                            cyan foreground
    37                            white foreground
    38                            enables underline option; white foreground
                                  with white underscore
    39                            disables underline option
    40                            black background
    41                            red background
    42                            green background
    43                            brown background
    44                            blue background
    45                            magenta background
    46                            cyan background
    47                            white background

 Additional screen attribute sequences

    _________________________________________________________________________
                                                                    Termcap
    Name          Sequence          Action                          Code
    _________________________________________________________________________
    n/a           CSI=p;dB          Sets the bell parameter to      n/a
                                    the decimal values of p and
                                    d.  p is the period of the
                                    bell tone in units of 840.3
                                    nanoseconds, and d is the
                                    duration of the tone in units
                                    of 100 milliseconds.
    n/a           CSI=s;eC          Sets the cursor to start on     n/a
                                    scanline s and end on scan-
                                    line e.
    n/a           CSI=xD            Turns on or off (x=1 or 0)      n/a
                                    the intensity of the back-
                                    ground color.
    n/a           CSI=xE            Sets or clears (x=1 or 0) the   n/a
                                    Blink vs. Bold background bit
                                    in the 6845 CRT controller.
    n/a           CSI=cA            Sets overscan color to color    n/a
                                    c.  c is a decimal value
                                    taken from Color Table above.
                                    (This sequence may not be
                                    supported on all hardware.)
    n/a           CSI=cF            Sets normal foreground color    n/a
                                    to c.  (c is a decimal param-
                                    eter taken from Color Table.)


    n/a           CSI=cG            Sets normal background.         n/a
                                    (See Color Table.)
    n/a           CSI=cH            Sets reverse foreground.        n/a
                                    (See Color Table.)
    n/a           CSI=cI            Sets reverse background.        n/a
                                    (See Color Table.)
    n/a           CSI=cJ            Sets graphic foreground.        n/a
                                    (See Color Table.)
    n/a           CSI=cK            Sets graphic background.        n/a
                                    (See Color Table.)
    n/a           CSIng             Accesses alternate graphics     n/a
                                    set.  Not the same as
                                    ``graphics mode''.  Refer to
                                    your hardware manual for
                                    decimal/character codes (Pn)
                                    and possible output charac-
                                    ters.
    n/a           CSInL             Fills new regions with          n/a
                                    current (n=0) or normal (n=1)
                                    attributes.  Default is 0.
    n/a           CSInM             Returns current foreground      n/a
                                    color attributes, with n=0
                                    for normal, 1 for reverse,
                                    and 2 for graphic.  The
                                    colors are sent back in the
                                    keyboard data input stream as
                                    text decimal values separated
                                    by a space and terminated


                                    with a newline.  For example,
                                    if the current foreground
                                    color is lt_red on black,
                                    ``12 0\n'' is returned.
    n/a           CSIs              Saves current cursor posi-      n/a
                                    tion.
    n/a           CSIu              Restores saved cursor posi-     n/a
                                    tion.
    n/a           ESC7              Saves current cursor posi-      n/a
                                    tion.
    n/a           ESC8              Restores saved cursor posi-     n/a
                                    tion.
    n/a           ESCQ Fn 'string'  Defines function key Fn with    n/a
                                    string.  String delimiters
                                    ' and ' may be any character
                                    not in string.  Fn is defined
                                    as the key number starting at
                                    zero plus the ASCII value of
                                    zero.  For example, F1 = 0...
                                    F16 = `` ? '', and so on.
                                    In this escape sequence, the
                                    `` ^ '' character will cause
                                    the next character to have 32
                                    subtracted from its ASCII
                                    value.  Thus `` ^! '' results
                                    in a SOH (^A) character.
    n/a           CSInz             Switches to screen n.  If the   n/a
                                    screen does not exist, no
                                    action will take place.


    Color Table

    _________________________________________________________________________
    Cn             Color                 Cn              Color
    _________________________________|_______________________________________
    0              Black             |    8              Grey
    1              Blue              |    9              Lt. Blue
    2              Green             |   10              Lt. Green
    3              Cyan              |   11              Lt. Cyan
    4              Red               |   12              Lt. Red
    5              Magenta           |   13              Lt. Magenta
    6              Brown             |   14              Yellow
    7              White             |   15              Lt. White

 Examples

    The following module includes useful examples of such operations as get-
    ting the display mode, screen switching, I/O privilege, and memory map-
    ping.

    Sample code (part 1 of 4)

    #include <stdio.h>

    #include <sys/types.h>
    #include <sys/signal.h>
    #include <sys/vtkd.h>

    #define SIG_REL SIGUSR1
    #define SIG_ACQ SIGUSR2

    int Isdisplayed;        /* flag: when are we flipped away */
    char *Screenmem;        /* physical map to the video RAM  */
    int graf();             /* Set everything up          */
    void grafend();         /* Restore user's text mode   */
    void grafquit();        /* Clean-up and exit          */
    void rel_screen(), acq_screen();
    int Oldmode;            /* save mode of user shell screen */

    /*
     * Set up the graphics multiscreen stuff and call another
     * routine to set up card.
     */
    graf()
    {
        struct vt_mode smode;

        Isdisplayed = 1;
    /*
     *  Set up to catch the screen switch signals.
     */
        signal(SIG_REL, rel_screen);
        signal(SIG_ACQ, acq_screen);
    /*
     * Set up the data structure that asks the driver
     * to send you signals when the screens are switched.
     * mode == VT_PROCESS means send screen switch signals.
     * mode == VT_AUTO means turn off screen switch signals (regular mode).
     * relsig == the signal you want when the user switches away.
     * acqsig == the signal you want when the user switches back to you.
     */
        smode.mode = VT_PROCESS;
        smode.waitv = 0;    /* not implemented, reserved */
        smode.relsig = SIG_REL;
        smode.acqsig = SIG_ACQ;
        smode.frsig  = SIGINT;  /* not implemented, reserved */

        if(-1 == ioctl(0, VT_SETMODE, &smode))
        {
            perror("screen switch signal ioctl VT_SETMODE");
            exit(1);
        }
        signal(SIGINT, grafquit);
        grafmode();
    }

    Sample code (part 2 of 4)

    /*
     * this is the signal handler for when the user screen flips
     * away from us.
     */
    void
    rel_screen()
    {
        signal(SIG_REL, rel_screen);
        Isdisplayed = 0;
        ega_save();
    /*
     * Tell the video driver that you have saved your state
     * and it can now have the card to switch to the new screen.
     * The video driver waits (forever) for this ioctl before
     * it will complete the screen switch requested by the user.
     * If you don't make this ioctl the screen switcher will
     * be wedged until it gets one.  It is best to have a
     * small one line reldisp.c program to unwedge your screen
     * switcher when development programs screw up from time
     * to time.
     */
        ioctl(0, VT_RELDISP, VT_TRUE);
    }

    /*
     * this is the signal handler for when the user screen flips
     * back to us.
     */
    void
    acq_screen()
    {
        signal(SIG_ACQ, acq_screen);
        Isdisplayed = 1;
        ega_restore();
    /*
     * Tell the video driver that you have restored your state
     * and screen switching can now continue.
     */
        ioctl(0, VT_RELDISP, VT_ACKACQ);
    }

    void
    grafquit()
    {
        grafend();
        exit(0);
    }

    Sample code (3 of 4)

    /*
     * restore text mode.
     */
    void
    grafend()
    {
        ioctl(0, MODESWITCH | Oldmode, (char *)0);
    }

    grafmode()
    {
        int adapter, privlcmd;
    /*
     * Confirm that we are on a supported video adapter.
     */
        adapter = ioctl(0, CONS_CURRENT, (char *)0);
        if(EGA != adapter && VGA != adapter)
        {
            puts("Stdin must be an EGA or VGA multiscreen\n");
            exit(0);
        }

    Sample code (4 of 4)

    /*
     * Save the user's current text mode so you
     * can restore it on exit.
     */
        Oldmode = ioctl(0, CONS_GET, (char *)0);
    /*
     * Get privilege to do direct INs and OUTs to the video card.
     */
        if(EGA == adapter)
            privlcmd = EGA_IOPRIVL;
        else
            privlcmd = VGA_IOPRIVL;
        if(-1 == ioctl(0, privlcmd, 1))
        {
            perror("I/O privilege denied");
            exit(1);
        }
    /*
     * Have the video driver reprogram the card for EGA 640x350 16 color mode.
     */
        ega_grafmode();
    /*
     * Map the video card's frame buffer into your address space.
     * This must be done after the mode switch command or you get
     * frame buffer address for the wrong mode mapped in.
     */
        Screenmem = (char *)ioctl(0, MAPCONS, (char *)0);
    }

 Files

    /dev/console
    /dev/tty[02-n]
    /dev/color
    /dev/monochrome
    /dev/ega
    /dev/vga

    Include files:
    /usr/include/sys/vtkd.h
    /usr/include/sys/comcrt.h
    /usr/include/sys/console.h
    /usr/include/sys/kb.h

 See also

    console(M), ioctl(S), keyboard(HW), keymap(M), mapkey(M), mapchan(M),
    multiscreen(M), scancode(HW), setcolor(C), stty(C), systty(M), vidi(C),
    termcap(M), tty(M)


Typewritten Software • bear@typewritten.org • Edmonds, WA 98026