home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / wp_dtp / xdme1820.lha / XDME / keycodes.c < prev    next >
C/C++ Source or Header  |  1993-03-09  |  21KB  |  954 lines

  1. /******************************************************************************
  2.  
  3.     MODUL
  4.     keycodes.c
  5.  
  6.     DESCRIPTION
  7.     Lowlevel module for evaluation of keycodes and qualifiers
  8.  
  9.     NOTES
  10.     highly amiga - specific
  11.  
  12.     BUGS
  13.     no use of dead-keys
  14.  
  15.     TODO
  16.     deadkey - checking
  17.     qual2iqual
  18.  
  19.     EXAMPLES
  20.  
  21.     SEE ALSO
  22.  
  23.     INDEX
  24.  
  25.     HISTORY
  26.     14-Dez-92 b_null created
  27.     14-Jan-93 b_null added UP
  28.     15-Jan-92 b_null added DeadKeyConvert, removed exit_kb - it caused a GURU
  29.  
  30. ******************************************************************************/
  31.  
  32. /**************************************
  33.         Includes
  34. **************************************/
  35. #include "defs.h"
  36. #include <devices/keymap.h>
  37. #include <devices/console.h>
  38.  
  39. extern ubyte CtlC;
  40.  
  41.  
  42. /**************************************
  43.         Globale Variable
  44. **************************************/
  45.  
  46. Prototype int     get_codequal    (const ubyte * str, ubyte * pcode, ushort * pqual);
  47. Prototype char * cqtoa        (int code, int qual);
  48.  
  49. Prototype ushort iqual2qual    (unsigned long qual, int blen, char * buf, int code);
  50. Prototype long     qual2iqual    (ushort qual);
  51.  
  52. Prototype int     a2iqual    (char * str, long * piqual);
  53. Prototype char * iqual2a    (long iqual);
  54. Prototype char     CtoA        (char c);
  55.  
  56. Prototype void     keyboard_init    (void);
  57. Prototype void     init_kb    (void);
  58. Prototype void     exit_kb    (void);
  59. Prototype struct Library * ConsoleDevice;
  60.  
  61. /**************************************
  62.       Interne Defines & Strukturen
  63. **************************************/
  64. typedef struct IOStdReq CIO;
  65.  
  66. /* format of entries in lname[] */
  67. #define LN(a,b,c,d)  ((a<<24)|(b<<16)|(c<<8)|d)
  68.  
  69. /* important numbers in lname[] */
  70. #define F1_START  0
  71. #define SP_START 10
  72. #define CS_START 20
  73. #define N0_START 24
  74. #define NS_START N0_START+10
  75. #define MB_START 41
  76.  
  77. /* internal representation for qualifiers */
  78. #define QUAL_SHIFT   0x0001
  79. #define QUAL_CTRL    0x0002
  80. #define QUAL_AMIGA   0x0004
  81. #define QUAL_ALT     0x0008
  82. #define QUAL_LMB     0x0010
  83. #define QUAL_MMB     0x0020
  84. #define QUAL_RMB     0x0040
  85.  
  86. #define QUAL_UP      0x0080 /* currently this MUST be 0x80 - that value is used in im.Code */
  87.  
  88. #define QUAL_XTX     0x0100 /* Extended Qualifiers for multi-key strokes */
  89. #define QUAL_XTY     0x0200
  90. #define QUAL_XTZ     0x0400
  91.  
  92. /* additional pseudo-intuition qualifiers - referring to the Quals above */
  93. #define EXTQUALIFIER_X    0x00100000
  94. #define EXTQUALIFIER_Y    0x00200000
  95. #define EXTQUALIFIER_Z    0x00400000
  96.  
  97. #define EXTQUALIFIER_UP 0x00800000 /* this one is not used yet */
  98.  
  99. /* some hardcoded keys on Amiga Keyboard */
  100. #define CSPC  0x40 /* Spacebar    */
  101. #define CB_S  0x41 /* BackSpace */
  102. #define CENT  0x43 /* Enter    */
  103. #define CRET  0x44 /* Return    */
  104.  
  105.  
  106. /**************************************
  107.         Interne Variable
  108. **************************************/
  109. static ubyte ctoa[128];    /* code to ascii  */
  110. static ubyte cstoa[128];   /* code shifted to ascii */
  111.  
  112. static long lname[] = {
  113.     /* FuncKeys */
  114.     LN('f','1', 0 , 0  ), LN('f','2', 0 , 0  ), LN('f','3', 0 , 0  ),
  115.     LN('f','4', 0 , 0  ), LN('f','5', 0 , 0  ), LN('f','6', 0 , 0  ),
  116.     LN('f','7', 0 , 0  ), LN('f','8', 0 , 0  ), LN('f','9', 0 , 0  ),
  117.     LN('f','1','0', 0  ),
  118.     /* Specials */
  119.     LN('h','e','l', 0  ), LN('e','s','c', 0  ), LN('d','e','l', 0  ),
  120.     LN('b','a','c', 0  ), LN('b','s', 0 , 0  ), LN('t','a','b', 0  ),
  121.     LN('r','e','t',CRET), LN('e','n','t',CENT), LN('s','p','c',CSPC),
  122.     LN('s','p','a',CSPC),
  123.     /* Cursor */
  124.     LN('u','p', 0 , 0  ), LN('d','o','w', 0  ), LN('r','i','g', 0  ),
  125.     LN('l','e','f', 0  ),
  126.     /* Numeric digits */
  127.     LN('n','k','0', 0  ), LN('n','k','1', 0  ), LN('n','k','2', 0  ),
  128.     LN('n','k','3', 0  ), LN('n','k','4', 0  ), LN('n','k','5', 0  ),
  129.     LN('n','k','6', 0  ), LN('n','k','7', 0  ), LN('n','k','8', 0  ),
  130.     LN('n','k','9', 0  ),
  131.     /* Numeric Specials */
  132.     LN('n','k', 0 , 0  ), LN('n','k', 0 , 0  ), LN('n','k','/', 0  ),
  133.     LN('n','k','*', 0  ), LN('n','k','+', 0  ), LN('n','k','-', 0  ),
  134.     LN('n','k','.', 0  ),
  135.     /* Mouse Buttons */
  136.     LN('l','m','b',0x68), LN('m','m','b',0x6A), LN('r','m','b',0x69),
  137.     LN('m','m','o',0x6B)
  138. };
  139.  
  140.  
  141.        struct Library * ConsoleDevice;
  142. static struct Library * KC_ConsoleDevice = NULL;      /* obsolete */
  143. static int        KC_Used      = 0;          /* obsolete */
  144.  
  145. /**************************************
  146.        Interne Prototypes
  147. **************************************/
  148.  
  149.  
  150. /*****************************************************************************
  151.  
  152.     NAME
  153.     keyboard_init
  154.  
  155.     PARAMETER
  156.     void
  157.  
  158.     RESULT
  159.     -/-
  160.  
  161.     RETURN
  162.     void
  163.  
  164.     DESCRIPTION
  165.     initializes the variables used in the current Module
  166.  
  167.     NOTES
  168.     That functon MUST be called before any other call to any
  169.     other functions of the key-modules
  170.  
  171.     BUGS
  172.     if a dead- and a deadable-key are next to each other,
  173.     tables may be corrupt
  174.  
  175.     EXAMPLES
  176.  
  177.     SEE ALSO
  178.  
  179.     INTERNALS
  180.  
  181.     HISTORY
  182.     14-Dec-92  b_null included & modified
  183.  
  184. ******************************************************************************/
  185.  
  186. void keyboard_init (void)
  187. {
  188.     static struct InputEvent ievent = {
  189.     NULL,
  190.     IECLASS_RAWKEY,
  191.     0, 0, 0, NULL,
  192.     };
  193.     ubyte buf[32];
  194.     short i,
  195.       len;
  196.  
  197. /* printf ("keyboard_init\n"); */
  198.     for (i = 0; i < 128; ++i) {
  199.     ievent.ie_Code = i;
  200.     ievent.ie_Qualifier = 0;
  201.     ievent.ie_position.ie_addr = NULL;
  202.  
  203.     len = RawKeyConvert (&ievent, buf, 32, NULL);
  204.  
  205.     switch(len) {
  206.     case 1:     /*    ESC/DEL/BS/TAB/NKx  */
  207.         if ((buf[0] & 0x7F) >= 32 && (buf[0] & 0x7F) < 127)
  208.         ctoa[i] = buf[0];
  209.  
  210.         switch(buf[0]) {
  211.         case 0x1B:    lname[SP_START+1] |= i; break;
  212.         case 0x7F:    lname[SP_START+2] |= i; break;
  213.         case 0x08:    lname[SP_START+3] |= i;
  214.             lname[SP_START+4] |= i; break;
  215.         case 0x09:    lname[SP_START+5] |= i; break;
  216.         case '@':                                                           /* for setmap cdn     */
  217.         case '[':                                                           /* for setmap d,f,i,n */
  218.         case '(': if (i > 0x3A) lname[NS_START+0] |= LN(0,0,*buf,i); break; /* for setmap usa/gb  */
  219.         case '°':                                                           /* for setmap cdn     */
  220.         case ']':                                                           /* for setmap d,i,f,n */
  221.         case ')': if (i > 0x3A) lname[NS_START+1] |= LN(0,0,*buf,i); break; /* for setmap usa/gb  */
  222.         case '/': if (i > 0x3A) lname[NS_START+2] |= i; break;
  223.         case '*': if (i > 0x3A) lname[NS_START+3] |= i; break;
  224.         case '+': if (i > 0x3A) lname[NS_START+4] |= i; break;
  225.         case '-': if (i > 0x3A) lname[NS_START+5] |= i; break;
  226.         case '.': if (i > 0x3A) lname[NS_START+6] |= i; break;
  227.         default:
  228.         if (i >= 0x0F && isdigit (buf[0]))
  229.             lname[N0_START+buf[0]-'0'] |= i;
  230.         } /* switch */
  231.         break;
  232.  
  233.     case 2:     /*    cursor            */
  234.         if (buf[0] == 0x9B)
  235.         {
  236.         switch(buf[1]) {
  237.         case 0x41:  lname[CS_START+0] |= i;  break;
  238.         case 0x42:  lname[CS_START+1] |= i;  break;
  239.         case 0x43:  lname[CS_START+2] |= i;  break;
  240.         case 0x44:  lname[CS_START+3] |= i;  break;
  241.         }
  242.         }
  243.         break;
  244.  
  245.     case 3:     /*    function/help        */
  246.         if (buf[0] == 0x9B && buf[2] == 0x7E)
  247.         {
  248.         if (buf[1] == 0x3F)
  249.             lname[SP_START+0] |= i;
  250.         if (buf[1] >= 0x30 && buf[1] <= 0x39)
  251.             lname[buf[1]-0x30+F1_START] |= i;
  252.         }
  253.         break;
  254.     } /* switch */
  255.     } /* for */
  256.  
  257.     for (i = 0; i < 128; ++i)
  258.     {
  259.     ievent.ie_Code = i;
  260.     ievent.ie_Qualifier = IEQUALIFIER_LSHIFT;
  261.     ievent.ie_position.ie_addr = NULL;
  262.  
  263.     len = RawKeyConvert (&ievent,buf,32,NULL);
  264.  
  265.     if (len == 1)
  266.         cstoa[i] = buf[0];
  267.     } /* for */
  268.  
  269.     {
  270.     ubyte  code;
  271.     ushort qual;
  272.  
  273.     get_codequal ("c", &code, &qual);
  274.  
  275.     CtlC = code;
  276.     } /* block */
  277. } /* keyboard_init */
  278.  
  279.  
  280.  
  281. /*****************************************************************************
  282.  
  283.     NAME
  284.     cqtoa
  285.  
  286.     PARAMETER
  287.     VAL (int, code)
  288.     VAL (int, qual)
  289.  
  290.     RESULT
  291.     a ptr to the string that is the readable
  292.     form of that key-stroke (static)
  293.  
  294.     RETURN
  295.     char *
  296.  
  297.     DESCRIPTION
  298.  
  299.     NOTES
  300.     we return a ptr to a static array of char
  301.     for only use of Qualifiers simply use code == -1
  302.  
  303.     BUGS
  304.     (none known)
  305.  
  306.     EXAMPLES
  307.  
  308.     SEE ALSO
  309.  
  310.     INTERNALS
  311.  
  312.     HISTORY
  313.     14-Dez-92 b_null created
  314.     14-Jan-93 b_null added UP
  315.  
  316. ******************************************************************************/
  317.  
  318. char * cqtoa (int code, int qual)
  319. {
  320.     static char buf[32];
  321.     char *    ptr = buf;
  322.     int     i;
  323.  
  324.     if (qual & QUAL_SHIFT)
  325.     *ptr++ = 's';
  326.     if (qual & QUAL_CTRL)
  327.     *ptr++ = 'c';
  328.     if (qual & QUAL_ALT)
  329.     *ptr++ = 'a';
  330.     if (qual & QUAL_AMIGA)
  331.     *ptr++ = 'A';
  332.     if (qual & QUAL_LMB)
  333.     *ptr++ = 'L';
  334.     if (qual & QUAL_MMB)
  335.     *ptr++ = 'M';
  336.     if (qual & QUAL_RMB)
  337.     *ptr++ = 'R';
  338.  
  339.     if (qual & QUAL_XTX)
  340.     *ptr++ = 'x';
  341.     if (qual & QUAL_XTY)
  342.     *ptr++ = 'y';
  343.     if (qual & QUAL_XTZ)
  344.     *ptr++ = 'z';
  345.  
  346.     if (qual & QUAL_UP)
  347.     *ptr++ = 'u';
  348. /*
  349. **  --- That little fragment was added
  350. **    to be able to get the extended qualifiers with already existing functions
  351. **    U might uncomment it, if U wanna get information about
  352. **    which quals have been set with QUALIFIER
  353. */
  354.     if (code == (-1)) {
  355. /* printf("U used a wrong undef\n"); */
  356.     *ptr++ = 0;
  357.     return(buf);
  358.     } /* if */
  359.  
  360.     // if (qual)        /* commented out for better readable keyfiles */
  361.     *ptr++ = '-';
  362.     for (i = 0; i < sizeof(lname)/sizeof(lname[0]); ++i) {
  363.     if ((lname[i]&0xFF) == code) {
  364.         *ptr++ = (lname[i]>>24);
  365.         *ptr++ = (lname[i]>>16);
  366.         *ptr++ = (lname[i]>>8);
  367.         break;
  368.     }
  369.     }
  370.     if (i == sizeof(lname)/sizeof(lname[0])) {
  371.     *ptr = ctoa[code];
  372.  
  373.     if (*ptr) {
  374.         ptr ++;
  375.     /* PATCH_NULL [14 Feb 1993] : direct access to rawcodes ... */
  376.     } else {
  377.         sprintf (ptr, "0x%02x",code);
  378.         ptr += 4;
  379.     } /* if */
  380.     /* PATCH_NULL [14 Feb 1993] : ... direct access to rawcodes */
  381.     } /* if no spcname */
  382.  
  383.     *ptr++ = 0;
  384.     return(buf);
  385. } /* cqtoa */
  386.  
  387.  
  388. /*****************************************************************************
  389.  
  390.     NAME
  391.     get_codequal
  392.  
  393.     PARAMETER
  394.     VAL (char *, string)
  395.     VAR (ubyte,  pcode)
  396.     VAR (ushort, pqual)
  397.  
  398.     RESULT
  399.     success: 1 == ok; 0 == error (unknown string)
  400.  
  401.     RETURN
  402.     int
  403.  
  404.     DESCRIPTION
  405.     we try to extract Qualifier- and Keycode -information
  406.     from an ascii-String and put the found values into
  407.     pcode and pqual
  408.  
  409.     NOTES
  410.     for only use of Qualifiers simply use code == -1
  411.  
  412.     BUGS
  413.     (none known)
  414.  
  415.     EXAMPLES
  416.  
  417.     SEE ALSO
  418.  
  419.     INTERNALS
  420.  
  421.     HISTORY
  422.     14-Dec-92 b_null included & modified
  423.     14-Jan-93 b_null added UP
  424.  
  425. ******************************************************************************/
  426.  
  427. int get_codequal (const ubyte * str, ubyte * pcode, ushort * pqual)
  428. {
  429.     const char * base = str;
  430.     ushort     qual;
  431.     short     i;
  432.  
  433.     qual = 0;
  434.     if (strlen(str) > 1) {
  435.     for (; *str && *str != '-'; ++str) {
  436.         if (*str == 's')
  437.         qual |= QUAL_SHIFT;
  438.         if (*str == 'c')
  439.         qual |= QUAL_CTRL;
  440.         if (*str == 'a')
  441.         qual |= QUAL_ALT;
  442.         if (*str == 'A')
  443.         qual |= QUAL_AMIGA;
  444.         if (*str == 'L')
  445.         qual |= QUAL_LMB;
  446.         if (*str == 'M')
  447.         qual |= QUAL_MMB;
  448.         if (*str == 'R')
  449.         qual |= QUAL_RMB;
  450.  
  451.         if (*str == 'x')
  452.         qual |= QUAL_XTX;
  453.         if (*str == 'y')
  454.         qual |= QUAL_XTY;
  455.         if (*str == 'z')
  456.         qual |= QUAL_XTZ;
  457.  
  458.         if (*str == 'u')
  459.         qual |= QUAL_UP;
  460.  
  461.         if (!qual)
  462.         goto notqual;
  463.     }
  464.     if (*str == 0) {
  465.         qual = 0;
  466.         str = base;
  467.     } else {
  468.         ++str;
  469.     }
  470.     }
  471. notqual:
  472.     if (strlen(str) != 1) {           /* long name   */
  473.     short shift = 24;
  474.     long mult = 0;
  475.     ubyte c;
  476.     ubyte * ptr = str; /* PATCH_NULL [14 Feb 1993] : added */
  477.  
  478.     *pqual = qual;
  479.     while ((c = *str) && shift >= 8) {
  480.         c = tolower (c);
  481.         mult |= c << shift;
  482.         shift -= 8;
  483.         ++str;
  484.     }
  485.     for (i = 0; lname[i]; ++i) {
  486.         if (mult == (lname[i] & 0xFFFFFF00)) {
  487.         *pcode = lname[i] & 0xFF;
  488.         return (1);
  489.         }
  490.     }
  491.     /* PATCH_NULL [14 Feb 1993] : direct access to raw-codes ... */
  492.     /* NOTE             : we cannot save that value yet!!! */
  493. /* printf ("testing %s with hex\n", str); */
  494.     if ((*ptr == '0') && ((ptr[1]|0x20) == 'x')) {
  495.         i = (strtol (ptr, &str, 0x10) & 0xff);
  496.         if (ptr != (ubyte *)str) {
  497.         *pcode = i;
  498.         return (1);
  499.         } /* if scanned */
  500.     } /* if */
  501.     /* PATCH_NULL [14 Feb 1993] : ... direct access to raw-codes */
  502.     } else {            /*    single character keycap */
  503.     for (i = 0; i < sizeof(ctoa); ++i) {
  504.         if (*str == ctoa[i]) {
  505.         *pcode = i;
  506.         *pqual = qual;
  507.         return (1);
  508.         }
  509.     }
  510.     for (i = 0; i < sizeof(cstoa); ++i) {
  511.         if (*str == cstoa[i]) {
  512.         *pcode = i;
  513.         *pqual = qual|QUAL_SHIFT;
  514.         return (1);
  515.         }
  516.     }
  517.     }
  518.     return (0);
  519. } /* get_codequal */
  520.  
  521.  
  522. /*****************************************************************************
  523.  
  524.     NAME
  525.     iqual2qual
  526.  
  527.     PARAMETER
  528.     VAL (ulong,  qual)
  529.     VAL (int,    blen)
  530.     VAL (char *, buf)
  531.     VAL (int,    code)
  532.  
  533.     RESULT
  534.     the [X]DME-internal qualifier referred by the intuition qualifier qual;
  535.  
  536.     RETURN
  537.     ushort
  538.  
  539.     DESCRIPTION
  540.     transform the different intuition - Qualifiers to [X]DME-Qualifiers
  541.     (if we have caps-lock and buffer contains
  542.     one lower char, it is used like shift)
  543.  
  544.     NOTES
  545.  
  546.     BUGS
  547.     (none known)
  548.  
  549.     EXAMPLES
  550.  
  551.     SEE ALSO
  552.  
  553.     INTERNALS
  554.  
  555.     HISTORY
  556.     14-Dec-92 b_null included & modified
  557.     14-Jan-93 b_null added UP
  558.  
  559. ******************************************************************************/
  560.  
  561. ushort iqual2qual (unsigned long qual, int blen, char * buf, int code)
  562. {
  563.     ushort q2 = 0;
  564.  
  565.     if (qual & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT))
  566.     q2 |= QUAL_SHIFT;
  567.     if (qual & (IEQUALIFIER_CONTROL))
  568.     q2 |= QUAL_CTRL;
  569.     if (qual & (IEQUALIFIER_LCOMMAND|IEQUALIFIER_RCOMMAND))
  570.     q2 |= QUAL_AMIGA;
  571.     if (qual & (IEQUALIFIER_LALT|IEQUALIFIER_RALT))
  572.     q2 |= QUAL_ALT;
  573.     if ((qual & IEQUALIFIER_CAPSLOCK) && blen == 1 && islower (buf[1]))
  574.     q2 |= QUAL_SHIFT;
  575.     if (qual & IEQUALIFIER_LEFTBUTTON)
  576.     q2 |= QUAL_LMB;
  577.     if (qual & IEQUALIFIER_MIDBUTTON)
  578.     q2 |= QUAL_MMB;
  579.     if (qual & (IEQUALIFIER_RBUTTON))
  580.     q2 |= QUAL_RMB;
  581.  
  582.     if (qual & (EXTQUALIFIER_X))
  583.     q2 |= QUAL_XTX;
  584.     if (qual & (EXTQUALIFIER_Y))
  585.     q2 |= QUAL_XTY;
  586.     if (qual & (EXTQUALIFIER_Z))
  587.     q2 |= QUAL_XTZ;
  588.  
  589.     if (qual & (EXTQUALIFIER_UP))
  590.     q2 |= QUAL_XTZ;
  591.     q2 |= (QUAL_UP & code);
  592.  
  593.     return(q2);
  594. } /* iqual2qual */
  595.  
  596.  
  597. /*****************************************************************************
  598.  
  599.     NAME
  600.     qual2iqual
  601.  
  602.     PARAMETER
  603.     VAL (ushort, qual)
  604.  
  605.     RESULT
  606.     Intuition Qualifiers, which represent the [X]DME - qualifiers
  607.  
  608.     RETURN
  609.     long
  610.  
  611.     DESCRIPTION
  612.     simple transformation of internal representation for
  613.     Qualifiers to a possible Amiga-representation
  614.  
  615.     NOTES
  616.     very slow
  617.     !ATTN!    there is currently no possibility to
  618.         transform the UP-Qualifier
  619.  
  620.     BUGS
  621.     (none known)
  622.  
  623.     EXAMPLES
  624.  
  625.     SEE ALSO
  626.     iqual2qual
  627.  
  628.     INTERNALS
  629.  
  630.     HISTORY
  631.     14-Dez-92 b_null created
  632.     14-Jan-93 b_null added UP
  633.  
  634. ******************************************************************************/
  635.  
  636. long qual2iqual (ushort qual)
  637. {
  638.     long q2 = 0;
  639.  
  640.     if (qual & QUAL_XTX)
  641.     q2 |= EXTQUALIFIER_X;
  642.     if (qual & QUAL_XTY)
  643.     q2 |= EXTQUALIFIER_Y;
  644.     if (qual & QUAL_XTZ)
  645.     q2 |= EXTQUALIFIER_Z;
  646.  
  647.     if (qual & QUAL_UP)
  648.     q2 |= EXTQUALIFIER_UP;
  649.  
  650.     if (qual & QUAL_SHIFT)
  651.     q2 |= IEQUALIFIER_LSHIFT;
  652.     if (qual & QUAL_CTRL)
  653.     q2 |= IEQUALIFIER_CONTROL;
  654.     if (qual & QUAL_AMIGA)
  655.     q2 |= IEQUALIFIER_LCOMMAND;
  656.     if (qual & QUAL_ALT)
  657.     q2 |= IEQUALIFIER_LALT;
  658.     if (qual & QUAL_LMB)
  659.     q2 |= IEQUALIFIER_LEFTBUTTON;
  660.     if (qual & QUAL_MMB)
  661.     q2 |= IEQUALIFIER_MIDBUTTON;
  662.     if (qual & QUAL_RMB)
  663.     q2 |= IEQUALIFIER_RBUTTON;
  664.  
  665.     return (q2);
  666. } /* qual2iqual */
  667.  
  668. /*****************************************************************************
  669.  
  670.     NAME
  671.     a2iqual
  672.  
  673.     PARAMETER
  674.     VAL (char *, str)
  675.     VAR (long,   piqual)
  676.  
  677.     RESULT
  678.     success: 1 == ok; 0 == any error
  679.  
  680.     RETURN
  681.     int
  682.  
  683.     DESCRIPTION
  684.     convert an ascii string into Input-Qualifiers
  685.     we check each char of the string and set the according bit
  686.     the string may be NULL-terminated or "-"-terminated
  687.     any unknown char causes "return (0)"
  688.  
  689.     NOTES
  690.  
  691.     BUGS
  692.     (none known)
  693.  
  694.     EXAMPLES
  695.  
  696.     SEE ALSO
  697.  
  698.     INTERNALS
  699.  
  700.     HISTORY
  701.     14-Dez-92 null created
  702.     14-Jan-93 b_null added UP
  703.  
  704. ******************************************************************************/
  705.  
  706. int a2iqual (char * str, long * piqual)
  707. {
  708.     *piqual = 0;
  709.     for (; *str; str++) {
  710.     switch (*str) {
  711.     case 'a':   *piqual |= IEQUALIFIER_LALT;        break;
  712.     case 'A':   *piqual |= IEQUALIFIER_LCOMMAND;    break;
  713.     case 's':   *piqual |= IEQUALIFIER_LSHIFT;      break;
  714.     case 'L':   *piqual |= IEQUALIFIER_LEFTBUTTON;  break;
  715.     case 'M':   *piqual |= IEQUALIFIER_MIDBUTTON;   break;
  716.     case 'R':   *piqual |= IEQUALIFIER_RBUTTON;     break;
  717.  
  718.     case 'u':   *piqual |= EXTQUALIFIER_UP;         break;
  719.  
  720.     case 'x':   *piqual |= EXTQUALIFIER_X;          break;
  721.     case 'y':   *piqual |= EXTQUALIFIER_Y;          break;
  722.     case 'z':   *piqual |= EXTQUALIFIER_Z;          break;
  723.  
  724.     case '-':   return (1);
  725.     default:    return (0);
  726.     } /* switch */
  727.     } /* for */
  728.     return (1);
  729. } /* a2iqual */
  730.  
  731. /*****************************************************************************
  732.  
  733.     NAME
  734.     iqual2a
  735.  
  736.     PARAMETER
  737.     VAL (long, iqual)
  738.  
  739.     RESULT
  740.     the string that corresponds to iqual  (static)
  741.  
  742.     RETURN
  743.     char *
  744.  
  745.     DESCRIPTION
  746.     create a string representing the readble form of Intuition Qualifiers
  747.  
  748.     NOTES
  749.     this is a slow routine, as we do not
  750.     immediately evaluated the string, but
  751.     use iqual2qual and cqtoa (but it works :-)
  752.  
  753.     BUGS
  754.     (none known)
  755.  
  756.     EXAMPLES
  757.  
  758.     SEE ALSO
  759.     iqual2qual(), cqtoa
  760.  
  761.     INTERNALS
  762.  
  763.     HISTORY
  764.     14-Dez-92 null created
  765.  
  766. ******************************************************************************/
  767.  
  768. char * iqual2a (long iqual)
  769. {
  770.     return (cqtoa (-1, iqual2qual (iqual, 0, NULL, 0)));
  771. } /* iqual2a */
  772.  
  773.  
  774. /*****************************************************************************
  775.  
  776.     NAME
  777.     init_kb
  778.     (exit_kb - obsolete)
  779.  
  780.     PARAMETER
  781.     void
  782.  
  783.     RESULT
  784.     -/-
  785.  
  786.     RETURN
  787.     void
  788.  
  789.     DESCRIPTION
  790.     entry and exit- code for Keyboard Control
  791.  
  792.     NOTES
  793.     this is the lowest level on Amiga Software, we use
  794.     exit_kb is obsolete, so user cannot call it any more
  795.     init_kb is "__AUTOINIT" so user need not call it
  796.     (he must indeed, if his compiler does not support __autoinit)
  797.  
  798.     BUGS
  799.     for unknown reasons, we must not close ConsoleDevice
  800.  
  801.     EXAMPLES
  802.  
  803.     SEE ALSO
  804.  
  805.     INTERNALS
  806.  
  807.     HISTORY
  808.     15-Dez-92  b_null created
  809.     15-Jan-93  b_null removed exit_kb
  810.  
  811. ******************************************************************************/
  812.  
  813. /* Das war teil von reset_hash... */
  814. /* es ist extremer Amiga - lowlevel - wohin?? */
  815. /*
  816. ** Achtung: keine Ahnung wieso,
  817. **  aber wir DUERFEN ConsoleDevice nicht schliessen
  818. **    es ist jedenfalls so, dass wir sonst ziemlich abkacken
  819. **  zwischenspeichern nuetzt nix ...
  820. **  daher koennen wir diesen ganzen kram mit KC_... weglassen
  821. */
  822.  
  823.  
  824. __autoinit
  825. void init_kb (void)
  826. {
  827.     struct IOStdReq cio;
  828.  
  829. /* printf ("init_kb\n"); */
  830.  
  831.     if (!KC_Used) {
  832.     OpenDevice ("console.device", -1, (struct IORequest *)&cio, 0);
  833.     ConsoleDevice = (struct Library *)cio.io_Device;
  834.     keyboard_init ();
  835.     } /* if */
  836.     KC_Used = 1;
  837. } /* init_kb */
  838.  
  839.  
  840. /*****************************************************************************
  841.  
  842.     NAME
  843.     CtoA
  844.  
  845.     PARAMETER
  846.     char c
  847.  
  848.     RESULT
  849.     ctoa[c]
  850.  
  851.     RETURN
  852.     char
  853.  
  854.     DESCRIPTION
  855.     this function was created to hide the stucture ctoa
  856.  
  857.     ctoa is designed to check, IF a code c represents a
  858.     single ascii character and WHICH one
  859.  
  860.     NOTES
  861.     a macro might be possible, too;
  862.     but then You have to declare ctoa non-static
  863.  
  864.     ctoa is initialized by keyboard_init(), so
  865.     any call to CtoA before keyboard initialisation is undefined
  866.  
  867.     BUGS
  868.     none known
  869.  
  870.     EXAMPLES
  871.  
  872.     SEE ALSO
  873.     ctoa
  874.  
  875.     INTERNALS
  876.  
  877.     HISTORY
  878.     30-Dez-92 b_null created
  879.     15-Jan-93 b_null documented
  880.  
  881. ******************************************************************************/
  882.  
  883. char CtoA (char c)
  884. {
  885.     return (ctoa[c]);
  886. } /* CtoA */
  887.  
  888. /*****************************************************************************
  889.  
  890.     NAME
  891.     DeadKeyConvert
  892.  
  893.     PARAMETER
  894.     struct IntuiMessage * msg
  895.     UBYTE *           buf
  896.     int              bufsize
  897.     struct KeyMap *       keymap
  898.  
  899.     RESULT
  900.     actual - the number of characters in the buffer, -2 if no
  901.     RawKey was given or -1 if a buffer overflow was about to occur.
  902.  
  903.     RETURN
  904.     int
  905.  
  906.     DESCRIPTION
  907.     convert any RawKey-Code to (VanillaKey) an ASCII-String
  908.  
  909.     NOTES
  910.     this function is only used by keycontrol.keyctl
  911.     but it for itself uses ConsoleDevice, so I could not
  912.     decide where to pu it.
  913.  
  914.     BUGS
  915.  
  916.     EXAMPLES
  917.  
  918.     SEE ALSO
  919.     console.device/RawKeyConvert
  920.  
  921.     INTERNALS
  922.     ereuge eine iorequest mit den allernotwendigsten eintraegen
  923.     und lasse sie auswerten
  924.  
  925.     HISTORY
  926.     15-Dez-92 b_null moved to keycontrol.c
  927.     16.Dez.92 b_null documented
  928.     15-Jan-93 b_null moved to keycodes.c
  929.  
  930. ******************************************************************************/
  931.  
  932. Prototype int     DeadKeyConvert (struct IntuiMessage * msg, UBYTE * buf, int bufsize, struct KeyMap * keymap);
  933.  
  934. int DeadKeyConvert (struct IntuiMessage * msg, UBYTE * buf, int bufsize, struct KeyMap * keymap)
  935. {
  936.     static struct InputEvent ievent = {
  937.     NULL, IECLASS_RAWKEY
  938.     };
  939.  
  940.     if (msg->Class != RAWKEY)
  941.     return(-2);
  942.  
  943.     ievent.ie_Code           = msg->Code;
  944.     ievent.ie_Qualifier        = msg->Qualifier;
  945.     ievent.ie_position.ie_addr = *((APTR *)msg->IAddress);
  946.  
  947.     return (RawKeyConvert (&ievent, (char *)buf, bufsize, keymap));
  948. } /* DeadKeyConvert */
  949.  
  950.  
  951. /******************************************************************************
  952. *****  ENDE keycodes.c
  953. ******************************************************************************/
  954.