home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / prog / c / rkrm1.lha / RKRM_Devices / RKRM_Devices.lha / Console / AskKeymap.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  5KB  |  141 lines

  1. /*
  2.  * Copyright (c) 1992 Commodore-Amiga, Inc.
  3.  * 
  4.  * This example is provided in electronic form by Commodore-Amiga, Inc. for 
  5.  * use with the "Amiga ROM Kernel Reference Manual: Devices", 3rd Edition, 
  6.  * published by Addison-Wesley (ISBN 0-201-56775-X).
  7.  * 
  8.  * The "Amiga ROM Kernel Reference Manual: Devices" contains additional 
  9.  * information on the correct usage of the techniques and operating system 
  10.  * functions presented in these examples.  The source and executable code 
  11.  * of these examples may only be distributed in free electronic form, via 
  12.  * bulletin board or as part of a fully non-commercial and freely 
  13.  * redistributable diskette.  Both the source and executable code (including 
  14.  * comments) must be included, without modification, in any copy.  This 
  15.  * example may not be published in printed form or distributed with any
  16.  * commercial product.  However, the programming techniques and support
  17.  * routines set forth in these examples may be used in the development
  18.  * of original executable software products for Commodore Amiga computers.
  19.  * 
  20.  * All other rights reserved.
  21.  * 
  22.  * This example is provided "as-is" and is subject to change; no
  23.  * warranties are made.  All use is at your own risk. No liability or
  24.  * responsibility is assumed.
  25.  *
  26.  ***************************************************************************
  27.  *
  28.  * AskKeymap.c
  29.  *
  30.  * Example of using the CD_ASKKEYMAP command.
  31.  *
  32.  * Compile with SAS C 5.10
  33.  *  lc -b1 -cfistq -v -y -L AskKeymap.c
  34.  *
  35.  */
  36.  
  37. #include <exec/types.h>
  38. #include <exec/memory.h>
  39. #include <exec/io.h>
  40. #include <exec/libraries.h>
  41.  
  42. #include <devices/console.h>
  43. #include <devices/keymap.h>
  44. #include <devices/conunit.h>
  45.  
  46. #include <clib/exec_protos.h>
  47. #include <clib/alib_protos.h>
  48.  
  49. #include <stdio.h>
  50.  
  51. #ifdef LATTICE
  52. int CXBRK(void) { return(0); }  /* Disable SAS CTRL/C handling */
  53. int chkabort(void) { return(0); }  /* really */
  54. #endif
  55.  
  56. extern struct Library *SysBase;
  57.  
  58.  
  59. VOID main(VOID)
  60. {
  61. struct MsgPort *ConsoleMP;       /* pointer to our message port */
  62. struct IOStdReq *ConsoleIO;      /* pointer to our IORequest */
  63. struct KeyMap  *keymap;         /* pointer to keymap */
  64. int i,j;
  65. UBYTE *prt;
  66.  
  67.     /* Release 2 (V36) or a later version of the OS is required */
  68. if(SysBase->lib_Version>=36)
  69.     {
  70.         /* Create the message port */
  71.     if (ConsoleMP=CreateMsgPort())
  72.         {
  73.             /* Create the IORequest */
  74.         if (ConsoleIO = CreateIORequest(ConsoleMP,sizeof(struct IOStdReq)))
  75.             {
  76.                 /* Open the Console device */
  77.             if ( OpenDevice("console.device",CONU_LIBRARY,
  78.                                (struct IORequest *)ConsoleIO,0L) )
  79.  
  80.                 /* Inform user that it could not be opened */
  81.                 printf("Error: console.device did not open\n");
  82.             else
  83.                 {
  84.                    /* Allocate memory for the keymap */
  85.             if (keymap = (struct KeyMap *)AllocMem(sizeof(struct KeyMap),
  86.                                                       MEMF_PUBLIC | MEMF_CLEAR))
  87.                     {
  88.                        /* device opened, send query command to it */
  89.                    ConsoleIO->io_Length = sizeof(struct KeyMap);
  90.                     /* where to put it */
  91.                 ConsoleIO->io_Data = (APTR)keymap;
  92.                 ConsoleIO->io_Command = CD_ASKKEYMAP;
  93.                     if (DoIO((struct IORequest *)ConsoleIO))
  94.  
  95.                         /* Inform user that Askkeymap failed */
  96.                         printf("AskKeyMap failed. Error - %d\n",
  97.                                   ConsoleIO->io_Error);
  98.                     else
  99.                          {
  100.                         /* print values for top row of keyboard */
  101.                         prt = (UBYTE *)keymap->km_LoKeyMap;
  102.                         printf("Result of CD_ASKKEYMAP for top row of keyboard\n\n");
  103.                         printf("\tShift\n");
  104.                         printf("\tAlt\tAlt\tShift\tNo Qualifier\n");
  105.                         for(j=0;j<14;j++)
  106.                             {
  107.                             for (i=0;i<4;i++)
  108.                                  printf("\t%c",*prt++);
  109.                             printf("\n");
  110.                             }
  111.                         }
  112.  
  113.                 /* Deallocate the memory for the keymap */
  114.                 FreeMem(keymap,sizeof(struct KeyMap));
  115.                 }
  116.                 else
  117.                     printf("Error: Could not allocate memory for keymap\n");
  118.  
  119.                 /* Close the Console device */
  120.                 CloseDevice((struct IORequest *)ConsoleIO);
  121.                 }
  122.  
  123.             /* Delete the IORequest */
  124.             DeleteIORequest(ConsoleIO);
  125.             }
  126.         else
  127.             /* Inform user that the IORequest could be created */
  128.             printf("Error: Could create IORequest\n");
  129.  
  130.         /* Delete the message port */
  131.         DeleteMsgPort(ConsoleMP);
  132.         }
  133.     else
  134.         /* Inform user that the message port could not be created */
  135.         printf("Error: Could not create message port\n");
  136.     }
  137. else
  138.     /* Inform user that this program reuqires Release 2 or later */
  139.     printf("Error: Release 2 (V36) or a later version of the OS required\n");
  140. }
  141.