home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / dev / rkrm.lha / RKRM / Keyboard / Read_Keyboard_Matrix.c < prev   
C/C++ Source or Header  |  1992-09-03  |  4KB  |  123 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.  * Read_Keyboard_Matrix.c
  29.  *
  30.  * Compile with SAS C 5.10  lc -b1 -cfistq -v -y -L
  31.  *
  32.  * Run from CLI only
  33.  */
  34.  
  35. #include <exec/types.h>
  36. #include <exec/memory.h>
  37. #include <exec/libraries.h>
  38. #include <dos/dos.h>
  39. #include <devices/keyboard.h>
  40.  
  41. #include <clib/exec_protos.h>
  42. #include <clib/alib_protos.h>
  43.  
  44. #include <stdio.h>
  45.  
  46. #ifdef LATTICE
  47. int CXBRK(void) { return(0); }     /* Disable SAS CTRL/C handling */
  48. int chkabort(void) { return(0); }  /* really */
  49. #endif
  50.  
  51.  
  52. /*
  53.  * There are keycodes from 0x00 to 0x7F, so the matrix needs to be
  54.  * of 0x80 bits in size, or 0x80/8 which is 0x10 or 16 bytes...
  55.  */
  56. #define MATRIX_SIZE 16L
  57.  
  58. /*
  59.  * This assembles the matrix for display that translates directly
  60.  * to the RAW key value of the key that is up or down
  61.  */
  62.  
  63. void Display_Matrix(UBYTE *keyMatrix)
  64. {
  65. SHORT  bitcount;
  66. SHORT  bytecount;
  67. SHORT   mask;
  68. USHORT twobyte;
  69.  
  70. printf("\n    0 1 2 3 4 5 6 7");
  71. printf("\n  +-----------------");
  72. for (bitcount=0;bitcount<16;bitcount++)
  73.     {
  74.     printf("\n%x |",bitcount);
  75.     mask=1 << bitcount;
  76.     for (bytecount=0;bytecount<16;bytecount+=2)
  77.         {
  78.         twobyte=keyMatrix[bytecount] | (keyMatrix[bytecount+1] << 8);
  79.         if (twobyte & mask)
  80.             printf(" *");
  81.         else
  82.             printf(" -");
  83.         }
  84.     }
  85. printf("\n\n");
  86. }
  87.  
  88.  
  89. VOID main(int argc, char *argv[])
  90. {
  91. extern struct Library *SysBase;
  92. struct IOStdReq *KeyIO;
  93. struct MsgPort  *KeyMP;
  94. UBYTE    *keyMatrix;
  95.  
  96. if (KeyMP=CreatePort(NULL,NULL))
  97.     {
  98.      if (KeyIO=(struct IOStdReq *)
  99.                 CreateExtIO(KeyMP,sizeof(struct IOStdReq)))
  100.         {
  101.         if (!OpenDevice("keyboard.device",NULL,(struct IORequest *)KeyIO,NULL))
  102.             {
  103.             if (keyMatrix=AllocMem(MATRIX_SIZE,MEMF_PUBLIC|MEMF_CLEAR))
  104.                 {
  105.                 KeyIO->io_Command=KBD_READMATRIX;
  106.                 KeyIO->io_Data=(APTR)keyMatrix;
  107.                 KeyIO->io_Length= SysBase->lib_Version >= 36 ? MATRIX_SIZE : 13;
  108.                 DoIO((struct IORequest *)KeyIO);
  109.  
  110.                 /* Check for CLI startup... */
  111.                 if (argc)
  112.                     Display_Matrix(keyMatrix);
  113.  
  114.                 FreeMem(keyMatrix,MATRIX_SIZE);
  115.                 }
  116.             CloseDevice((struct IORequest *)KeyIO);
  117.             }
  118.         DeleteExtIO((struct IORequest *)KeyIO);
  119.         }
  120.     DeletePort(KeyMP);
  121.     }
  122. }
  123.