Home | History | Annotate | Line # | Download | only in dev
kbd.c revision 1.32
      1  1.32        is /*	$NetBSD: kbd.c,v 1.32 1998/03/08 19:59:15 is Exp $	*/
      2  1.11       cgd 
      3   1.1        mw /*
      4   1.1        mw  * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
      5   1.1        mw  * All rights reserved.
      6   1.1        mw  *
      7   1.1        mw  * Redistribution and use in source and binary forms, with or without
      8   1.1        mw  * modification, are permitted provided that the following conditions
      9   1.1        mw  * are met:
     10   1.1        mw  * 1. Redistributions of source code must retain the above copyright
     11   1.1        mw  *    notice, this list of conditions and the following disclaimer.
     12   1.1        mw  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1        mw  *    notice, this list of conditions and the following disclaimer in the
     14   1.1        mw  *    documentation and/or other materials provided with the distribution.
     15   1.1        mw  * 3. All advertising materials mentioning features or use of this software
     16   1.1        mw  *    must display the following acknowledgement:
     17   1.1        mw  *	This product includes software developed by the University of
     18   1.1        mw  *	California, Berkeley and its contributors.
     19   1.1        mw  * 4. Neither the name of the University nor the names of its contributors
     20   1.1        mw  *    may be used to endorse or promote products derived from this software
     21   1.1        mw  *    without specific prior written permission.
     22   1.1        mw  *
     23   1.1        mw  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.1        mw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.1        mw  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.1        mw  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.1        mw  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.1        mw  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.1        mw  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1        mw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1        mw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1        mw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1        mw  * SUCH DAMAGE.
     34   1.1        mw  *
     35   1.4        mw  *	kbd.c
     36   1.1        mw  */
     37   1.7    chopps #include <sys/param.h>
     38   1.7    chopps #include <sys/systm.h>
     39   1.9    chopps #include <sys/device.h>
     40   1.7    chopps #include <sys/ioctl.h>
     41   1.7    chopps #include <sys/tty.h>
     42   1.7    chopps #include <sys/proc.h>
     43   1.7    chopps #include <sys/file.h>
     44   1.7    chopps #include <sys/kernel.h>
     45   1.7    chopps #include <sys/syslog.h>
     46  1.18     veego #include <sys/signalvar.h>
     47   1.8    chopps #include <dev/cons.h>
     48  1.31        is #include <m68k/asm_single.h>
     49   1.7    chopps #include <machine/cpu.h>
     50   1.9    chopps #include <amiga/amiga/device.h>
     51   1.7    chopps #include <amiga/amiga/custom.h>
     52  1.19        is #ifdef DRACO
     53  1.19        is #include <amiga/amiga/drcustom.h>
     54  1.19        is #endif
     55   1.7    chopps #include <amiga/amiga/cia.h>
     56   1.9    chopps #include <amiga/dev/itevar.h>
     57   1.9    chopps #include <amiga/dev/kbdreg.h>
     58  1.18     veego #include <amiga/dev/kbdmap.h>
     59   1.7    chopps #include <amiga/dev/event_var.h>
     60   1.7    chopps #include <amiga/dev/vuid_event.h>
     61   1.9    chopps #include "kbd.h"
     62   1.5        mw 
     63  1.18     veego #include <sys/conf.h>
     64  1.18     veego #include <machine/conf.h>
     65  1.18     veego 
     66   1.5        mw struct kbd_softc {
     67   1.9    chopps 	int k_event_mode;	/* if true, collect events, else pass to ite */
     68   1.9    chopps 	struct evvar k_events;	/* event queue state */
     69  1.19        is #ifdef DRACO
     70  1.19        is 	u_char k_rlprfx;	/* MF-II rel. prefix has been seen */
     71  1.31        is 	u_char k_mf2;
     72  1.19        is #endif
     73   1.9    chopps };
     74   1.9    chopps struct kbd_softc kbd_softc;
     75   1.9    chopps 
     76  1.28     veego int kbdmatch __P((struct device *, struct cfdata *, void *));
     77  1.17    mhitch void kbdattach __P((struct device *, struct device *, void *));
     78  1.18     veego void kbdintr __P((int));
     79  1.19        is void kbdstuffchar __P((u_char));
     80   1.9    chopps 
     81  1.31        is int drkbdgetc __P((void));
     82  1.31        is int drkbdrputc __P((int));
     83  1.31        is int drkbdputc __P((int));
     84  1.31        is int drkbdputc2 __P((int, int));
     85  1.31        is int drkbdwaitfor __P((int));
     86  1.31        is 
     87  1.16   thorpej struct cfattach kbd_ca = {
     88  1.16   thorpej 	sizeof(struct device), kbdmatch, kbdattach
     89  1.16   thorpej };
     90   1.9    chopps 
     91   1.9    chopps /*ARGSUSED*/
     92   1.9    chopps int
     93  1.28     veego kbdmatch(pdp, cfp, auxp)
     94   1.9    chopps 	struct device *pdp;
     95  1.28     veego 	struct cfdata *cfp;
     96  1.28     veego 	void *auxp;
     97   1.9    chopps {
     98  1.16   thorpej 
     99   1.9    chopps 	if (matchname((char *)auxp, "kbd"))
    100   1.9    chopps 		return(1);
    101   1.9    chopps 	return(0);
    102   1.9    chopps }
    103   1.9    chopps 
    104   1.9    chopps /*ARGSUSED*/
    105   1.9    chopps void
    106   1.9    chopps kbdattach(pdp, dp, auxp)
    107   1.9    chopps 	struct device *pdp, *dp;
    108   1.9    chopps 	void *auxp;
    109   1.9    chopps {
    110  1.19        is #ifdef DRACO
    111  1.31        is 	kbdenable();
    112  1.31        is 	if (kbd_softc.k_mf2)
    113  1.31        is 		printf(": QuickLogic type MF-II\n");
    114  1.31        is 	else
    115  1.31        is 		printf(": CIA A type Amiga\n");
    116  1.19        is #else
    117  1.26  christos 	printf(": CIA A type Amiga\n");
    118  1.19        is #endif
    119  1.19        is 
    120   1.9    chopps }
    121   1.5        mw 
    122   1.5        mw /* definitions for amiga keyboard encoding. */
    123   1.5        mw #define KEY_CODE(c)  ((c) & 0x7f)
    124   1.5        mw #define KEY_UP(c)    ((c) & 0x80)
    125   1.5        mw 
    126  1.31        is #define DATLO single_inst_bclr_b(draco_ioct->io_control, DRCNTRL_KBDDATOUT)
    127  1.31        is #define DATHI single_inst_bset_b(draco_ioct->io_control, DRCNTRL_KBDDATOUT)
    128  1.31        is 
    129  1.31        is #define CLKLO single_inst_bclr_b(draco_ioct->io_control, DRCNTRL_KBDCLKOUT)
    130  1.31        is #define CLKHI single_inst_bset_b(draco_ioct->io_control, DRCNTRL_KBDCLKOUT)
    131  1.31        is 
    132   1.1        mw void
    133  1.18     veego kbdenable()
    134   1.1        mw {
    135  1.30        is 	static int kbd_inited = 0;
    136  1.30        is 
    137   1.9    chopps 	int s;
    138  1.22        is 
    139  1.21        is #ifdef DRACO
    140  1.31        is 	int id;
    141  1.21        is #endif
    142   1.9    chopps 	/*
    143   1.9    chopps 	 * collides with external ints from SCSI, watch out for this when
    144   1.9    chopps 	 * enabling/disabling interrupts there !!
    145   1.9    chopps 	 */
    146  1.30        is 	s = splhigh();	/* don't lower; might be called from early ddb */
    147  1.30        is 	if (kbd_inited) {
    148  1.30        is 		splx(s);
    149  1.30        is 		return;
    150  1.30        is 	}
    151  1.30        is 	kbd_inited = 1;
    152  1.19        is #ifdef DRACO
    153  1.31        is 	if (is_draco()) {
    154  1.31        is 
    155  1.31        is 		CLKLO;
    156  1.31        is 		delay(5000);
    157  1.31        is 		draco_ioct->io_kbdrst = 0;
    158  1.31        is 
    159  1.31        is 		if (drkbdputc(0xf2))
    160  1.31        is 			goto LnoMFII;
    161  1.31        is 
    162  1.31        is 		id = drkbdgetc() << 8;
    163  1.31        is 		id |= drkbdgetc();
    164  1.31        is 
    165  1.31        is 		if (id != 0xab83)
    166  1.31        is 			goto LnoMFII;
    167  1.19        is 
    168  1.31        is 		if (drkbdputc2(0xf0, 3))	/* mode 3 */
    169  1.31        is 			goto LnoMFII;
    170  1.31        is 
    171  1.31        is 		if (drkbdputc(0xf8))		/* make/break, no typematic */
    172  1.31        is 			goto LnoMFII;
    173  1.31        is 
    174  1.31        is 		if (drkbdputc(0xf4))		/* enable */
    175  1.31        is 			goto LnoMFII;
    176  1.31        is 		kbd_softc.k_mf2 = 1;
    177  1.31        is 		draco_ioct->io_control &= ~DRCNTRL_KBDINTENA;
    178  1.19        is 
    179  1.31        is 		ciaa.icr = CIA_ICR_SP;  /* CIA SP interrupt disable */
    180  1.31        is 		ciaa.cra &= ~(1<<6);	/* serial line == input */
    181  1.31        is 		splx(s);
    182  1.31        is 		return;
    183  1.19        is 
    184  1.31        is 	LnoMFII:
    185  1.31        is 		kbd_softc.k_mf2 = 0;
    186  1.31        is 		*draco_intena |= DRIRQ_INT2;
    187  1.31        is 		ciaa.icr = CIA_ICR_IR_SC | CIA_ICR_SP;
    188  1.31        is 					/* SP interrupt enable */
    189  1.31        is 		ciaa.cra &= ~(1<<6);	/* serial line == input */
    190  1.31        is 		splx(s);
    191  1.31        is 		return;
    192  1.31        is 
    193  1.31        is 	} else {
    194  1.31        is #endif
    195   1.9    chopps 	custom.intena = INTF_SETCLR | INTF_PORTS;
    196   1.9    chopps 	ciaa.icr = CIA_ICR_IR_SC | CIA_ICR_SP;  /* SP interrupt enable */
    197   1.9    chopps 	ciaa.cra &= ~(1<<6);		/* serial line == input */
    198  1.31        is #ifdef DRACO
    199  1.31        is 	}
    200  1.19        is #endif
    201   1.9    chopps 	kbd_softc.k_event_mode = 0;
    202   1.9    chopps 	kbd_softc.k_events.ev_io = 0;
    203   1.9    chopps 	splx(s);
    204   1.1        mw }
    205   1.1        mw 
    206  1.32        is #ifdef DRACO
    207  1.31        is /*
    208  1.31        is  * call this with kbd interupt blocked
    209  1.31        is  */
    210  1.31        is 
    211  1.31        is int
    212  1.31        is drkbdgetc()
    213  1.31        is {
    214  1.31        is 	u_int8_t in;
    215  1.31        is 
    216  1.31        is 	while ((draco_ioct->io_status & DRSTAT_KBDRECV) == 0);
    217  1.31        is 	in = draco_ioct->io_kbddata;
    218  1.31        is 	draco_ioct->io_kbdrst = 0;
    219  1.31        is 
    220  1.31        is 	return in;
    221  1.31        is }
    222  1.31        is 
    223  1.31        is #define WAIT0 if (drkbdwaitfor(0)) goto Ltimeout
    224  1.31        is #define WAIT1 if (drkbdwaitfor(DRSTAT_KBDCLKIN)) goto Ltimeout
    225  1.31        is 
    226  1.31        is int
    227  1.31        is drkbdwaitfor(bit)
    228  1.31        is 	int bit;
    229  1.31        is {
    230  1.31        is 	int i;
    231  1.31        is 
    232  1.31        is 
    233  1.31        is 
    234  1.31        is 	i = 60000;	/* about 50 ms max */
    235  1.31        is 
    236  1.31        is 	do {
    237  1.31        is 		if ((draco_ioct->io_status & DRSTAT_KBDCLKIN) == bit)
    238  1.31        is 			return 0;
    239  1.31        is 
    240  1.31        is 	} while (--i >= 0);
    241  1.31        is 
    242  1.31        is 	return 1;
    243  1.31        is }
    244  1.31        is 
    245  1.31        is /*
    246  1.31        is  * Output a raw byte to the keyboard (+ parity and stop bit).
    247  1.31        is  * return 0 on success, 1 on timeout.
    248  1.31        is  */
    249  1.31        is int
    250  1.31        is drkbdrputc(c)
    251  1.31        is 	u_int8_t c;
    252  1.31        is {
    253  1.31        is 	u_int8_t parity;
    254  1.31        is 	int bitcnt;
    255  1.31        is 
    256  1.31        is 	DATLO; CLKHI; WAIT1;
    257  1.31        is 	parity = 0;
    258  1.31        is 
    259  1.31        is 	for (bitcnt=7; bitcnt >= 0; bitcnt--) {
    260  1.31        is 		WAIT0;
    261  1.31        is 		if (c & 1) {
    262  1.31        is 			DATHI;
    263  1.31        is 		} else {
    264  1.31        is 			++parity;
    265  1.31        is 			DATLO;
    266  1.31        is 		}
    267  1.31        is 		c >>= 1;
    268  1.31        is 		WAIT1;
    269  1.31        is 	}
    270  1.31        is 	WAIT0;
    271  1.31        is 	/* parity bit */
    272  1.31        is 	if (parity & 1) {
    273  1.31        is 		DATLO;
    274  1.31        is 	} else {
    275  1.31        is 		DATHI;
    276  1.31        is 	}
    277  1.31        is 	WAIT1;
    278  1.31        is 	/* stop bit */
    279  1.31        is 	WAIT0; DATHI; WAIT1;
    280  1.31        is 
    281  1.31        is 	WAIT0; /* XXX should check the ack bit here... */
    282  1.31        is 	WAIT1;
    283  1.31        is 	draco_ioct->io_kbdrst = 0;
    284  1.31        is 	return 0;
    285  1.31        is 
    286  1.31        is Ltimeout:
    287  1.31        is 	DATHI;
    288  1.31        is 	draco_ioct->io_kbdrst = 0;
    289  1.31        is 	return 1;
    290  1.31        is }
    291  1.31        is 
    292  1.31        is /*
    293  1.31        is  * Output one cooked byte to the keyboard, with wait for ACK or RESEND,
    294  1.31        is  * and retry if necessary. 0 == success, 1 == timeout
    295  1.31        is  */
    296  1.31        is int
    297  1.31        is drkbdputc(c)
    298  1.31        is 	u_int8_t c;
    299  1.31        is {
    300  1.31        is 	int rc;
    301  1.31        is 
    302  1.31        is 	do {
    303  1.31        is 		if (drkbdrputc(c))
    304  1.31        is 			return(-1);
    305  1.31        is 
    306  1.31        is 		rc = drkbdgetc();
    307  1.31        is 	} while (rc == 0xfe);
    308  1.31        is 	return (!(rc == 0xfa));
    309  1.31        is }
    310  1.31        is 
    311  1.31        is /*
    312  1.31        is  * same for twobyte sequence
    313  1.31        is  */
    314  1.31        is 
    315  1.31        is int
    316  1.31        is drkbdputc2(c1, c2)
    317  1.31        is 	u_int8_t c1, c2;
    318  1.31        is {
    319  1.31        is 	int rc;
    320  1.31        is 
    321  1.31        is 	do {
    322  1.31        is 		do {
    323  1.31        is 			if (drkbdrputc(c1))
    324  1.31        is 				return(-1);
    325  1.31        is 
    326  1.31        is 			rc = drkbdgetc();
    327  1.31        is 		} while (rc == 0xfe);
    328  1.31        is 		if (rc != 0xfa)
    329  1.31        is 			return (-1);
    330  1.31        is 
    331  1.31        is 		if (drkbdrputc(c2))
    332  1.31        is 			return(-1);
    333  1.31        is 
    334  1.31        is 		rc = drkbdgetc();
    335  1.31        is 	} while (rc == 0xfe);
    336  1.31        is 	return (!(rc == 0xfa));
    337  1.31        is }
    338  1.32        is #endif
    339   1.1        mw 
    340   1.1        mw int
    341  1.18     veego kbdopen(dev, flags, mode, p)
    342  1.18     veego 	dev_t dev;
    343  1.18     veego 	int flags, mode;
    344  1.18     veego 	struct proc *p;
    345   1.5        mw {
    346   1.5        mw 
    347  1.30        is 	kbdenable();
    348  1.18     veego 	if (kbd_softc.k_events.ev_io)
    349  1.18     veego 		return EBUSY;
    350   1.5        mw 
    351  1.18     veego 	kbd_softc.k_events.ev_io = p;
    352  1.18     veego 	ev_init(&kbd_softc.k_events);
    353  1.18     veego 	return (0);
    354   1.5        mw }
    355   1.5        mw 
    356   1.5        mw int
    357  1.18     veego kbdclose(dev, flags, mode, p)
    358  1.18     veego 	dev_t dev;
    359  1.18     veego 	int flags, mode;
    360  1.18     veego 	struct proc *p;
    361   1.5        mw {
    362  1.18     veego 
    363  1.18     veego 	/* Turn off event mode, dump the queue */
    364  1.18     veego 	kbd_softc.k_event_mode = 0;
    365  1.18     veego 	ev_fini(&kbd_softc.k_events);
    366  1.18     veego 	kbd_softc.k_events.ev_io = NULL;
    367  1.18     veego 	return (0);
    368   1.5        mw }
    369   1.5        mw 
    370   1.5        mw int
    371  1.18     veego kbdread(dev, uio, flags)
    372  1.18     veego 	dev_t dev;
    373  1.18     veego 	struct uio *uio;
    374  1.18     veego 	int flags;
    375   1.5        mw {
    376  1.18     veego 	return ev_read (&kbd_softc.k_events, uio, flags);
    377   1.5        mw }
    378   1.5        mw 
    379   1.5        mw int
    380  1.18     veego kbdioctl(dev, cmd, data, flag, p)
    381  1.18     veego 	dev_t dev;
    382  1.18     veego 	u_long cmd;
    383  1.18     veego 	register caddr_t data;
    384  1.18     veego 	int flag;
    385  1.18     veego 	struct proc *p;
    386   1.5        mw {
    387  1.18     veego 	register struct kbd_softc *k = &kbd_softc;
    388  1.18     veego 
    389  1.18     veego 	switch (cmd) {
    390  1.18     veego 		case KIOCTRANS:
    391  1.18     veego 			if (*(int *)data == TR_UNTRANS_EVENT)
    392  1.18     veego 				return 0;
    393  1.18     veego 			break;
    394  1.18     veego 
    395  1.18     veego 		case KIOCGTRANS:
    396  1.18     veego 			/* Get translation mode */
    397  1.18     veego 			*(int *)data = TR_UNTRANS_EVENT;
    398  1.18     veego 			return 0;
    399  1.18     veego 
    400  1.18     veego 		case KIOCSDIRECT:
    401  1.18     veego 			k->k_event_mode = *(int *)data;
    402  1.18     veego 			return 0;
    403  1.18     veego 
    404  1.18     veego 		case FIONBIO:	/* we will remove this someday (soon???) */
    405  1.18     veego 			return 0;
    406  1.18     veego 
    407  1.18     veego 		case FIOASYNC:
    408  1.18     veego 			k->k_events.ev_async = *(int *)data != 0;
    409  1.18     veego 			return 0;
    410  1.18     veego 
    411  1.18     veego 		case TIOCSPGRP:
    412  1.18     veego 			if (*(int *)data != k->k_events.ev_io->p_pgid)
    413  1.18     veego 				return EPERM;
    414  1.18     veego 			return 0;
    415  1.18     veego 
    416  1.18     veego 		default:
    417  1.18     veego 			return ENOTTY;
    418  1.18     veego 	}
    419   1.5        mw 
    420  1.18     veego 	/* We identified the ioctl, but we do not handle it. */
    421  1.18     veego 	return EOPNOTSUPP;	/* misuse, but what the heck */
    422   1.5        mw }
    423   1.5        mw 
    424   1.5        mw int
    425  1.25    mhitch kbdpoll(dev, events, p)
    426  1.18     veego 	dev_t dev;
    427  1.25    mhitch 	int events;
    428  1.18     veego 	struct proc *p;
    429   1.5        mw {
    430  1.25    mhitch 	return ev_poll (&kbd_softc.k_events, events, p);
    431   1.5        mw }
    432   1.5        mw 
    433   1.5        mw 
    434  1.18     veego void
    435  1.18     veego kbdintr(mask)
    436  1.18     veego 	int mask;
    437   1.1        mw {
    438  1.18     veego 	u_char c;
    439  1.13    chopps #ifdef KBDRESET
    440  1.18     veego 	static int reset_warn;
    441  1.13    chopps #endif
    442   1.1        mw 
    443  1.19        is 	/*
    444  1.19        is 	 * now only invoked from generic CIA interrupt handler if there *is*
    445  1.18     veego 	 * a keyboard interrupt pending
    446  1.18     veego 	 */
    447   1.1        mw 
    448  1.18     veego 	c = ~ciaa.sdr;	/* keyboard data is inverted */
    449  1.18     veego 	/* ack */
    450  1.18     veego 	ciaa.cra |= (1 << 6);	/* serial line output */
    451  1.13    chopps #ifdef KBDRESET
    452  1.18     veego 	if (reset_warn && c == 0xf0) {
    453  1.13    chopps #ifdef DEBUG
    454  1.26  christos 		printf ("kbdintr: !!!! Reset Warning !!!!\n");
    455  1.13    chopps #endif
    456  1.18     veego 		bootsync();
    457  1.18     veego 		reset_warn = 0;
    458  1.18     veego 		DELAY(30000000);
    459  1.18     veego 	}
    460  1.13    chopps #endif
    461  1.18     veego 	/* wait 200 microseconds (for bloody Cherry keyboards..) */
    462  1.18     veego 	DELAY(2000);			/* fudge delay a bit for some keyboards */
    463  1.18     veego 	ciaa.cra &= ~(1 << 6);
    464  1.18     veego 
    465  1.18     veego 	/* process the character */
    466  1.18     veego 	c = (c >> 1) | (c << 7);	/* rotate right once */
    467   1.1        mw 
    468  1.13    chopps #ifdef KBDRESET
    469  1.18     veego 	if (c == 0x78) {
    470  1.13    chopps #ifdef DEBUG
    471  1.26  christos 		printf ("kbdintr: Reset Warning started\n");
    472  1.13    chopps #endif
    473  1.18     veego 		++reset_warn;
    474  1.18     veego 		return;
    475  1.18     veego 	}
    476  1.13    chopps #endif
    477  1.19        is 	kbdstuffchar(c);
    478  1.19        is }
    479  1.19        is 
    480  1.19        is #ifdef DRACO
    481  1.19        is /* maps MF-II keycodes to Amiga keycodes */
    482  1.19        is 
    483  1.27        is const u_char drkbdtab[] = {
    484  1.19        is 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x50,
    485  1.19        is 	0x45, 0xff, 0xff, 0xff, 0xff, 0x42, 0x00, 0x51,
    486  1.19        is 
    487  1.19        is 	0xff, 0x64, 0x60, 0x30, 0x63, 0x10, 0x01, 0x52,
    488  1.19        is 	0xff, 0x66, 0x31, 0x21, 0x20, 0x11, 0x02, 0x53,
    489  1.19        is 
    490  1.19        is 	0xff, 0x33, 0x32, 0x22, 0x12, 0x04, 0x03, 0x54,
    491  1.19        is 	0xff, 0x40, 0x34, 0x23, 0x14, 0x13, 0x05, 0x55,
    492  1.19        is 
    493  1.19        is 	0xff, 0x36, 0x35, 0x25, 0x24, 0x15, 0x06, 0x56,
    494  1.19        is 	0xff, 0x67, 0x37, 0x26, 0x16, 0x07, 0x08, 0x57,
    495  1.19        is 	/* --- */
    496  1.19        is 	0xff, 0x38, 0x27, 0x17, 0x18, 0x0a, 0x09, 0x58,
    497  1.19        is 	0xff, 0x39, 0x3a, 0x28, 0x29, 0x19, 0x0b, 0x59,
    498  1.19        is 
    499  1.19        is 	0xff, 0xff, 0x2a, 0x2b, 0x1a, 0x0c, 0x4b, 0xff,
    500  1.19        is 	0x65, 0x61, 0x44, 0x1b, 0xff, 0xff, 0x6f, 0xff,
    501  1.19        is 
    502  1.19        is 	0x4d, 0x4f, 0xff, 0x4c, 0x0d, 0xff, 0x41, 0x46,
    503  1.19        is 	0xff, 0x1d, 0x4e, 0x2d, 0x3d, 0x4a, 0x5f, 0x62,
    504  1.19        is 
    505  1.19        is 	0x0f, 0x3c, 0x1e, 0x2e, 0x2f, 0x3e, 0x5a, 0x5b,
    506  1.19        is 	0xff, 0x43, 0x1f, 0xff, 0x5e, 0x3f, 0x5c, 0xff,
    507  1.19        is 	/* --- */
    508  1.19        is 	0xff, 0xff, 0xff, 0xff, 0x5d
    509  1.19        is };
    510  1.19        is #endif
    511  1.19        is 
    512  1.19        is 
    513  1.19        is int
    514  1.19        is kbdgetcn ()
    515  1.19        is {
    516  1.19        is 	int s;
    517  1.19        is 	u_char ints, mask, c, in;
    518  1.19        is 
    519  1.19        is #ifdef DRACO
    520  1.31        is 	if (is_draco() && kbd_softc.k_mf2) {
    521  1.31        is 		do {
    522  1.31        is 			c = 0;
    523  1.31        is 			s = spltty ();
    524  1.19        is 			while ((draco_ioct->io_status & DRSTAT_KBDRECV) == 0);
    525  1.19        is 			in = draco_ioct->io_kbddata;
    526  1.19        is 			draco_ioct->io_kbdrst = 0;
    527  1.31        is 			if (in == 0xF0) { /* release prefix */
    528  1.31        is 				c = 0x80;
    529  1.31        is 				while ((draco_ioct->io_status & DRSTAT_KBDRECV) == 0);
    530  1.31        is 				in = draco_ioct->io_kbddata;
    531  1.31        is 				draco_ioct->io_kbdrst = 0;
    532  1.31        is 			}
    533  1.31        is 			splx(s);
    534  1.19        is #ifdef DRACORAWKEYDEBUG
    535  1.31        is 			printf("<%02x>", in);
    536  1.19        is #endif
    537  1.31        is 			c |= in>=sizeof(drkbdtab) ? 0xff : drkbdtab[in];
    538  1.31        is 		} while (c == 0xff);
    539  1.31        is 		return (c);
    540  1.19        is 	}
    541  1.19        is #endif
    542  1.19        is 	s = spltty();
    543  1.19        is 	for (ints = 0; ! ((mask = ciaa.icr) & CIA_ICR_SP);
    544  1.19        is 	    ints |= mask) ;
    545  1.19        is 
    546  1.19        is 	in = ciaa.sdr;
    547  1.19        is 	c = ~in;
    548  1.19        is 
    549  1.19        is 	/* ack */
    550  1.19        is 	ciaa.cra |= (1 << 6);	/* serial line output */
    551  1.19        is 	ciaa.sdr = 0xff;	/* ack */
    552  1.19        is 	/* wait 200 microseconds */
    553  1.19        is 	DELAY(2000);	/* XXXX only works as long as DELAY doesn't
    554  1.19        is 			 * use a timer and waits.. */
    555  1.19        is 	ciaa.cra &= ~(1 << 6);
    556  1.19        is 	ciaa.sdr = in;
    557  1.19        is 
    558  1.19        is 	splx (s);
    559  1.19        is 	c = (c >> 1) | (c << 7);
    560  1.19        is 
    561  1.19        is 	/* take care that no CIA-interrupts are lost */
    562  1.19        is 	if (ints)
    563  1.19        is 		dispatch_cia_ints (0, ints);
    564  1.19        is 
    565  1.19        is 	return c;
    566  1.19        is }
    567  1.19        is 
    568  1.19        is void
    569  1.19        is kbdstuffchar(c)
    570  1.19        is 	u_char c;
    571  1.19        is {
    572  1.19        is 	struct firm_event *fe;
    573  1.19        is 	struct kbd_softc *k = &kbd_softc;
    574  1.19        is 	int put;
    575  1.19        is 
    576  1.19        is 	/*
    577  1.19        is 	 * If not in event mode, deliver straight to ite to process
    578  1.19        is 	 * key stroke
    579  1.19        is 	 */
    580  1.19        is 
    581  1.18     veego 	if (! k->k_event_mode) {
    582  1.18     veego 		ite_filter (c, ITEFILT_TTY);
    583  1.18     veego 		return;
    584  1.18     veego 	}
    585  1.18     veego 
    586  1.19        is 	/*
    587  1.19        is 	 * Keyboard is generating events. Turn this keystroke into an
    588  1.19        is 	 * event and put it in the queue. If the queue is full, the
    589  1.18     veego 	 * keystroke is lost (sorry!).
    590  1.18     veego 	 */
    591  1.19        is 
    592  1.18     veego 	put = k->k_events.ev_put;
    593  1.18     veego 	fe = &k->k_events.ev_q[put];
    594  1.18     veego 	put = (put + 1) % EV_QSIZE;
    595  1.18     veego 	if (put == k->k_events.ev_get) {
    596  1.19        is 		log(LOG_WARNING, "keyboard event queue overflow\n");
    597  1.19        is 			/* ??? */
    598  1.18     veego 		return;
    599  1.18     veego 	}
    600  1.18     veego 	fe->id = KEY_CODE(c);
    601  1.18     veego 	fe->value = KEY_UP(c) ? VKEY_UP : VKEY_DOWN;
    602  1.18     veego 	fe->time = time;
    603  1.18     veego 	k->k_events.ev_put = put;
    604  1.18     veego 	EV_WAKEUP(&k->k_events);
    605   1.1        mw }
    606   1.1        mw 
    607   1.1        mw 
    608  1.19        is #ifdef DRACO
    609  1.19        is void
    610  1.19        is drkbdintr()
    611   1.1        mw {
    612  1.19        is 	u_char in;
    613  1.19        is 	struct kbd_softc *k = &kbd_softc;
    614  1.18     veego 
    615  1.19        is 	in = draco_ioct->io_kbddata;
    616  1.19        is 	draco_ioct->io_kbdrst = 0;
    617   1.1        mw 
    618  1.19        is 	if (in == 0xF0)
    619  1.19        is 		k->k_rlprfx = 0x80;
    620  1.19        is 	else {
    621  1.19        is 		kbdstuffchar(in>=sizeof(drkbdtab) ? 0xff :
    622  1.19        is 		    drkbdtab[in] | k->k_rlprfx);
    623  1.19        is 		k->k_rlprfx = 0;
    624  1.19        is 	}
    625  1.19        is }
    626   1.1        mw 
    627  1.19        is #endif
    628