xref: /csrg-svn/sys/news3400/bm/kb_ctrl.c (revision 53889)
1*53889Smckusick /*
2*53889Smckusick  * Copyright (c) 1992 The Regents of the University of California.
3*53889Smckusick  * All rights reserved.
4*53889Smckusick  *
5*53889Smckusick  * This code is derived from software contributed to Berkeley by
6*53889Smckusick  * Sony Corp. and Kazumasa Utashiro of Software Research Associates, Inc.
7*53889Smckusick  *
8*53889Smckusick  * %sccs.include.redist.c%
9*53889Smckusick  *
10*53889Smckusick  * from: $Hdr: kb_ctrl.c,v 4.300 91/06/09 06:14:49 root Rel41 $ SONY
11*53889Smckusick  *
12*53889Smckusick  *	@(#)kb_ctrl.c	7.1 (Berkeley) 06/04/92
13*53889Smckusick  */
14*53889Smckusick 
15*53889Smckusick /*
16*53889Smckusick  *	Keyboard driver
17*53889Smckusick  */
18*53889Smckusick 
19*53889Smckusick #include "../include/fix_machine_type.h"
20*53889Smckusick 
21*53889Smckusick #ifdef IPC_MRX
22*53889Smckusick #include "../../h/ioctl.h"
23*53889Smckusick #include "../../iop/keyboard.h"
24*53889Smckusick #include "../../iop/kbreg.h"
25*53889Smckusick #else
26*53889Smckusick #include "ioctl.h"
27*53889Smckusick #include "param.h"
28*53889Smckusick #include "systm.h"
29*53889Smckusick #include "types.h"
30*53889Smckusick #include "../iop/keyboard.h"
31*53889Smckusick #include "../iop/kbreg.h"
32*53889Smckusick #endif
33*53889Smckusick 
34*53889Smckusick extern int tmode;
35*53889Smckusick extern int kbd_status;
36*53889Smckusick 
37*53889Smckusick int iscaps = 0;
38*53889Smckusick int change_country = K_JAPANESE_J;
39*53889Smckusick int country;
40*53889Smckusick 
41*53889Smckusick extern Key_table default_table[];
42*53889Smckusick 
43*53889Smckusick #ifdef CPU_SINGLE
44*53889Smckusick extern Key_table key_table[];
45*53889Smckusick Key_table *key_table_addr = key_table;
46*53889Smckusick #endif
47*53889Smckusick 
48*53889Smckusick #ifdef CPU_DOUBLE
49*53889Smckusick Key_table *key_table_addr = default_table;
50*53889Smckusick #endif
51*53889Smckusick 
52*53889Smckusick #ifdef CPU_SINGLE
53*53889Smckusick #include "ms.h"
54*53889Smckusick #include "clist.h"
55*53889Smckusick #include "ttydev.h"
56*53889Smckusick #include "tty.h"
57*53889Smckusick #include "../sio/scc.h"
58*53889Smckusick #include "time.h"
59*53889Smckusick #include "../iop/mouse.h"
60*53889Smckusick 
61*53889Smckusick extern int cnrint();
62*53889Smckusick 
63*53889Smckusick kbd_open(chan)
64*53889Smckusick 	int chan;
65*53889Smckusick {
66*53889Smckusick 	register int i;
67*53889Smckusick 
68*53889Smckusick #ifdef news700
69*53889Smckusick 	scc_open(chan);
70*53889Smckusick #endif
71*53889Smckusick #if defined(news1700) || defined(news1200) || defined(news3400)
72*53889Smckusick 	kbm_open(chan);
73*53889Smckusick #endif
74*53889Smckusick 	return (0);
75*53889Smckusick }
76*53889Smckusick 
77*53889Smckusick kbd_read(chan, buf, n)
78*53889Smckusick 	int chan;
79*53889Smckusick 	char *buf;
80*53889Smckusick 	int n;
81*53889Smckusick {
82*53889Smckusick #ifdef news700
83*53889Smckusick 	register int i;
84*53889Smckusick 
85*53889Smckusick 	for (i = n; i > 0; i--)
86*53889Smckusick 		*buf++ = scc_getc(chan);
87*53889Smckusick 	return (n);
88*53889Smckusick #endif
89*53889Smckusick #if defined(news1700) || defined(news1200)
90*53889Smckusick 
91*53889Smckusick 	return (kbd_read_raw(chan, buf, n));
92*53889Smckusick #endif
93*53889Smckusick }
94*53889Smckusick 
95*53889Smckusick kbd_write(chan, buf, n)
96*53889Smckusick 	int chan;
97*53889Smckusick 	char *buf;
98*53889Smckusick 	int n;
99*53889Smckusick {
100*53889Smckusick #ifdef news700
101*53889Smckusick 	register int i;
102*53889Smckusick 
103*53889Smckusick 	for (i = 0; i < n; i++) {
104*53889Smckusick 		scc_putc(SCC_KEYBOARD, *buf++);
105*53889Smckusick #ifndef NO_PRE_EMPT
106*53889Smckusick 		if (i % 4 == 0) PRE_EMPT;
107*53889Smckusick #endif
108*53889Smckusick 	}
109*53889Smckusick 	return (n);
110*53889Smckusick #endif /* news700 */
111*53889Smckusick #if defined(news1700) || defined(news1200) || defined(news3400)
112*53889Smckusick 
113*53889Smckusick 	return (kbm_write(SCC_KEYBOARD, buf, n));
114*53889Smckusick #endif
115*53889Smckusick }
116*53889Smckusick 
117*53889Smckusick kbd_back(buf, len)
118*53889Smckusick 	register char *buf;
119*53889Smckusick 	register int len;
120*53889Smckusick {
121*53889Smckusick 	int s;
122*53889Smckusick 
123*53889Smckusick 	while (--len >= 0) {
124*53889Smckusick 		s = spltty();
125*53889Smckusick 		cnrint(*buf++);
126*53889Smckusick 		(void) splx(s);
127*53889Smckusick 	}
128*53889Smckusick 	return (0);
129*53889Smckusick }
130*53889Smckusick 
131*53889Smckusick #define	KBPRI	(PZERO+1)
132*53889Smckusick 
133*53889Smckusick struct clist scode_buf;
134*53889Smckusick struct clist keyboard_buf;
135*53889Smckusick char	kb_rwait;
136*53889Smckusick 
137*53889Smckusick kbd_flush()
138*53889Smckusick {
139*53889Smckusick 
140*53889Smckusick 	ndflush(&scode_buf, scode_buf.c_cc);
141*53889Smckusick 	return (0);
142*53889Smckusick }
143*53889Smckusick 
144*53889Smckusick static
145*53889Smckusick kbd_put_raw(scode)
146*53889Smckusick 	int scode;
147*53889Smckusick {
148*53889Smckusick 	extern char kb_busy;
149*53889Smckusick 
150*53889Smckusick 	if (kb_busy) {
151*53889Smckusick 		if (scode_buf.c_cc < CBSIZE)
152*53889Smckusick 			putc(scode, &scode_buf);
153*53889Smckusick 		if (kb_rwait) {
154*53889Smckusick 			kb_rwait = 0;
155*53889Smckusick 			wakeup((caddr_t)&kb_rwait);
156*53889Smckusick 		}
157*53889Smckusick 	}
158*53889Smckusick 	return (scode);
159*53889Smckusick 
160*53889Smckusick }
161*53889Smckusick 
162*53889Smckusick kbd_read_raw(chan, buf, count)
163*53889Smckusick 	int chan;
164*53889Smckusick 	char *buf;
165*53889Smckusick 	register int count;
166*53889Smckusick {
167*53889Smckusick 	register int i;
168*53889Smckusick 	register int n;
169*53889Smckusick 	register int s;
170*53889Smckusick 
171*53889Smckusick 	if (count <= 0)
172*53889Smckusick 		return (count);
173*53889Smckusick 	s = splscc();
174*53889Smckusick 	while ((n = min(scode_buf.c_cc, count)) == 0) {
175*53889Smckusick 		kb_rwait = 1;
176*53889Smckusick 		sleep((caddr_t)&kb_rwait, KBPRI);
177*53889Smckusick 		kb_rwait = 0;
178*53889Smckusick 	}
179*53889Smckusick 	(void) splx(s);
180*53889Smckusick 	for (i = n; i > 0 ; i--)
181*53889Smckusick 		*buf++ = getc(&scode_buf);
182*53889Smckusick 	return (n);
183*53889Smckusick }
184*53889Smckusick 
185*53889Smckusick kbd_nread()
186*53889Smckusick {
187*53889Smckusick 
188*53889Smckusick 	return (scode_buf.c_cc);
189*53889Smckusick }
190*53889Smckusick 
191*53889Smckusick kbd_bell(n)
192*53889Smckusick 	register int n;
193*53889Smckusick {
194*53889Smckusick 
195*53889Smckusick #if defined(news1700) || defined(news1200) || defined(news3400)
196*53889Smckusick 	(void) kbm_write(SCC_KEYBOARD, NULL, n);
197*53889Smckusick #endif
198*53889Smckusick #ifdef news700
199*53889Smckusick 	kbd_bell_scc(n);
200*53889Smckusick #endif
201*53889Smckusick 	return (0);
202*53889Smckusick }
203*53889Smckusick 
204*53889Smckusick kbd_putcode(code)
205*53889Smckusick 	int code;
206*53889Smckusick {
207*53889Smckusick 	int c;
208*53889Smckusick 
209*53889Smckusick 	kbd_put_raw(code);
210*53889Smckusick 	kbd_encode(code);
211*53889Smckusick 	while ((c = getc(&keyboard_buf)) != -1)
212*53889Smckusick 		cnrint(c);
213*53889Smckusick }
214*53889Smckusick 
215*53889Smckusick put_code(buf, cnt)
216*53889Smckusick 	register char *buf;
217*53889Smckusick 	register int cnt;
218*53889Smckusick {
219*53889Smckusick 
220*53889Smckusick 	while (--cnt >= 0)
221*53889Smckusick 		putc(*buf++, &keyboard_buf);
222*53889Smckusick }
223*53889Smckusick 
224*53889Smckusick kb_softint()
225*53889Smckusick {
226*53889Smckusick 	int code;
227*53889Smckusick 	extern int tty00_is_console;
228*53889Smckusick 
229*53889Smckusick 	while ((code = xgetc(SCC_KEYBOARD)) >= 0) {
230*53889Smckusick #if defined(news1200) || defined(news3200)		/* BEGIN reiko */
231*53889Smckusick 		if ((code & 0x7f) == KEY_EISUU) {
232*53889Smckusick 			int up = code & OFF;
233*53889Smckusick 			static int kana = 0;
234*53889Smckusick 
235*53889Smckusick 			if (kana) {
236*53889Smckusick 				if (up) {
237*53889Smckusick 					kana = 0;
238*53889Smckusick 				}
239*53889Smckusick 			} else {
240*53889Smckusick 				if (up) {
241*53889Smckusick 					code = KEY_KANA | OFF;
242*53889Smckusick 					kana = 1;
243*53889Smckusick 				} else {
244*53889Smckusick 					code = KEY_KANA;
245*53889Smckusick 				}
246*53889Smckusick 			}
247*53889Smckusick 		}
248*53889Smckusick #endif
249*53889Smckusick 
250*53889Smckusick #ifdef NOTDEF /* KU:XXX */
251*53889Smckusick 		if (!tty00_is_console)
252*53889Smckusick #endif
253*53889Smckusick 			rst_dimmer_cnt();
254*53889Smckusick #if NMS > 0
255*53889Smckusick 		if (!mskeytrigger(0, code & OFF, code & 0x7f))
256*53889Smckusick #endif
257*53889Smckusick 		kbd_putcode(code);
258*53889Smckusick 	}
259*53889Smckusick }
260*53889Smckusick #endif /* CPU_SINGLE */
261*53889Smckusick 
262*53889Smckusick #ifdef IPC_MRX
263*53889Smckusick #include "mrx.h"
264*53889Smckusick #include "queue.h"
265*53889Smckusick #include "process.h"
266*53889Smckusick #include "buffer.h"
267*53889Smckusick #include "port.h"
268*53889Smckusick #include "message.h"
269*53889Smckusick #include "machdep.h"
270*53889Smckusick #include "malloc.h"
271*53889Smckusick #include "config.h"
272*53889Smckusick #include "kbms.h"
273*53889Smckusick 
274*53889Smckusick #ifdef news1800
275*53889Smckusick #include "scc.h"
276*53889Smckusick #endif
277*53889Smckusick 
278*53889Smckusick static struct buffer *kbd_buf;
279*53889Smckusick static int port_kbd_intr;
280*53889Smckusick static int port_kbd_back;
281*53889Smckusick static int port_kbd_ctrl;
282*53889Smckusick 
283*53889Smckusick keyboard(chan)
284*53889Smckusick 	int chan;
285*53889Smckusick {
286*53889Smckusick 	int kbd_ctrl(), kbd_output();
287*53889Smckusick 	int kbd_read(), kbd_ioctl(), kbd_io();
288*53889Smckusick 
289*53889Smckusick #ifdef news3800
290*53889Smckusick 	extern int (*Xkb_intr)();
291*53889Smckusick 	int kb_intr();
292*53889Smckusick 
293*53889Smckusick 	Xkb_intr = kb_intr;
294*53889Smckusick #endif
295*53889Smckusick 
296*53889Smckusick #ifdef news1800
297*53889Smckusick 	int scc_input(), scc_output();
298*53889Smckusick 
299*53889Smckusick 	if (scc_open(SCC_KEYBOARD) < 0)
300*53889Smckusick 		return;
301*53889Smckusick 	proc_create("scc_kbread", scc_input, 601, 512, SCC_KEYBOARD);
302*53889Smckusick 	proc_create("scc_kbwrite", scc_output, 601, 512, SCC_KEYBOARD);
303*53889Smckusick 	while (scc_std_ports[SCC_KEYBOARD][0] == 0)
304*53889Smckusick 		proc_sleep_self(100);
305*53889Smckusick #endif
306*53889Smckusick 	kb_ioctl = kbd_ioctl;
307*53889Smckusick 	kb_read = kbd_read;
308*53889Smckusick 	kbd_init();
309*53889Smckusick 	proc_create("kbd_ctrl", kbd_ctrl, 300, DEFAULT_STACK_SIZE, 0);
310*53889Smckusick 	proc_create("kbd_output", kbd_output, 300, DEFAULT_STACK_SIZE, 0);
311*53889Smckusick 	proc_create("kbd_io", kbd_io, 300, DEFAULT_STACK_SIZE, 0);
312*53889Smckusick }
313*53889Smckusick 
314*53889Smckusick int (*reset_dimmer)();
315*53889Smckusick 
316*53889Smckusick kbd_ctrl()
317*53889Smckusick {
318*53889Smckusick 	register int m, n;
319*53889Smckusick 	register int select;
320*53889Smckusick 	int *len, from, count;
321*53889Smckusick 	char *addr;
322*53889Smckusick 	int ports[3];
323*53889Smckusick 	static char buf[16];
324*53889Smckusick 
325*53889Smckusick 	ports[0] = port_kbd_intr = port_create("kb_intr");
326*53889Smckusick 	ports[1] = port_kbd_back = port_create("kb_echoback");
327*53889Smckusick 	ports[2] = port_kbd_ctrl = STDPORT;
328*53889Smckusick 
329*53889Smckusick #ifdef news3800
330*53889Smckusick 	*(char *)KEYBD_RESET = 0;
331*53889Smckusick 	*(char *)KEYBD_INTE = 1;
332*53889Smckusick #endif
333*53889Smckusick #ifdef news1800
334*53889Smckusick 	count = 1;
335*53889Smckusick 	msg_send(scc_std_ports[SCC_KEYBOARD][0], ports[0],
336*53889Smckusick 		&count, sizeof (count), 0);
337*53889Smckusick #endif
338*53889Smckusick 
339*53889Smckusick 	kbd_buf = buffer_alloc(32);
340*53889Smckusick 	(void) spl0();
341*53889Smckusick 	for (;;) {
342*53889Smckusick 		if (buffer_status(kbd_buf) > 0)
343*53889Smckusick 			m = 3;
344*53889Smckusick 		else
345*53889Smckusick 			m = 2;
346*53889Smckusick 		if ((select = msg_select(m, ports)) == 0) {
347*53889Smckusick 			msg_recv(ports[0], NULL, &addr, &count, 0);
348*53889Smckusick 			if (reset_dimmer)
349*53889Smckusick 				(*reset_dimmer)();
350*53889Smckusick 			while (--count >= 0) {
351*53889Smckusick 				if (send_mouse == 0 || (*send_mouse)(*addr) == 0)
352*53889Smckusick 					kbd_encode(*addr);
353*53889Smckusick 				addr++;
354*53889Smckusick 			}
355*53889Smckusick #ifdef news1800
356*53889Smckusick 			count = 1;
357*53889Smckusick 			msg_send(scc_std_ports[SCC_KEYBOARD][0], ports[select],
358*53889Smckusick 			    &count, sizeof (count), 0);
359*53889Smckusick #endif
360*53889Smckusick 		} else if (select == 1) {	/* ESC [ 6 n */
361*53889Smckusick 			msg_recv(ports[select], NULL, &addr, &count, 0);
362*53889Smckusick 			put(kbd_buf, addr, count);
363*53889Smckusick 		} else {
364*53889Smckusick 			msg_recv(ports[select], &from, &len, NULL, 0);
365*53889Smckusick 			n = buffer_status(kbd_buf);
366*53889Smckusick 			n = min(n, *len);
367*53889Smckusick 			n = get(kbd_buf, buf, min(n, sizeof (buf)));
368*53889Smckusick 			msg_send(from, ports[select], buf, n, 0);
369*53889Smckusick 		}
370*53889Smckusick 	}
371*53889Smckusick }
372*53889Smckusick 
373*53889Smckusick kbd_output()
374*53889Smckusick {
375*53889Smckusick 	char *addr;
376*53889Smckusick 	int from, len;
377*53889Smckusick #ifdef news1800
378*53889Smckusick 	register int subport;
379*53889Smckusick 
380*53889Smckusick 	subport = port_create("port_kbd_write");
381*53889Smckusick #endif
382*53889Smckusick 
383*53889Smckusick 	(void) spl0();
384*53889Smckusick 	for (;;) {
385*53889Smckusick 		msg_recv(STDPORT, &from, &addr, &len, 0);
386*53889Smckusick #ifdef news3800
387*53889Smckusick 		len = kbd_write(0, addr, len);
388*53889Smckusick #endif
389*53889Smckusick #ifdef news1800
390*53889Smckusick 		len = kbd_write(subport, addr, len);
391*53889Smckusick #endif
392*53889Smckusick 		msg_send(from, STDPORT, &len, sizeof(len), 0);
393*53889Smckusick 	}
394*53889Smckusick }
395*53889Smckusick 
396*53889Smckusick kbd_io()
397*53889Smckusick {
398*53889Smckusick 	struct kb_ctrl_req *req;
399*53889Smckusick 	int from, reply;
400*53889Smckusick #ifdef news1800
401*53889Smckusick 	register int sub_port;
402*53889Smckusick 
403*53889Smckusick 	sub_port = port_create("port_kbd_sub");
404*53889Smckusick #endif
405*53889Smckusick 
406*53889Smckusick 	(void) spl0();
407*53889Smckusick 	for (;;) {
408*53889Smckusick 		msg_recv(STDPORT, &from, &req, NULL, 0);
409*53889Smckusick 		if (req->kb_func == KIOCCHTBL || req->kb_func == KIOCOYATBL)
410*53889Smckusick 			kbd_ioctl(0, req->kb_func, req->kb_arg);
411*53889Smckusick 		else
412*53889Smckusick #ifdef news1800
413*53889Smckusick 			kbd_ioctl(sub_port, req->kb_func, &req->kb_arg);
414*53889Smckusick #else
415*53889Smckusick 			kbd_ioctl(0, req->kb_func, &req->kb_arg);
416*53889Smckusick #endif
417*53889Smckusick 		reply = req->kb_arg;
418*53889Smckusick 		msg_send(from, STDPORT, &reply, sizeof(reply), 0);
419*53889Smckusick 	}
420*53889Smckusick }
421*53889Smckusick 
422*53889Smckusick kbd_read(chan, buf, n)
423*53889Smckusick 	int chan;
424*53889Smckusick 	char *buf;
425*53889Smckusick 	int n;
426*53889Smckusick {
427*53889Smckusick 	static int port;
428*53889Smckusick 	char *addr;
429*53889Smckusick 	int len;
430*53889Smckusick 
431*53889Smckusick 	if (port == 0)
432*53889Smckusick 		port = port_create("port_kbd_read");
433*53889Smckusick 	if (n <= 0)
434*53889Smckusick 		return (0);
435*53889Smckusick 	msg_send(port_kbd_ctrl, port, &n, sizeof (n), 0);
436*53889Smckusick 	msg_recv(port, NULL, &addr, &len, 0);
437*53889Smckusick 	bcopy(addr, buf, len);
438*53889Smckusick 	msg_free(port);
439*53889Smckusick 	return (len);
440*53889Smckusick }
441*53889Smckusick 
442*53889Smckusick kbd_write(chan, buf, n)
443*53889Smckusick 	int chan;
444*53889Smckusick 	char *buf;
445*53889Smckusick 	int n;
446*53889Smckusick {
447*53889Smckusick #ifdef news1800
448*53889Smckusick 	return (scc_write(chan, SCC_KEYBOARD, buf, n));
449*53889Smckusick #endif
450*53889Smckusick 
451*53889Smckusick #ifdef news3800
452*53889Smckusick 	*(char *)BEEP_FREQ = ~(n & 1);
453*53889Smckusick 	*(char *)KEYBD_BEEP = 1;
454*53889Smckusick 	return (n);
455*53889Smckusick #endif
456*53889Smckusick }
457*53889Smckusick 
458*53889Smckusick kbd_back(buf, len)
459*53889Smckusick 	char *buf;
460*53889Smckusick 	int len;
461*53889Smckusick {
462*53889Smckusick 
463*53889Smckusick 	msg_send(port_kbd_back, 0, buf, len, 0);
464*53889Smckusick 	return (0);
465*53889Smckusick }
466*53889Smckusick 
467*53889Smckusick kbd_nread()
468*53889Smckusick {
469*53889Smckusick 
470*53889Smckusick 	return (buffer_status(kbd_buf));
471*53889Smckusick }
472*53889Smckusick 
473*53889Smckusick kbd_flush()
474*53889Smckusick {
475*53889Smckusick 
476*53889Smckusick 	buffer_flush(kbd_buf);
477*53889Smckusick 	return (0);
478*53889Smckusick }
479*53889Smckusick 
480*53889Smckusick #ifdef news3800
481*53889Smckusick kb_intr()
482*53889Smckusick {
483*53889Smckusick 	char c;
484*53889Smckusick 
485*53889Smckusick 	if (port_kbd_intr > 0)
486*53889Smckusick 		while (*(char *)KBMS_STAT & (1 << b_KBREADY)) {
487*53889Smckusick 			c = *(char *)KEYBD_DATA;
488*53889Smckusick 			msg_send(port_kbd_intr, 0, &c, sizeof (char), 0);
489*53889Smckusick 		}
490*53889Smckusick }
491*53889Smckusick #endif /* news3800 */
492*53889Smckusick 
493*53889Smckusick kbd_bell(n, port)
494*53889Smckusick 	int n, port;
495*53889Smckusick {
496*53889Smckusick 
497*53889Smckusick #ifdef news3800
498*53889Smckusick 	(void) kbd_write(0, NULL, n);
499*53889Smckusick #else
500*53889Smckusick 	kbd_bell_scc(n, port);
501*53889Smckusick #endif
502*53889Smckusick 	return (0);
503*53889Smckusick }
504*53889Smckusick 
505*53889Smckusick put_code(buf, cnt)
506*53889Smckusick 	char *buf;
507*53889Smckusick 	int cnt;
508*53889Smckusick {
509*53889Smckusick 
510*53889Smckusick 	put(kbd_buf, buf, cnt);
511*53889Smckusick }
512*53889Smckusick #endif /* IPC_MRX */
513*53889Smckusick 
514*53889Smckusick kbd_ioctl(chan, cmd, argp)
515*53889Smckusick 	int chan;
516*53889Smckusick 	int cmd;
517*53889Smckusick 	int *argp;
518*53889Smckusick {
519*53889Smckusick 	switch (cmd) {
520*53889Smckusick 
521*53889Smckusick 	case KIOCFLUSH:
522*53889Smckusick 		return (kbd_flush());
523*53889Smckusick 
524*53889Smckusick 	case KIOCSETS:
525*53889Smckusick 	case KIOCGETS:
526*53889Smckusick 		return (kbd_string(cmd, (Pfk_string *)argp));
527*53889Smckusick 
528*53889Smckusick 	case KIOCBELL:
529*53889Smckusick #ifdef news1800
530*53889Smckusick 		return (kbd_bell(*argp, chan));
531*53889Smckusick #else
532*53889Smckusick 		return (kbd_bell(*argp));
533*53889Smckusick #endif
534*53889Smckusick 
535*53889Smckusick 	case KIOCBACK:
536*53889Smckusick 		if (argp == NULL)
537*53889Smckusick 			return (-1);
538*53889Smckusick 		if ((int)((Key_string *)argp)->key_string == NULL)
539*53889Smckusick 			return (-1);
540*53889Smckusick 		if ((int)((Key_string *)argp)->key_length <= 0)
541*53889Smckusick 			return (-1);
542*53889Smckusick 		return (kbd_back(((Key_string *)argp)->key_string,
543*53889Smckusick 		    ((Key_string *)argp)->key_length));
544*53889Smckusick 
545*53889Smckusick 	case KIOCREPT:
546*53889Smckusick 		return (kbd_repeat(1));
547*53889Smckusick 
548*53889Smckusick 	case KIOCNRPT:
549*53889Smckusick 		return (kbd_repeat(0));
550*53889Smckusick 
551*53889Smckusick 	case KIOCNREAD:
552*53889Smckusick 		*argp = kbd_nread();
553*53889Smckusick 		return (0);
554*53889Smckusick 
555*53889Smckusick 	case KIOCSETLOCK:
556*53889Smckusick 		iscaps = *argp;
557*53889Smckusick 		return (0);
558*53889Smckusick 
559*53889Smckusick 	case KIOCGETCNUM:
560*53889Smckusick 		*argp = country;
561*53889Smckusick 		return (0);
562*53889Smckusick 
563*53889Smckusick 	case KIOCSETCNUM:
564*53889Smckusick 		country = *argp;
565*53889Smckusick 		change_country = country;
566*53889Smckusick 		return (0);
567*53889Smckusick 
568*53889Smckusick 	case KIOCDEFTBL:
569*53889Smckusick 		key_table_addr = default_table;
570*53889Smckusick 		country = K_JAPANESE_J;
571*53889Smckusick 		return (0);
572*53889Smckusick 
573*53889Smckusick 	case KIOCCHTBL:
574*53889Smckusick 		key_table_addr = (Key_table *)argp;
575*53889Smckusick 		country = change_country;
576*53889Smckusick 		return (0);
577*53889Smckusick 
578*53889Smckusick 	case KIOCGETSTAT:
579*53889Smckusick 		*argp = kbd_status;
580*53889Smckusick 		return (0);
581*53889Smckusick 
582*53889Smckusick 	case KIOCSETSTAT:
583*53889Smckusick 		kbd_status = *argp;
584*53889Smckusick 		return (0);
585*53889Smckusick 
586*53889Smckusick 	default:
587*53889Smckusick 		return (-1);
588*53889Smckusick 	}
589*53889Smckusick }
590*53889Smckusick 
591*53889Smckusick #ifdef news1800
592*53889Smckusick kbd_bell_scc(n, port)
593*53889Smckusick 	register int n, port;
594*53889Smckusick #else
595*53889Smckusick kbd_bell_scc(n)
596*53889Smckusick 	register int n;
597*53889Smckusick #endif
598*53889Smckusick {
599*53889Smckusick 	register int i;
600*53889Smckusick 	static char bell_data[] = {
601*53889Smckusick 		0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
602*53889Smckusick 		0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
603*53889Smckusick 		0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
604*53889Smckusick 		0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0
605*53889Smckusick 	};
606*53889Smckusick 
607*53889Smckusick 	while (n > 0) {
608*53889Smckusick 		i = min(n, sizeof (bell_data));
609*53889Smckusick #ifdef news1800
610*53889Smckusick 		(void) kbd_write(port, bell_data, i);
611*53889Smckusick #else
612*53889Smckusick 		(void) kbd_write(0, bell_data, i);
613*53889Smckusick #endif
614*53889Smckusick 		n -= i;
615*53889Smckusick 	}
616*53889Smckusick }
617*53889Smckusick 
618*53889Smckusick #ifdef KBDEBUG
619*53889Smckusick scc_error_puts(chan, buf)
620*53889Smckusick 	int chan;
621*53889Smckusick 	char *buf;
622*53889Smckusick {
623*53889Smckusick 	while (*buf) {
624*53889Smckusick 		scc_error_write(chan, *buf++, 1);
625*53889Smckusick 	}
626*53889Smckusick }
627*53889Smckusick 
628*53889Smckusick scc_error_write_hex(chan, n, zs)
629*53889Smckusick 	int chan;
630*53889Smckusick 	unsigned int n;
631*53889Smckusick 	int zs;
632*53889Smckusick {
633*53889Smckusick 	int i;
634*53889Smckusick 	int tmp, al;
635*53889Smckusick 	static char hex[] = "0123456789abcdef";
636*53889Smckusick 
637*53889Smckusick 	al = 0;
638*53889Smckusick 
639*53889Smckusick 	for (i = 28; i >= 0; i -= 4) {
640*53889Smckusick 		tmp = (n >> i) & 0x0f;
641*53889Smckusick 		if (tmp || al || !zs || !i) {
642*53889Smckusick 			al++;
643*53889Smckusick 			scc_error_write(chan, hex[tmp], 1);
644*53889Smckusick 		}
645*53889Smckusick 	}
646*53889Smckusick }
647*53889Smckusick #endif /* KBDEBUG */
648