1 /* 2 * Copyright (c) 1992 OMRON Corporation. 3 * Copyright (c) 1992 The Regents of the University of California. 4 * All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * OMRON Corporation. 8 * 9 * %sccs.include.redist.c% 10 * 11 * @(#)kbd.c 7.2 (Berkeley) 01/20/93 12 */ 13 14 /* 15 * kbd.c -- key-code decoding routine 16 * by A.Fujita, Dec-12-1992 17 */ 18 19 #include <sys/param.h> 20 #include <luna68k/stand/kbdreg.h> 21 22 struct kbd_keymap kbd_keymap[] = { 23 KC_IGNORE, 0, 0, /* 0 [0x00] */ 24 KC_IGNORE, 0, 0, /* 1 [0x01] */ 25 KC_IGNORE, 0, 0, /* 2 [0x02] */ 26 KC_IGNORE, 0, 0, /* 3 [0x03] */ 27 KC_IGNORE, 0, 0, /* 4 [0x04] */ 28 KC_IGNORE, 0, 0, /* 5 [0x05] */ 29 KC_IGNORE, 0, 0, /* 6 [0x06] */ 30 KC_IGNORE, 0, 0, /* 7 [0x07] */ 31 KC_IGNORE, 0, 0, /* 8 [0x08] */ 32 KC_CODE, 0x09, 0x09, /* 9 [0x09] TAB */ 33 KC_SHIFT, KS_CTRL, KS_CTRL, /* 10 [0x0A] CTRL */ 34 KC_IGNORE, 0, 0, /* 11 [0x0B] */ 35 KC_SHIFT, KS_SHIFT, KS_SHIFT, /* 12 [0x0C] SHIFT */ 36 KC_SHIFT, KS_SHIFT, KS_SHIFT, /* 13 [0x0D] SHIFT */ 37 KC_IGNORE, 0, 0, /* 14 [0x0E] */ 38 KC_SHIFT, KS_META, KS_META, /* 15 [0x0F] META */ 39 KC_CODE, 0x1B, 0x1B, /* 16 [0x10] ESC */ 40 KC_CODE, 0x08, 0x08, /* 17 [0x11] BS */ 41 KC_CODE, 0x0D, 0x0D, /* 18 [0x12] CR */ 42 KC_IGNORE, 0, 0, /* 19 [0x13] */ 43 KC_CODE, 0x20, 0x20, /* 20 [0x14] SP */ 44 KC_CODE, 0x7F, 0x7F, /* 21 [0x15] DEL */ 45 KC_IGNORE, 0, 0, /* 22 [0x16] */ 46 KC_IGNORE, 0, 0, /* 23 [0x17] */ 47 KC_IGNORE, 0, 0, /* 24 [0x18] */ 48 KC_IGNORE, 0, 0, /* 25 [0x19] */ 49 KC_IGNORE, 0, 0, /* 26 [0x1A] */ 50 KC_IGNORE, 0, 0, /* 27 [0x1B] */ 51 KC_IGNORE, 0, 0, /* 28 [0x1C] */ 52 KC_IGNORE, 0, 0, /* 29 [0x1D] */ 53 KC_IGNORE, 0, 0, /* 30 [0x1E] */ 54 KC_IGNORE, 0, 0, /* 31 [0x1F] */ 55 KC_IGNORE, 0, 0, /* 32 [0x20] */ 56 KC_IGNORE, 0, 0, /* 33 [0x21] */ 57 KC_CODE, 0x31, 0x21, /* 34 [0x22] 1 */ 58 KC_CODE, 0x32, 0x22, /* 35 [0x23] 2 */ 59 KC_CODE, 0x33, 0x23, /* 36 [0x24] 3 */ 60 KC_CODE, 0x34, 0x24, /* 37 [0x25] 4 */ 61 KC_CODE, 0x35, 0x25, /* 38 [0x26] 5 */ 62 KC_CODE, 0x36, 0x26, /* 39 [0x27] 6 */ 63 KC_CODE, 0x37, 0x27, /* 40 [0x28] 7 */ 64 KC_CODE, 0x38, 0x28, /* 41 [0x29] 8 */ 65 KC_CODE, 0x39, 0x29, /* 42 [0x2A] 9 */ 66 KC_CODE, 0x30, 0x30, /* 43 [0x2B] 0 */ 67 KC_CODE, 0x2D, 0x3D, /* 44 [0x2C] - */ 68 KC_CODE, 0x5E, 0x7E, /* 45 [0x2D] ^ */ 69 KC_CODE, 0x5C, 0x7C, /* 46 [0x2E] \ */ 70 KC_IGNORE, 0, 0, /* 47 [0x2F] */ 71 KC_IGNORE, 0, 0, /* 48 [0x30] */ 72 KC_IGNORE, 0, 0, /* 49 [0x31] */ 73 KC_CODE, 0x71, 0x51, /* 50 [0x32] q */ 74 KC_CODE, 0x77, 0x57, /* 51 [0x33] w */ 75 KC_CODE, 0x65, 0x45, /* 52 [0x34] e */ 76 KC_CODE, 0x72, 0x52, /* 53 [0x35] r */ 77 KC_CODE, 0x74, 0x54, /* 54 [0x36] t */ 78 KC_CODE, 0x79, 0x59, /* 55 [0x37] y */ 79 KC_CODE, 0x75, 0x55, /* 56 [0x38] u */ 80 KC_CODE, 0x69, 0x49, /* 57 [0x39] i */ 81 KC_CODE, 0x6F, 0x4F, /* 58 [0x3A] o */ 82 KC_CODE, 0x70, 0x50, /* 59 [0x3B] p */ 83 KC_CODE, 0x40, 0x60, /* 60 [0x3C] @ */ 84 KC_CODE, 0x5B, 0x7B, /* 61 [0x3D] [ */ 85 KC_IGNORE, 0, 0, /* 62 [0x3E] */ 86 KC_IGNORE, 0, 0, /* 63 [0x3F] */ 87 KC_IGNORE, 0, 0, /* 64 [0x40] */ 88 KC_IGNORE, 0, 0, /* 65 [0x41] */ 89 KC_CODE, 0x61, 0x41, /* 66 [0x42] a */ 90 KC_CODE, 0x73, 0x53, /* 67 [0x43] s */ 91 KC_CODE, 0x64, 0x44, /* 68 [0x44] d */ 92 KC_CODE, 0x66, 0x46, /* 69 [0x45] f */ 93 KC_CODE, 0x67, 0x47, /* 70 [0x46] g */ 94 KC_CODE, 0x68, 0x48, /* 71 [0x47] h */ 95 KC_CODE, 0x6A, 0x4A, /* 72 [0x48] j */ 96 KC_CODE, 0x6B, 0x4B, /* 73 [0x49] k */ 97 KC_CODE, 0x6C, 0x4C, /* 74 [0x4A] l */ 98 KC_CODE, 0x3B, 0x2B, /* 75 [0x4B] ; */ 99 KC_CODE, 0x3A, 0x2A, /* 76 [0x4C] : */ 100 KC_CODE, 0x5D, 0x7D, /* 77 [0x4D] ] */ 101 KC_IGNORE, 0, 0, /* 78 [0x4E] */ 102 KC_IGNORE, 0, 0, /* 79 [0x4F] */ 103 KC_IGNORE, 0, 0, /* 80 [0x50] */ 104 KC_IGNORE, 0, 0, /* 81 [0x51] */ 105 KC_CODE, 0x7A, 0x5A, /* 82 [0x52] z */ 106 KC_CODE, 0x78, 0x58, /* 83 [0x53] x */ 107 KC_CODE, 0x63, 0x43, /* 84 [0x54] c */ 108 KC_CODE, 0x76, 0x56, /* 85 [0x55] v */ 109 KC_CODE, 0x62, 0x42, /* 86 [0x56] b */ 110 KC_CODE, 0x6E, 0x4E, /* 87 [0x57] n */ 111 KC_CODE, 0x6D, 0x4D, /* 88 [0x58] m */ 112 KC_CODE, 0x2C, 0x3C, /* 89 [0x59] , */ 113 KC_CODE, 0x2E, 0x3E, /* 90 [0x5A] . */ 114 KC_CODE, 0x2F, 0x3F, /* 91 [0x5B] / */ 115 KC_CODE, 0x5F, 0x5F, /* 92 [0x5C] _ */ 116 KC_IGNORE, 0, 0, /* 93 [0x5D] */ 117 KC_IGNORE, 0, 0, /* 94 [0x5E] */ 118 KC_IGNORE, 0, 0, /* 95 [0x5F] */ 119 KC_IGNORE, 0, 0, /* 96 [0x60] */ 120 KC_IGNORE, 0, 0, /* 97 [0x61] */ 121 KC_IGNORE, 0, 0, /* 98 [0x62] */ 122 KC_IGNORE, 0, 0, /* 99 [0x63] */ 123 KC_IGNORE, 0, 0, /* 100 [0x64] */ 124 KC_IGNORE, 0, 0, /* 101 [0x65] */ 125 KC_IGNORE, 0, 0, /* 102 [0x66] */ 126 KC_IGNORE, 0, 0, /* 103 [0x67] */ 127 KC_IGNORE, 0, 0, /* 104 [0x68] */ 128 KC_IGNORE, 0, 0, /* 105 [0x69] */ 129 KC_IGNORE, 0, 0, /* 106 [0x6A] */ 130 KC_IGNORE, 0, 0, /* 107 [0x6B] */ 131 KC_IGNORE, 0, 0, /* 108 [0x6C] */ 132 KC_IGNORE, 0, 0, /* 109 [0x6D] */ 133 KC_IGNORE, 0, 0, /* 110 [0x6E] */ 134 KC_IGNORE, 0, 0, /* 111 [0x6F] */ 135 KC_IGNORE, 0, 0, /* 112 [0x70] */ 136 KC_IGNORE, 0, 0, /* 113 [0x71] */ 137 KC_IGNORE, 0, 0, /* 114 [0x72] */ 138 KC_IGNORE, 0, 0, /* 115 [0x73] */ 139 KC_IGNORE, 0, 0, /* 116 [0x74] */ 140 KC_IGNORE, 0, 0, /* 117 [0x75] */ 141 KC_IGNORE, 0, 0, /* 118 [0x76] */ 142 KC_IGNORE, 0, 0, /* 119 [0x77] */ 143 KC_IGNORE, 0, 0, /* 120 [0x78] */ 144 KC_IGNORE, 0, 0, /* 121 [0x79] */ 145 KC_IGNORE, 0, 0, /* 122 [0x7A] */ 146 KC_IGNORE, 0, 0, /* 123 [0x7B] */ 147 KC_IGNORE, 0, 0, /* 124 [0x7C] */ 148 KC_IGNORE, 0, 0, /* 125 [0x7D] */ 149 KC_IGNORE, 0, 0, /* 126 [0x7E] */ 150 KC_IGNORE, 0, 0, /* 127 [0x7F] */ 151 }; 152 153 int shift_flag = 0; 154 int ctrl_flag = 0; 155 int meta_flag = 0; 156 157 kbd_decode(code) 158 register u_char code; 159 { 160 register unsigned int c, updown = 0; 161 162 if (code & 0x80) 163 updown = 1; 164 165 code &= 0x7F; 166 167 c = kbd_keymap[code].km_type; 168 169 if (c == KC_IGNORE) 170 return(KC_IGNORE); 171 172 if ((c == KC_CODE) && updown) 173 return(KC_IGNORE); 174 175 if (c == KC_SHIFT) { 176 switch(kbd_keymap[code].km_code[0]) { 177 178 case KS_SHIFT: 179 shift_flag = 1 - updown; 180 break; 181 182 case KS_CTRL: 183 ctrl_flag = 1 - updown; 184 break; 185 186 case KS_META: 187 meta_flag = 1 - updown; 188 break; 189 } 190 191 return(KC_IGNORE); 192 } 193 194 if (shift_flag) 195 c = kbd_keymap[code].km_code[1]; 196 else 197 c = kbd_keymap[code].km_code[0]; 198 199 if (meta_flag) 200 c |= 0x80; 201 202 if (ctrl_flag) 203 c &= 0x1F; 204 205 return(c); 206 } 207