Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ console(7) — A/UX 0.7

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

phys(2)

ioctl(2)

mouse(7)

termio(7)



     console(7)                                             console(7)



     NAME
          /dev/console - keyboard/screen driver

     DESCRIPTION
          The keyboard and video screen driver provides access to the
          system's console keyboard and screen.  Running in its
          default configuration it provides emulation of an ANSI
          standard screen and keyboard combination. Various ioctl
          commands allow the user to configure it for use along with
          the mouse in a more interactive environment.

          The screen driver is a streams based driver.  Before use, a
          line discipline may have to be pushed onto the device's
          stream.  Under most conditions this is done automatically by
          the operating system.  When an application opens
          /dev/console explicitly, and it is not already open, it may
          be necessary to push such a line discipline.  There are
          three ways to do this:


          ioctl(fd, I_PUSH, "line");
                              unconditionally pushes a line discipline

          line_push(fd);      pushes a line discipline if one is not
                              already pushed

          /etc/line_sane fd   does the same (but as an application in
                              a shell script)

          In the above examples fd is a file descriptor of the open
          device.  The last two methods are the prefered examples as
          they will only push a line discipline if required, also they
          can be used on non-streams drivers without any adverse
          effects.

          When /dev/console is opened with a line discipline pushed on
          it, it will respond to all the ioctls and modes described in
          termio(7).  Without the line discipline it will only respond
          to the flags described under ccflag in termio(7).  Setting
          the number of bits/character to CS8 will put the screen into
          reverse video when it is in terminal emulation mode.

        ANSI Compatible Escape Sequences
          The terminal emulator responds to the following ANSI escape
          sequences.  Note: characters in single quotes (') are
          literal. ESC is the escape character.  Other symbols
          represent strings of ASCII numbers which represent their
          decimal equivalent.  [n] represents an optional number.  If
          it is not present 0 is used in its place.  When sending
          row/column numbers to the screen the top left corner has
          address row=1, column=1.




     Page 1                                        (last mod. 1/15/87)





     console(7)                                             console(7)



          '\b'                backspace - move 1 column left

          '\r'                RETURN - move to column 1

          '\n'                linefeed - move to next line

          '\t'                TAB

          ESC '='             turn on keypad mode

          ESC '>'             turn off keypad mode

          ESC 'D'             line feed

          ESC 'M'             scroll down

          ESC '7'             save cursor position

          ESC '8'             restore cursor position

          ESC '[' 's'         save cursor position

          ESC '[' 'u'         restore cursor position

          ESC '[' 'H'         home cursor

          ESC '[' 'f'         home cursor

          ESC '[' [n] 'A'     up n, if n = 0 go up 1

          ESC '[' [n] 'B'     down n, if n = 0 go down 1

          ESC '[' [n] 'D'     left n, if n = 0 go left 1

          ESC '[' [n] 'C'     right n, if n = 0 go right 1

          ESC '[' [n] 'J'     0->erase to end of page
                              1->erase to beginning of page
                              2->erase whole page

          ESC '[' [n] 'K'     0->erase to end of line
                              1->erase from beginning of line
                              2->erase whole line

          ESC '[' n 'L'       scroll down n lines

          ESC '[' n 'M'       scroll up n lines

          ESC '[' n '@'       insert n spaces

          ESC '[' n 'P'       delete n characters




     Page 2                                        (last mod. 1/15/87)





     console(7)                                             console(7)



          ESC '[' n 'm'       7->reverse video
                              0->normal video

          ESC '[' n 'n'       6-> return cursor position as a string:
                              "ESC '[' row ';' col 'R'"

          ESC '[' n 'Z'       TAB to n*8

          ESC '[' [n1] ';' [n2] 'r'
                              move to col n2, line n1

          ESC '[' [n1] ';' [n2] 'f'
                              set scrolling region from row n2 to row
                              n2

          ESC '[' [n1] ';' [n2] 'H'
                              set scrolling region from row n1 to row
                              n2

          ESC '[' '?' [n] 'h' enable scrolling region

          ESC '[' '?' [n] 'l' disable scrolling region

          If the keyboard is not in ``keypad mode,'' it returns the
          characters on the keys.  If it is in ``keypad mode,'' then
          the following escape sequences are generated:

               Key       Sequence

               0         ESC 'O' 'p'
               1         ESC 'O' 'q'
               2         ESC 'O' 'r'
               3         ESC 'O' 's'
               4         ESC 'O' 't'
               5         ESC 'O' 'u'
               6         ESC 'O' 'v'
               7         ESC 'O' 'w'
               8         ESC 'O' 'x'
               9         ESC 'O' 'y'
               -         ESC 'O' 'm'
               ENTER          ESC 'O' 'M'
               functions ]


        IOCTLS
          The display responds to a large number of ioctls which
          affect its behavior in many different ways.  It responds to
          all the ioctls defined in termio(7) in the normal manner.
          Since it is a streams device all other ioctls must be called
          using the streams indirect ioctl call function ISTR.  With
          this is passed a packet describing the ioctl to be done.
          This packet is of type struct strioctl and is described in



     Page 3                                        (last mod. 1/15/87)





     console(7)                                             console(7)



          sys/stropts.  It has 4 fields,


          iccmd    The command RB ( ioctl ) requested to be done.

          icdp     A pointer to any data to be read/written to by the
                    ioctl (parameters or returned results for
                    example).

          iclen    The size of the data in bytes.

          ictimout A timeout (how long to wait for the ioctl to
                    complete before returning an error), -1 means no
                    timeout (or wait for ever).

          If ``s'' is a data structure of type struct strioctl then an
          ioctl call is made using a call of the following form:

               ioctl(fd, I_STR, &s)

          Further examples of such calls are given later in this
          document.

          Screen ioctls fall into three main areas: control of the
          keyboard, control of the video generation hardware and
          control of the mouse.  All the following
          ioctls,andthesymbolsdefined defined in the include file
          sys/video.h.

        Keyboard ioctls
          The keyboard operates in two modes, either as an ANSI
          standard keyboard generating characters in the normal
          manner, or in ``raw'' mode where each keystroke is generated
          (both up and down keystrokes) and passed directly without
          any modification.

          VIDEORAW      This ioctl puts the keyboard into ``raw''
                         mode. The key codes returned are the raw
                         keycodes directly from the keyboard. (Refer
                         to the keyboard documentation for a list of
                         these.) The most significant bit indicates
                         whether the keystroke is up or down. One
                         exception is the mouse escape character (see
                         VIDEOMOUSE below).

          VIDEOASCII    This is the default mode when /dev/key is
                         opened for the first time. It is an emulation
                         of an ANSI standard terminal keyboard
                         (including keypad).

        Video ioctls
          The video screen can be used in two different ways, either



     Page 4                                        (last mod. 1/15/87)





     console(7)                                             console(7)



          as a terminal emulation (in which case the interface is in
          the normal manner), or as a bit mapped screen, mapped into a
          process's address space using the phys(2) system call.
          There is no explicit way to shift from one mode to the other
          .... one simply stops sending characters to the terminal
          (including turning off ECHO) and writes to the bitmap.


          VIDEOSIZE       This ioctl returns the size (in characters)
                           of the screen when used in terminal
                           emulation mode. The result is two longs
                           representing the horizontal and vertical
                           sizes.

          VIDEOSETMODE    Set the interlace/bits per pixel mode (NGC
                           board only).  One longword parameter is
                           passed, the following options are allowed:
                           NGC_1NI  1-bit per pixel non-interlaced
                           NGC_2NI  2-bit per pixel non-interlaced
                           NGC_4NI  4-bit per pixel non-interlaced
                           NGC_8NI  8-bit per pixel non-interlaced
                           NGC_1I   1-bit per pixel interlaced
                           NGC_2I   2-bit per pixel interlaced
                           NGC_4I   4-bit per pixel interlaced
                           NGC_8I   8-bit per pixel interlaced
                           As a side effect, the color lookup table is
                           set to the default for the new mode.

          VIDEOSETCLUT    This loads the entire color lookup table
                           (CLUT) (NGC board only). It takes a
                           parameter of 256 consectutive groups of 3
                           bytes for red, green, blue resp.

          VIDEOSETCENT    This loads one color lookup table entry
                           (NGC board only). It takes 4 single bytes
                           as parameters, a one byte address, followed
                           by 3 bytes of red, green and blue resp.

          VIDEOSETDEF     This sets up the screen with the default
                           color lookup table entries for the mode in
                           which the screen is currently set. It takes
                           no parameters.

          VIDEOSETCOLOR   This controls how the default color lookup
                           table information is processed before being
                           set up in a VIDEOSETDEF or VIDEOSETMODE
                           call. It takes a single longword parameter:

                           NGC_BW              Black/White screen
                           NGC_COLOR     Color screen

          VIDEOADDR       This ioctl returns (as a longword) the



     Page 5                                        (last mod. 1/15/87)





     console(7)                                             console(7)



                           physical address of the video ram on the
                           video board (suitable for use in a phys(2)
                           system call)

        Mouse ioctls
          It is possible to attach the mouse to the keyboard device
          using the VIDEOMOUSE system call.  This can only happen if
          the mouse is not currently opened in any other way (see
          mouse(7)).  When in mouse mode, changes in the mouse are
          converted into characters and inserted into the keyboard's
          input stream.  This mode is most useful in conjunction with
          the keyboard mode VIDEORAW.  The mouse input is always
          preceded by the character MOUSEESCAPE and can take one of
          two forms depending on whether the display is in
          VIDEOMBUTTON mode or not.  If it is then the next
          character is a 1 or 0 depending on the state of the mouse
          button (1 if it is down), in this mode mouse information is
          only placed into the input stream when the state of the
          mouse button changes.  In the other mode the display places
          2 bytes into the input stream whenever the mouse moves or
          the state of the button changes.  The 2 bytes have the
          following format:


          Byte 0:   Bit 7  The state of the mouse button 0 for down

                     Bits 0-6
                           2's complement of the mouse movement in the
                           Y axis since the last entry

          Byte 1:   Bit 7  Always 1

                     Bits 0-6
                           2's complement of the mouse movement in the
                           X axis since the last entry

          The mouse ioctls are:


          VIDEOMOUSE         Put the display into VIDEOMOUSE mode as
                              described above. This will fail if the
                              mouse is already in use.

          VIDEONOMOUSE       Take the display out of VIDEOMOUSE
                              mode.  This is the default when the
                              display is opened for the first time.

          VIDEOMBUTTON      Put the display into a mode (described
                              above) where only changes in the mouse
                              button find their way into the keyboard
                              input stream.




     Page 6                                        (last mod. 1/15/87)





     console(7)                                             console(7)



          VIDEOMALL         This option makes all mouse changes
                              (including changes in mouse position) be
                              put into the keyboard's input stream.
                              This is the default when entering
                              VIDEOMOUSE mode.

          VIDEOMDELTA       This call returns the CHANGE in mouse
                              position since it was last called (or
                              since the display was put into
                              VIDEOMOUSE mode). It returns two shorts
                              (horizontal displacement followed by
                              vertical).

          VIDEOMABS         This also only works in VIDEOMOUSE
                              mode, it returns the ABSOLUTE mouse
                              position (relative to 0 when the system
                              was booted). It returns two shorts
                              (horizontal displacement followed by
                              vertical).

     EXAMPLE
          The following is an example of streams ioctls.  It opens the
          keyboard, removes any line disciplines (after first saving
          their states), then it puts the display into VIDEO_RAW and
          VIDEO_MOUSE modes and reads the input, displaying it to the
          standard output.  When a character code 1 (from the key
          ``s'') is found, it stops and  puts the display back into
          VIDEOASCII/VIDEONOMOUSE modes. It then pushes the line
          discipline back on and restores its state.


          #include <sys/stropts.h>
          #include <sys/termio.h>
          #include <sys/video.h>
          #include <fcntl.h>
          main()
          {
             struct termio t;
             char c;
             short ss;
             int fd, line;
             struct strioctl s;

             fd = open("/dev/console", O_RDWR); /*open the keyboard*/
             ioctl(fd,TCGETA,&t);           /*save the old tty*/
                                            /*state*/
             line = ioctl(fd,I_POP,0);      /*remove the line*/
                                            /*discipline and*/
                                            /*remember if there*/
                                            /*was one*/
             s.ic_timout = -1;              /*set the streams*/
                                            /*timeout to infinity*/



     Page 7                                        (last mod. 1/15/87)





     console(7)                                             console(7)



             s.ic_len = 0;                  /*put keyboard into*/
             s.ic_cmd = VIDEO_RAW;          /*raw mode*/
             if (ioctl(fd,I_STR,&s) < 0)
                     goto quit;
             s.ic_len = 0;                  /*attach to mouse*/
             s.ic_cmd = VIDEO_MOUSE;
             if (ioctl(fd,I_STR,&s) < 0)
                     goto quit;
             ioctl(fd,I_FLUSH,FLUSHRW);     /*flush input to*/
                                            /*put us in a known*/
                                            /*starting state*/
             for(;;) {                      /*loop reading input*/
                     if (read(fd,&c,1) < 0) /*and displaying it*/
                         break;
                     if (c == MOUSE_ESCAPE) {
                             if (read(fd,&ss,s) < 0)
                                     break;
                             printf("m = 0x%04x0,s&0xffff);
                             continue;
                     }
                     if (c == 1)            /*quit on char.*/
                                            /*code 1*/
                              break;
                     printf("c = 0x%02x0,c&0xff);
             }
          quit:
             s.ic_len = 0;                 /*set the keyboard*/
                                           /*back to*/
             s.ic_cmd = VIDEO_NOMOUSE;     /*a sane state*/
             ioctl(fd,I_STR,&s);
             s.ic_len = 0;
             s.ic_cmd = VIDEO_ASCII;
             ioctl(fd,I_STR,&s);
             if (line == 0)                   /*if required*/
                     ioctl(fd,I_PUSH,"line"); /*push a line*/
                                              /*discipline*/
             ioctl(fd,TCSETA,&t);             /*restore its modes*/
          }

     FILES
          /dev/console
          /dev/mouse
          /usr/include/sys/video.h
          /usr/include/sys/stropts.h
          /usr/include/termio.h

     SEE ALSO
          phys(2), ioctl(2), mouse(7), termio(7).







     Page 8                                        (last mod. 1/15/87)



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