vrkiu.c revision 1.1 1 1.1 takemura /* $NetBSD: vrkiu.c,v 1.1 1999/09/16 12:23:33 takemura Exp $ */
2 1.1 takemura
3 1.1 takemura /*-
4 1.1 takemura * Copyright (c) 1999 SASAKI Takesi
5 1.1 takemura * Copyright (c) 1999 PocketBSD Project. All rights reserved.
6 1.1 takemura * All rights reserved.
7 1.1 takemura *
8 1.1 takemura * This code is a part of the PocketBSD.
9 1.1 takemura *
10 1.1 takemura * Redistribution and use in source and binary forms, with or without
11 1.1 takemura * modification, are permitted provided that the following conditions
12 1.1 takemura * are met:
13 1.1 takemura * 1. Redistributions of source code must retain the above copyright
14 1.1 takemura * notice, this list of conditions and the following disclaimer.
15 1.1 takemura * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 takemura * notice, this list of conditions and the following disclaimer in the
17 1.1 takemura * documentation and/or other materials provided with the distribution.
18 1.1 takemura * 3. All advertising materials mentioning features or use of this software
19 1.1 takemura * must display the following acknowledgement:
20 1.1 takemura * This product includes software developed by the PocketBSD project
21 1.1 takemura * and its contributors.
22 1.1 takemura * 4. Neither the name of the project nor the names of its contributors
23 1.1 takemura * may be used to endorse or promote products derived from this software
24 1.1 takemura * without specific prior written permission.
25 1.1 takemura *
26 1.1 takemura * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 1.1 takemura * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.1 takemura * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.1 takemura * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 1.1 takemura * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.1 takemura * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.1 takemura * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.1 takemura * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.1 takemura * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.1 takemura * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.1 takemura * SUCH DAMAGE.
37 1.1 takemura *
38 1.1 takemura */
39 1.1 takemura
40 1.1 takemura #define VRKIUDEBUG
41 1.1 takemura
42 1.1 takemura #include <sys/param.h>
43 1.1 takemura #include <sys/tty.h>
44 1.1 takemura #include <sys/systm.h>
45 1.1 takemura #include <sys/device.h>
46 1.1 takemura #include <sys/conf.h>
47 1.1 takemura #include <sys/kernel.h>
48 1.1 takemura #include <sys/proc.h>
49 1.1 takemura
50 1.1 takemura #include <machine/intr.h>
51 1.1 takemura #include <machine/cpu.h>
52 1.1 takemura #include <machine/bus.h>
53 1.1 takemura #include <machine/platid.h>
54 1.1 takemura
55 1.1 takemura #include <hpcmips/vr/vr.h>
56 1.1 takemura #include <hpcmips/vr/vripvar.h>
57 1.1 takemura #include <hpcmips/vr/vrkiuvar.h>
58 1.1 takemura #include <hpcmips/vr/vrkiureg.h>
59 1.1 takemura #include <hpcmips/vr/icureg.h>
60 1.1 takemura
61 1.1 takemura #ifdef VRKIUDEBUG
62 1.1 takemura int vrkiu_debug = 0;
63 1.1 takemura #define DPRINTF(arg) if (vrkiu_debug) printf arg;
64 1.1 takemura #else
65 1.1 takemura #define DPRINTF(arg)
66 1.1 takemura #endif
67 1.1 takemura
68 1.1 takemura static int vrkiumatch __P((struct device *, struct cfdata *, void *));
69 1.1 takemura static void vrkiuattach __P((struct device *, struct device *, void *));
70 1.1 takemura
71 1.1 takemura static void vrkiu_write __P((struct vrkiu_softc *, int, unsigned short));
72 1.1 takemura static unsigned short vrkiu_read __P((struct vrkiu_softc *, int));
73 1.1 takemura
74 1.1 takemura int vrkiu_intr __P((void *));
75 1.1 takemura
76 1.1 takemura static void detect_key __P((struct vrkiu_softc *));
77 1.1 takemura static void process_key __P((struct vrkiu_softc *, int, int));
78 1.1 takemura
79 1.1 takemura struct cfattach vrkiu_ca = {
80 1.1 takemura sizeof(struct vrkiu_softc), vrkiumatch, vrkiuattach
81 1.1 takemura };
82 1.1 takemura
83 1.1 takemura static struct vrkiu_softc *the_vrkiu = NULL; /* XXX: kludge!! */
84 1.1 takemura
85 1.1 takemura /* XXX: This tranlation table may depend on each machine.
86 1.1 takemura Should I build it in? */
87 1.1 takemura static char keytrans[] = {
88 1.1 takemura -1, 28, 25, 52, 21, 48, 44, 57, /* - enter p . y b z space */
89 1.1 takemura -1, 53, 24, 51, 20, 47, 30, -1, /* - / o , t v a - */
90 1.1 takemura -1, -1, 23, 50, 19, 46, 17, -1, /* - - i m r c w - */
91 1.1 takemura 13, -1, 22, -1, 18, 45, 16, 2, /* = - u - e x q 1 */
92 1.1 takemura -1, -1, 11, 38, 40, 34, 15, 59, /* - - 0 l ' g tab f1 */
93 1.1 takemura -1, 39, 10, 49, 6, 33, 3, 37, /* - ; 9 n 5 f 2 k */
94 1.1 takemura -1, 27, 9, 36, 5, 32, 7, -1, /* - ] 8 j 4 d 6 - */
95 1.1 takemura 12, 26, 8, 35, 4, 41, 31, -1, /* - [ 7 h 3 ` s - */
96 1.1 takemura 58, -1, -1, -1, 14, -1, 66, 61, /* caps - - - bs - f8 f3 */
97 1.1 takemura -1, 56, -1, -1, 43, -1, 65, 62, /* - alt - - \ - f7 f4 */
98 1.1 takemura -1, -1, 29, -1, 68, -1, 64, 60, /* - - ctrl - f10 - f6 f2 */
99 1.1 takemura -1, -1, -1, 42, -1, 67, 63, 1, /* - - - shift - f9 f5 esc */
100 1.1 takemura };
101 1.1 takemura /* XXX: fill the field of funct. keys, ex. arrow, fnc, nfer... */
102 1.1 takemura
103 1.1 takemura #define SCROLL 0x0001 /* stop output */
104 1.1 takemura #define NUM 0x0002 /* numeric shift cursors vs. numeric */
105 1.1 takemura #define CAPS 0x0004 /* caps shift -- swaps case of letter */
106 1.1 takemura #define SHIFT 0x0008 /* keyboard shift */
107 1.1 takemura #define CTL 0x0010 /* control shift -- allows ctl function */
108 1.1 takemura #define ASCII 0x0020 /* ascii code for this key */
109 1.1 takemura #define ALT 0x0080 /* alternate shift -- alternate chars */
110 1.1 takemura #define FUNC 0x0100 /* function key */
111 1.1 takemura #define KP 0x0200 /* Keypad keys */
112 1.1 takemura #define NONE 0x0400 /* no function */
113 1.1 takemura
114 1.1 takemura #define CODE_SIZE 4 /* Use a max of 4 for now... */
115 1.1 takemura
116 1.1 takemura typedef struct {
117 1.1 takemura u_short type;
118 1.1 takemura char unshift[CODE_SIZE];
119 1.1 takemura char shift[CODE_SIZE];
120 1.1 takemura char ctl[CODE_SIZE];
121 1.1 takemura } Scan_def;
122 1.1 takemura
123 1.1 takemura #if !defined(PCCONS_REAL_BS)
124 1.1 takemura #define PCCONS_REAL_BS 1
125 1.1 takemura #endif
126 1.1 takemura #if !defined(CAPS_IS_CONTROL)
127 1.1 takemura #define CAPS_IS_CONTROL 1
128 1.1 takemura #endif
129 1.1 takemura #if !defined(CAPS_ADD_CONTROL)
130 1.1 takemura #define CAPS_ADD_CONTROL 0
131 1.1 takemura #endif
132 1.1 takemura
133 1.1 takemura static Scan_def scan_codes[] = {
134 1.1 takemura { NONE, "", "", "" }, /* 0 unused */
135 1.1 takemura { ASCII,"\033", "\033", "\033" }, /* 1 ESCape */
136 1.1 takemura { ASCII,"1", "!", "!" }, /* 2 1 */
137 1.1 takemura { ASCII,"2", "@", "\000" }, /* 3 2 */
138 1.1 takemura { ASCII,"3", "#", "#" }, /* 4 3 */
139 1.1 takemura { ASCII,"4", "$", "$" }, /* 5 4 */
140 1.1 takemura { ASCII,"5", "%", "%" }, /* 6 5 */
141 1.1 takemura { ASCII,"6", "^", "\036" }, /* 7 6 */
142 1.1 takemura { ASCII,"7", "&", "&" }, /* 8 7 */
143 1.1 takemura { ASCII,"8", "*", "\010" }, /* 9 8 */
144 1.1 takemura { ASCII,"9", "(", "(" }, /* 10 9 */
145 1.1 takemura { ASCII,"0", ")", ")" }, /* 11 0 */
146 1.1 takemura { ASCII,"-", "_", "\037" }, /* 12 - */
147 1.1 takemura { ASCII,"=", "+", "+" }, /* 13 = */
148 1.1 takemura #ifndef PCCONS_REAL_BS
149 1.1 takemura { ASCII,"\177", "\177", "\010" }, /* 14 backspace */
150 1.1 takemura #else
151 1.1 takemura { ASCII,"\010", "\010", "\177" }, /* 14 backspace */
152 1.1 takemura #endif
153 1.1 takemura { ASCII,"\t", "\177\t", "\t" }, /* 15 tab */
154 1.1 takemura { ASCII,"q", "Q", "\021" }, /* 16 q */
155 1.1 takemura { ASCII,"w", "W", "\027" }, /* 17 w */
156 1.1 takemura { ASCII,"e", "E", "\005" }, /* 18 e */
157 1.1 takemura { ASCII,"r", "R", "\022" }, /* 19 r */
158 1.1 takemura { ASCII,"t", "T", "\024" }, /* 20 t */
159 1.1 takemura { ASCII,"y", "Y", "\031" }, /* 21 y */
160 1.1 takemura { ASCII,"u", "U", "\025" }, /* 22 u */
161 1.1 takemura { ASCII,"i", "I", "\011" }, /* 23 i */
162 1.1 takemura { ASCII,"o", "O", "\017" }, /* 24 o */
163 1.1 takemura { ASCII,"p", "P", "\020" }, /* 25 p */
164 1.1 takemura { ASCII,"[", "{", "\033" }, /* 26 [ */
165 1.1 takemura { ASCII,"]", "}", "\035" }, /* 27 ] */
166 1.1 takemura { ASCII,"\r", "\r", "\n" }, /* 28 return */
167 1.1 takemura #if CAPS_IS_CONTROL == 1 && CAPS_ADD_CONTROL == 0
168 1.1 takemura { CAPS, "", "", "" }, /* 29 caps */
169 1.1 takemura #else
170 1.1 takemura { CTL, "", "", "" }, /* 29 control */
171 1.1 takemura #endif
172 1.1 takemura { ASCII,"a", "A", "\001" }, /* 30 a */
173 1.1 takemura { ASCII,"s", "S", "\023" }, /* 31 s */
174 1.1 takemura { ASCII,"d", "D", "\004" }, /* 32 d */
175 1.1 takemura { ASCII,"f", "F", "\006" }, /* 33 f */
176 1.1 takemura { ASCII,"g", "G", "\007" }, /* 34 g */
177 1.1 takemura { ASCII,"h", "H", "\010" }, /* 35 h */
178 1.1 takemura { ASCII,"j", "J", "\n" }, /* 36 j */
179 1.1 takemura { ASCII,"k", "K", "\013" }, /* 37 k */
180 1.1 takemura { ASCII,"l", "L", "\014" }, /* 38 l */
181 1.1 takemura { ASCII,";", ":", ";" }, /* 39 ; */
182 1.1 takemura { ASCII,"'", "\"", "'" }, /* 40 ' */
183 1.1 takemura { ASCII,"`", "~", "`" }, /* 41 ` */
184 1.1 takemura { SHIFT,"", "", "" }, /* 42 shift */
185 1.1 takemura { ASCII,"\\", "|", "\034" }, /* 43 \ */
186 1.1 takemura { ASCII,"z", "Z", "\032" }, /* 44 z */
187 1.1 takemura { ASCII,"x", "X", "\030" }, /* 45 x */
188 1.1 takemura { ASCII,"c", "C", "\003" }, /* 46 c */
189 1.1 takemura { ASCII,"v", "V", "\026" }, /* 47 v */
190 1.1 takemura { ASCII,"b", "B", "\002" }, /* 48 b */
191 1.1 takemura { ASCII,"n", "N", "\016" }, /* 49 n */
192 1.1 takemura { ASCII,"m", "M", "\r" }, /* 50 m */
193 1.1 takemura { ASCII,",", "<", "<" }, /* 51 , */
194 1.1 takemura { ASCII,".", ">", ">" }, /* 52 . */
195 1.1 takemura { ASCII,"/", "?", "\037" }, /* 53 / */
196 1.1 takemura { SHIFT,"", "", "" }, /* 54 shift */
197 1.1 takemura { KP, "*", "*", "*" }, /* 55 kp * */
198 1.1 takemura { ALT, "", "", "" }, /* 56 alt */
199 1.1 takemura { ASCII," ", " ", "\000" }, /* 57 space */
200 1.1 takemura #if CAPS_IS_CONTROL == 1 || CAPS_ADD_CONTROL == 1
201 1.1 takemura { CTL, "", "", "" }, /* 58 control */
202 1.1 takemura #else
203 1.1 takemura { CAPS, "", "", "" }, /* 58 caps */
204 1.1 takemura #endif
205 1.1 takemura { FUNC, "\033[M", "\033[Y", "\033[k" }, /* 59 f1 */
206 1.1 takemura { FUNC, "\033[N", "\033[Z", "\033[l" }, /* 60 f2 */
207 1.1 takemura { FUNC, "\033[O", "\033[a", "\033[m" }, /* 61 f3 */
208 1.1 takemura { FUNC, "\033[P", "\033[b", "\033[n" }, /* 62 f4 */
209 1.1 takemura { FUNC, "\033[Q", "\033[c", "\033[o" }, /* 63 f5 */
210 1.1 takemura { FUNC, "\033[R", "\033[d", "\033[p" }, /* 64 f6 */
211 1.1 takemura { FUNC, "\033[S", "\033[e", "\033[q" }, /* 65 f7 */
212 1.1 takemura { FUNC, "\033[T", "\033[f", "\033[r" }, /* 66 f8 */
213 1.1 takemura { FUNC, "\033[U", "\033[g", "\033[s" }, /* 67 f9 */
214 1.1 takemura { FUNC, "\033[V", "\033[h", "\033[t" }, /* 68 f10 */
215 1.1 takemura { NUM, "", "", "" }, /* 69 num lock */
216 1.1 takemura { SCROLL,"", "", "" }, /* 70 scroll lock */
217 1.1 takemura { KP, "7", "\033[H", "7" }, /* 71 kp 7 */
218 1.1 takemura { KP, "8", "\033[A", "8" }, /* 72 kp 8 */
219 1.1 takemura { KP, "9", "\033[I", "9" }, /* 73 kp 9 */
220 1.1 takemura { KP, "-", "-", "-" }, /* 74 kp - */
221 1.1 takemura { KP, "4", "\033[D", "4" }, /* 75 kp 4 */
222 1.1 takemura { KP, "5", "\033[E", "5" }, /* 76 kp 5 */
223 1.1 takemura { KP, "6", "\033[C", "6" }, /* 77 kp 6 */
224 1.1 takemura { KP, "+", "+", "+" }, /* 78 kp + */
225 1.1 takemura { KP, "1", "\033[F", "1" }, /* 79 kp 1 */
226 1.1 takemura { KP, "2", "\033[B", "2" }, /* 80 kp 2 */
227 1.1 takemura { KP, "3", "\033[G", "3" }, /* 81 kp 3 */
228 1.1 takemura { KP, "0", "\033[L", "0" }, /* 82 kp 0 */
229 1.1 takemura { KP, ".", "\177", "." }, /* 83 kp . */
230 1.1 takemura { NONE, "", "", "" }, /* 84 0 */
231 1.1 takemura { NONE, "100", "", "" }, /* 85 0 */
232 1.1 takemura { NONE, "101", "", "" }, /* 86 0 */
233 1.1 takemura { FUNC, "\033[W", "\033[i", "\033[u" }, /* 87 f11 */
234 1.1 takemura { FUNC, "\033[X", "\033[j", "\033[v" }, /* 88 f12 */
235 1.1 takemura { NONE, "102", "", "" }, /* 89 0 */
236 1.1 takemura { NONE, "103", "", "" }, /* 90 0 */
237 1.1 takemura { NONE, "", "", "" }, /* 91 0 */
238 1.1 takemura { ASCII,"\177", "\177", "\010" }, /* 92 del */
239 1.1 takemura { NONE, "", "", "" }, /* 93 0 */
240 1.1 takemura { NONE, "", "", "" }, /* 94 0 */
241 1.1 takemura { NONE, "", "", "" }, /* 95 0 */
242 1.1 takemura { NONE, "", "", "" }, /* 96 0 */
243 1.1 takemura { NONE, "", "", "" }, /* 97 0 */
244 1.1 takemura { NONE, "", "", "" }, /* 98 0 */
245 1.1 takemura { NONE, "", "", "" }, /* 99 0 */
246 1.1 takemura { NONE, "", "", "" }, /* 100 */
247 1.1 takemura { NONE, "", "", "" }, /* 101 */
248 1.1 takemura { NONE, "", "", "" }, /* 102 */
249 1.1 takemura { NONE, "", "", "" }, /* 103 */
250 1.1 takemura { NONE, "", "", "" }, /* 104 */
251 1.1 takemura { NONE, "", "", "" }, /* 105 */
252 1.1 takemura { NONE, "", "", "" }, /* 106 */
253 1.1 takemura { NONE, "", "", "" }, /* 107 */
254 1.1 takemura { NONE, "", "", "" }, /* 108 */
255 1.1 takemura { NONE, "", "", "" }, /* 109 */
256 1.1 takemura { NONE, "", "", "" }, /* 110 */
257 1.1 takemura { NONE, "", "", "" }, /* 111 */
258 1.1 takemura { NONE, "", "", "" }, /* 112 */
259 1.1 takemura { NONE, "", "", "" }, /* 113 */
260 1.1 takemura { NONE, "", "", "" }, /* 114 */
261 1.1 takemura { NONE, "", "", "" }, /* 115 */
262 1.1 takemura { NONE, "", "", "" }, /* 116 */
263 1.1 takemura { NONE, "", "", "" }, /* 117 */
264 1.1 takemura { NONE, "", "", "" }, /* 118 */
265 1.1 takemura { NONE, "", "", "" }, /* 119 */
266 1.1 takemura { NONE, "", "", "" }, /* 120 */
267 1.1 takemura { NONE, "", "", "" }, /* 121 */
268 1.1 takemura { NONE, "", "", "" }, /* 122 */
269 1.1 takemura { NONE, "", "", "" }, /* 123 */
270 1.1 takemura { NONE, "", "", "" }, /* 124 */
271 1.1 takemura { NONE, "", "", "" }, /* 125 */
272 1.1 takemura { NONE, "", "", "" }, /* 126 */
273 1.1 takemura { NONE, "", "", "" }, /* 127 */
274 1.1 takemura };
275 1.1 takemura
276 1.1 takemura /* XXX: Make these queue obsolute, or move these into vrkiu_softc */
277 1.1 takemura static int
278 1.1 takemura vrkiumatch(parent, cf, aux)
279 1.1 takemura struct device *parent;
280 1.1 takemura struct cfdata *cf;
281 1.1 takemura void *aux;
282 1.1 takemura {
283 1.1 takemura return 1; /* XXX */
284 1.1 takemura }
285 1.1 takemura
286 1.1 takemura static inline void
287 1.1 takemura vrkiu_write(sc, port, val)
288 1.1 takemura struct vrkiu_softc *sc;
289 1.1 takemura int port;
290 1.1 takemura unsigned short val;
291 1.1 takemura {
292 1.1 takemura bus_space_write_2(sc->sc_iot, sc->sc_ioh, port, val);
293 1.1 takemura }
294 1.1 takemura
295 1.1 takemura static inline unsigned short
296 1.1 takemura vrkiu_read(sc, port)
297 1.1 takemura struct vrkiu_softc *sc;
298 1.1 takemura int port;
299 1.1 takemura {
300 1.1 takemura return bus_space_read_2(sc->sc_iot, sc->sc_ioh, port);
301 1.1 takemura }
302 1.1 takemura
303 1.1 takemura static void
304 1.1 takemura vrkiuattach(parent, self, aux)
305 1.1 takemura struct device *parent;
306 1.1 takemura struct device *self;
307 1.1 takemura void *aux;
308 1.1 takemura {
309 1.1 takemura struct vrkiu_softc *sc = (struct vrkiu_softc *)self;
310 1.1 takemura struct vrip_attach_args *va = aux;
311 1.1 takemura
312 1.1 takemura bus_space_tag_t iot = va->va_iot;
313 1.1 takemura bus_space_handle_t ioh;
314 1.1 takemura
315 1.1 takemura if (bus_space_map(iot, va->va_addr, 1, 0, &ioh)) {
316 1.1 takemura printf(": can't map bus space\n");
317 1.1 takemura return;
318 1.1 takemura }
319 1.1 takemura
320 1.1 takemura sc->sc_iot = iot;
321 1.1 takemura sc->sc_ioh = ioh;
322 1.1 takemura
323 1.1 takemura /* set KIU */
324 1.1 takemura vrkiu_write(sc, KIURST, 1); /* reset */
325 1.1 takemura vrkiu_write(sc, KIUSCANLINE, 0); /* 96keys */
326 1.1 takemura vrkiu_write(sc, KIUWKS, 0x18a4); /* XXX: scan timing! */
327 1.1 takemura vrkiu_write(sc, KIUWKI, 450);
328 1.1 takemura vrkiu_write(sc, KIUSCANREP, 0x8023);
329 1.1 takemura /* KEYEN | STPREP = 2 | ATSTP | ATSCAN */
330 1.1 takemura
331 1.1 takemura the_vrkiu = sc;
332 1.1 takemura
333 1.1 takemura if (!(sc->sc_handler =
334 1.1 takemura vrip_intr_establish(va->va_vc, va->va_intr, IPL_TTY,
335 1.1 takemura vrkiu_intr, sc))) {
336 1.1 takemura printf (": can't map interrupt line.\n");
337 1.1 takemura return;
338 1.1 takemura }
339 1.1 takemura /* Level2 register setting */
340 1.1 takemura vrip_intr_setmask2(va->va_vc, sc->sc_handler, KIUINT_KDATRDY, 1);
341 1.1 takemura
342 1.1 takemura printf("\n");
343 1.1 takemura }
344 1.1 takemura
345 1.1 takemura int
346 1.1 takemura vrkiu_intr(arg)
347 1.1 takemura void *arg;
348 1.1 takemura {
349 1.1 takemura struct vrkiu_softc *sc = arg;
350 1.1 takemura /* When key scan finisshed, this entry is called. */
351 1.1 takemura detect_key(sc);
352 1.1 takemura DPRINTF(("%d", vrkiu_read(sc, KIUINT) & 7));
353 1.1 takemura
354 1.1 takemura vrkiu_write(sc, KIUINT, 0x7); /* Clear all interrupt */
355 1.1 takemura
356 1.1 takemura return 0;
357 1.1 takemura }
358 1.1 takemura
359 1.1 takemura static void
360 1.1 takemura detect_key(sc)
361 1.1 takemura struct vrkiu_softc *sc;
362 1.1 takemura {
363 1.1 takemura int i, k;
364 1.1 takemura
365 1.1 takemura DPRINTF(("[detect_key():begin read]"));
366 1.1 takemura
367 1.1 takemura for (i = 0; i < KIU_NSCANLINE / 2; i++) {
368 1.1 takemura k = vrkiu_read(sc, KIUDATP + i * 2) ^ sc->keystat[i];
369 1.1 takemura sc->keystat[i] = vrkiu_read(sc, KIUDATP + i * 2);
370 1.1 takemura while (k) {
371 1.1 takemura int n, m;
372 1.1 takemura n = ffs(k) - 1;
373 1.1 takemura if (n < 0) {
374 1.1 takemura break;
375 1.1 takemura }
376 1.1 takemura k ^= 1 << n;
377 1.1 takemura m = n + i * 16;
378 1.1 takemura if (keytrans[m] < 0) {
379 1.1 takemura printf("vrkiu: Unkown scan code 0x%02x\n", m);
380 1.1 takemura continue;
381 1.1 takemura }
382 1.1 takemura /* XXX: scanbuf may overflow! */
383 1.1 takemura process_key(sc, keytrans[m],
384 1.1 takemura !((sc->keystat[i] & (1 << n))));
385 1.1 takemura }
386 1.1 takemura /* XXX: The order of keys can be a problem.
387 1.1 takemura If CTRL and normal key are pushed simultaneously,
388 1.1 takemura normal key can be entered in queue first.
389 1.1 takemura Same problem would occur in key break. */
390 1.1 takemura }
391 1.1 takemura /* TODO: Enter scancode into the queue as long as the key pressed */
392 1.1 takemura
393 1.1 takemura }
394 1.1 takemura
395 1.1 takemura static void
396 1.1 takemura process_key(sc, k, brk)
397 1.1 takemura struct vrkiu_softc *sc;
398 1.1 takemura int k, brk;
399 1.1 takemura {
400 1.1 takemura char *p;
401 1.1 takemura extern struct tty biconsdev_tty[];
402 1.1 takemura
403 1.1 takemura switch (scan_codes[k].type) {
404 1.1 takemura case ALT:
405 1.1 takemura sc->k_alt = brk ? 0 : 1;
406 1.1 takemura break;
407 1.1 takemura case SHIFT:
408 1.1 takemura sc->k_sft = brk ? 0 : 1;
409 1.1 takemura break;
410 1.1 takemura case CTL:
411 1.1 takemura sc->k_ctrl = brk ? 0 : 1;
412 1.1 takemura break;
413 1.1 takemura case ASCII:
414 1.1 takemura if (!brk) {
415 1.1 takemura if (sc->k_ctrl) {
416 1.1 takemura p = scan_codes[k].ctl;
417 1.1 takemura } else if (sc->k_sft) {
418 1.1 takemura p = scan_codes[k].shift;
419 1.1 takemura } else {
420 1.1 takemura p = scan_codes[k].unshift;
421 1.1 takemura }
422 1.1 takemura sc->keybuf[sc->keybufhead++] =
423 1.1 takemura sc->k_alt ? (*p | 0x80) : *p;
424 1.1 takemura /* XXX: multi byte key! */
425 1.1 takemura if (sc->keybufhead >= NKEYBUF) {
426 1.1 takemura sc->keybufhead = 0;
427 1.1 takemura }
428 1.1 takemura (*linesw[0].l_rint)(sc->k_alt ? (*p | 0x80) : *p,
429 1.1 takemura &biconsdev_tty [0]);
430 1.1 takemura }
431 1.1 takemura break;
432 1.1 takemura default:
433 1.1 takemura /* Ignored */
434 1.1 takemura }
435 1.1 takemura }
436 1.1 takemura
437 1.1 takemura /* called from biconsdev.c */
438 1.1 takemura int
439 1.1 takemura vrkiu_getc()
440 1.1 takemura {
441 1.1 takemura int ret;
442 1.1 takemura
443 1.1 takemura if (the_vrkiu == NULL) {
444 1.1 takemura return 0; /* XXX */
445 1.1 takemura }
446 1.1 takemura
447 1.1 takemura while (the_vrkiu->keybuftail == the_vrkiu->keybufhead) {
448 1.1 takemura detect_key(the_vrkiu);
449 1.1 takemura }
450 1.1 takemura ret = the_vrkiu->keybuf[the_vrkiu->keybuftail++];
451 1.1 takemura if (the_vrkiu->keybuftail >= NKEYBUF) {
452 1.1 takemura the_vrkiu->keybuftail = 0;
453 1.1 takemura }
454 1.1 takemura return ret;
455 1.1 takemura }
456 1.1 takemura
457