hil.c revision 1.3.50.3 1 /* $NetBSD: hil.c,v 1.3.50.3 2004/09/21 13:15:27 skrll Exp $ */
2
3 /*-
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Copyright (c) 1990, 1993
41 * The Regents of the University of California. All rights reserved.
42 *
43 * This code is derived from software contributed to Berkeley by
44 * the Systems Programming Group of the University of Utah Computer
45 * Science Department.
46 *
47 * Redistribution and use in source and binary forms, with or without
48 * modification, are permitted provided that the following conditions
49 * are met:
50 * 1. Redistributions of source code must retain the above copyright
51 * notice, this list of conditions and the following disclaimer.
52 * 2. Redistributions in binary form must reproduce the above copyright
53 * notice, this list of conditions and the following disclaimer in the
54 * documentation and/or other materials provided with the distribution.
55 * 3. Neither the name of the University nor the names of its contributors
56 * may be used to endorse or promote products derived from this software
57 * without specific prior written permission.
58 *
59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
70 *
71 * from: Utah Hdr: hil.c 1.1 89/08/22
72 *
73 * @(#)hil.c 8.1 (Berkeley) 6/10/93
74 */
75 /*
76 * Copyright (c) 1988 University of Utah.
77 *
78 * This code is derived from software contributed to Berkeley by
79 * the Systems Programming Group of the University of Utah Computer
80 * Science Department.
81 *
82 * Redistribution and use in source and binary forms, with or without
83 * modification, are permitted provided that the following conditions
84 * are met:
85 * 1. Redistributions of source code must retain the above copyright
86 * notice, this list of conditions and the following disclaimer.
87 * 2. Redistributions in binary form must reproduce the above copyright
88 * notice, this list of conditions and the following disclaimer in the
89 * documentation and/or other materials provided with the distribution.
90 * 3. All advertising materials mentioning features or use of this software
91 * must display the following acknowledgement:
92 * This product includes software developed by the University of
93 * California, Berkeley and its contributors.
94 * 4. Neither the name of the University nor the names of its contributors
95 * may be used to endorse or promote products derived from this software
96 * without specific prior written permission.
97 *
98 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
99 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
100 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
101 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
102 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
103 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
104 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
105 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
106 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
107 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
108 * SUCH DAMAGE.
109 *
110 * from: Utah Hdr: hil.c 1.1 89/08/22
111 *
112 * @(#)hil.c 8.1 (Berkeley) 6/10/93
113 */
114
115 /*
116 * HIL keyboard routines for the standalone ITE.
117 */
118
119 #if defined(ITECONSOLE) && defined(HIL_KEYBOARD)
120
121 #include <sys/param.h>
122 #include <sys/device.h> /* XXX */
123
124 #include <hp300/dev/hilreg.h>
125 #include <hp300/dev/kbdmap.h>
126 #include <hp300/dev/itevar.h>
127
128 #include <hp300/stand/common/samachdep.h>
129 #include <hp300/stand/common/kbdvar.h>
130
131 #ifndef SMALL
132
133 /*
134 * HIL cooked keyboard keymaps.
135 * Supports only unshifted, shifted and control keys.
136 */
137 char hil_us_keymap[] = {
138 '\0', '`', '\\', ESC, '\0', DEL, '\0', '\0',
139 '\n', '\t', '\0', '\0', '\0', '\0', '\0', '\0',
140 '\0', '\n', '\0', '\0', '\0', '\0', '\0', '\0',
141 '\0', '\t', '\0', '\0', '\0', '\0', '\0', '\0',
142 '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
143 '\0', '\0', '\0', '\0', '\0', '\0', '\b', '\0',
144 '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
145 ESC, '\r', '\0', '\n', '0', '.', ',', '+',
146 '1', '2', '3', '-', '4', '5', '6', '*',
147 '7', '8', '9', '/', 'E', '(', ')', '^',
148 '1', '2', '3', '4', '5', '6', '7', '8',
149 '9', '0', '-', '=', '[', ']', ';', '\'',
150 ',', '.', '/', '\040', 'o', 'p', 'k', 'l',
151 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
152 'a', 's', 'd', 'f', 'g', 'h', 'j', 'm',
153 'z', 'x', 'c', 'v', 'b', 'n', '\0', '\0'
154 };
155
156 char hil_us_shiftmap[] = {
157 '\0', '~', '|', DEL, '\0', DEL, '\0', '\0',
158 '\n', '\t', '\0', '\0', '\0', '\0', '\0', '\0',
159 '\0', '\n', '\0', '\0', '\0', '\0', '\0', '\0',
160 '\0', '\t', '\0', '\0', '\0', '\0', '\0', '\0',
161 '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
162 '\0', '\0', '\0', '\0', '\0', '\0', DEL, '\0',
163 '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
164 ESC, '\r', '\0', '\n', '0', '.', ',', '+',
165 '1', '2', '3', '-', '4', '5', '6', '*',
166 '7', '8', '9', '/', '`', '|', '\\', '~',
167 '!', '@', '#', '$', '%', '^', '&', '*',
168 '(', ')', '_', '+', '{', '}', ':', '\"',
169 '<', '>', '?', '\040', 'O', 'P', 'K', 'L',
170 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I',
171 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'M',
172 'Z', 'X', 'C', 'V', 'B', 'N', '\0', '\0'
173 };
174
175 char hil_us_ctrlmap[] = {
176 '\0', '`', '\034', ESC, '\0', DEL, '\0', '\0',
177 '\n', '\t', '\0', '\0', '\0', '\0', '\0', '\0',
178 '\0', '\n', '\0', '\0', '\0', '\0', '\0', '\0',
179 '\0', '\t', '\0', '\0', '\0', '\0', '\0', '\0',
180 '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
181 '\0', '\0', '\0', '\0', '\0', '\0', '\b', '\0',
182 '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
183 ESC, '\r', '\0', '\n', '0', '.', ',', '+',
184 '1', '2', '3', '-', '4', '5', '6', '*',
185 '7', '8', '9', '/', 'E', '(', ')', '\036',
186 '1', '2', '3', '4', '5', '6', '7', '8',
187 '9', '0', '-', '=', '\033', '\035', ';', '\'',
188 ',', '.', '/', '\040', '\017', '\020', '\013', '\014',
189 '\021', '\027', '\005', '\022', '\024', '\031', '\025', '\011',
190 '\001', '\023', '\004', '\006', '\007', '\010', '\012', '\015',
191 '\032', '\030', '\003', '\026', '\002', '\016', '\0', '\0'
192 };
193
194 #ifdef UK_KEYBOARD
195 char hil_uk_keymap[] = {
196 '\0', '`', '<', ESC, '\0', DEL, '\0', '\0',
197 '\n', '\t', '\0', '\0', '\0', '\0', '\0', '\0',
198 '\0', '\n', '\0', '\0', '\0', '\0', '\0', '\0',
199 '\0', '\t', '\0', '\0', '\0', '\0', '\0', '\0',
200 '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
201 '\0', '\0', '\0', '\0', '\0', '\0', '\b', '\0',
202 '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
203 ESC, '\r', '\0', '\n', '0', '.', ',', '+',
204 '1', '2', '3', '-', '4', '5', '6', '*',
205 '7', '8', '9', '/', 'E', '(', ')', '^',
206 '1', '2', '3', '4', '5', '6', '7', '8',
207 '9', '0', '+', '\'', '[', ']', '*', '\\',
208 ',', '.', '-', '\040', 'o', 'p', 'k', 'l',
209 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
210 'a', 's', 'd', 'f', 'g', 'h', 'j', 'm',
211 'z', 'x', 'c', 'v', 'b', 'n', '\0', '\0'
212 };
213
214 char hil_uk_shiftmap[] = {
215 '\0', '~', '>', DEL, '\0', DEL, '\0', '\0',
216 '\n', '\t', '\0', '\0', '\0', '\0', '\0', '\0',
217 '\0', '\n', '\0', '\0', '\0', '\0', '\0', '\0',
218 '\0', '\t', '\0', '\0', '\0', '\0', '\0', '\0',
219 '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
220 '\0', '\0', '\0', '\0', '\0', '\0', DEL, '\0',
221 '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
222 ESC, '\r', '\0', '\n', '0', '.', ',', '+',
223 '1', '2', '3', '-', '4', '5', '6', '*',
224 '7', '8', '9', '/', '`', '|', '\\', '~',
225 '!', '\"', '#', '$', '%', '&', '^', '(',
226 ')', '=', '?', '/', '{', '}', '@', '|',
227 ';', ':', '_', '\040', 'O', 'P', 'K', 'L',
228 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I',
229 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'M',
230 'Z', 'X', 'C', 'V', 'B', 'N', '\0', '\0'
231 };
232
233 char hil_uk_ctrlmap[] = {
234 '\0', '`', '<', ESC, '\0', DEL, '\0', '\0',
235 '\n', '\t', '\0', '\0', '\0', '\0', '\0', '\0',
236 '\0', '\n', '\0', '\0', '\0', '\0', '\0', '\0',
237 '\0', '\t', '\0', '\0', '\0', '\0', '\0', '\0',
238 '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
239 '\0', '\0', '\0', '\0', '\0', '\0', '\b', '\0',
240 '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
241 ESC, '\r', '\0', '\n', '0', '.', ',', '+',
242 '1', '2', '3', '-', '4', '5', '6', '*',
243 '7', '8', '9', '/', 'E', '(', ')', '\036',
244 '1', '2', '3', '4', '5', '6', '7', '8',
245 '9', '0', '+', '\'', '\033', '\035', '*', '\034',
246 ',', '.', '/', '\040', '\017', '\020', '\013', '\014',
247 '\021', '\027', '\005', '\022', '\024', '\031', '\025', '\011',
248 '\001', '\023', '\004', '\006', '\007', '\010', '\012', '\015',
249 '\032', '\030', '\003', '\026', '\002', '\016', '\0', '\0'
250 };
251 #endif
252
253 /*
254 * The keyboard map table.
255 * Lookup is by hardware returned language code.
256 */
257 struct kbdmap hilkbd_map[] = {
258 { KBD_US, "",
259 hil_us_keymap, hil_us_shiftmap, hil_us_ctrlmap, NULL, NULL},
260
261 #ifdef UK_KEYBOARD
262 { KBD_UK, "",
263 hil_uk_keymap, hil_uk_shiftmap, hil_uk_ctrlmap, NULL, NULL},
264 #endif
265
266 { 0, "",
267 NULL, NULL, NULL, NULL, NULL},
268 };
269
270 char *hilkbd_keymap = hil_us_keymap;
271 char *hilkbd_shiftmap = hil_us_shiftmap;
272 char *hilkbd_ctrlmap = hil_us_ctrlmap;
273
274 int
275 hilkbd_getc()
276 {
277 int status, c;
278 struct hil_dev *hiladdr = HILADDR;
279
280 status = hiladdr->hil_stat;
281 if ((status & HIL_DATA_RDY) == 0)
282 return 0;
283 c = hiladdr->hil_data;
284 switch ((status>>KBD_SSHIFT) & KBD_SMASK) {
285 case KBD_SHIFT:
286 c = hilkbd_shiftmap[c & KBD_CHARMASK];
287 break;
288 case KBD_CTRL:
289 c = hilkbd_ctrlmap[c & KBD_CHARMASK];
290 break;
291 case KBD_KEY:
292 c = hilkbd_keymap[c & KBD_CHARMASK];
293 break;
294 default:
295 c = 0;
296 break;
297 }
298 return c;
299 }
300 #endif /* SMALL */
301
302 void
303 hilkbd_nmi()
304 {
305 struct hil_dev *hiladdr = HILADDR;
306
307 HILWAIT(hiladdr);
308 hiladdr->hil_cmd = HIL_CNMT;
309 HILWAIT(hiladdr);
310 hiladdr->hil_cmd = HIL_CNMT;
311 HILWAIT(hiladdr);
312 }
313
314 int
315 hilkbd_init()
316 {
317 struct hil_dev *hiladdr = HILADDR;
318 struct kbdmap *km;
319 u_char lang;
320
321 /*
322 * Determine the existence of a HIL keyboard.
323 */
324 HILWAIT(hiladdr);
325 hiladdr->hil_cmd = HIL_READKBDSADR;
326 HILDATAWAIT(hiladdr);
327 lang = hiladdr->hil_data;
328 if (lang == 0)
329 return 0;
330
331 HILWAIT(hiladdr);
332 hiladdr->hil_cmd = HIL_SETARR;
333 HILWAIT(hiladdr);
334 hiladdr->hil_data = ar_format(KBD_ARR);
335 HILWAIT(hiladdr);
336 hiladdr->hil_cmd = HIL_READKBDLANG;
337 HILDATAWAIT(hiladdr);
338 lang = hiladdr->hil_data;
339 for (km = hilkbd_map; km->kbd_code; km++) {
340 if (km->kbd_code == lang) {
341 hilkbd_keymap = km->kbd_keymap;
342 hilkbd_shiftmap = km->kbd_shiftmap;
343 hilkbd_ctrlmap = km->kbd_ctrlmap;
344 }
345 }
346 HILWAIT(hiladdr);
347 hiladdr->hil_cmd = HIL_INTON;
348 return 1;
349 }
350 #endif /* ITECONSOLE && HIL_KEYBOARD */
351