[Contents] [Index] [Help] [Retrace] [Browse <] [Browse >]

Most console device processing involves a window, but there are functions
and special commands that may be used without a window.  To use the
console device without a window, you call opendevice() with the console
unit CONU_LIBRARY.

The console device functions are cdinputhandler() and rawkeyconvert();
they may only be used with the CONU_LIBRARY console unit.  The console
device commands which do not require a window are cd_askdefaultkeymap
and cd_setdefaultkeymap; they be used with any console unit.  the
advantage of using the commands with the CONU_LIBRARY unit is the lack of
overhead required for CONU_LIBRARY because it doesn't require a window.

To use the functions requires the following steps:

   *  Declare the console device base address variable ConsoleDevice in the
      global data area.

   *  Declare storage for an I/O request of type iostdreq.

   *  Open the console device with CONU_LIBRARY set as the console unit.

   *  Set the console device base address variable to point to the device
      library vector which is returned in io_Device.

   *  Call the console device function(s).

   *  Close the console device when you are finished.


   #include <devices/conunit.h>
   struct ConsoleDevice *ConsoleDevice;  /* declare device base address */

   struct IOStdReq ConsIO= {0};          /* I/O request */

   main()


       /* Open the device with CONU_LIBRARY for function use */
   if (0 == OpenDevice("console.device",CONU_LIBRARY,
                      (struct IORequest *)&ConsIO,0) )
       {
       /* Set the base address variable to the device library vector */
       ConsoleDevice = (struct ConsoleDevice *)ConsIO.io_Device;

                     .
                     .    (console device functions would be called here)
                     .

       CloseDevice(ConsIO);
       }

The code fragment shows only the steps outlined above, it is not complete
in any sense of the word.  For a complete example of using a console
device function, see the rawkey.c code example in the
"intuition: mouse and keyboard" chapter of the amiga rom kernel reference
Manual: Libraries.  The example uses the rawkeyconvert() function.

To use the commands with the CONU_LIBRARY console unit, you follow the
same steps that were outlined in the opening the console device section of
this chapter.

   struct MsgPort *ConsoleMP;       /* pointer to our message port */
   struct IOStdReq *ConsoleIO;      /* pointer to our I/O request */
   struct KeyMap  *keymap;          /* pointer to keymap */

       /* Create the message port */
   if (ConsoleMP=CreateMsgPort())
       {
           /* Create the I/O request */
       if (ConsoleIO = CreateIORequest(ConsoleMP,sizeof(struct IOStdReq)))
           {
               /* Open the Console device */
           if (OpenDevice("console.device",CONU_LIBRARY,
                         (struct IORequest *)ConsoleIO,0L))

               /* Inform user that it could not be opened */
               printf("Error: console.device did not open\n");
           else
               {
                  /* Allocate memory for the keymap */
               if (keymap = (struct KeyMap *)
                  AllocMem(sizeof(struct KeyMap),MEMF_PUBLIC | MEMF_CLEAR))
                  {
                  /* device opened, send CD_ASKKEYMAP command to it */
                  ConsoleIO->io_Length = sizeof(struct KeyMap);
                  ConsoleIO->io_Data = (APTR)keymap; /* where to put it */
                  ConsoleIO->io_Command = CD_ASKKEYMAP;
                  DoIO((struct IORequest *)ConsoleIO))
                  }

               CloseDevice(ConsIO);
               }

Again, as in the previous code fragment, this is not complete (that's why
it's a fragment!) and you should only use it as a guide.