Home | History | Annotate | Line # | Download | only in dev
kbd.c revision 1.31
      1  1.31        is /*	$NetBSD: kbd.c,v 1.31 1998/02/28 21:53: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.31        is 		/*draco_ioct->io_control &= ~DRCNTRL_KBDKBDACK;*/
    179  1.31        is 		printf("ioctrl: 0x%02x, iostat: 0x%02x\n",
    180  1.31        is 			draco_ioct->io_control, draco_ioct->io_status);
    181  1.19        is 
    182  1.31        is 		ciaa.icr = CIA_ICR_SP;  /* CIA SP interrupt disable */
    183  1.31        is 		ciaa.cra &= ~(1<<6);	/* serial line == input */
    184  1.31        is 		splx(s);
    185  1.31        is 		return;
    186  1.19        is 
    187  1.31        is 	LnoMFII:
    188  1.31        is 		kbd_softc.k_mf2 = 0;
    189  1.31        is 		*draco_intena |= DRIRQ_INT2;
    190  1.31        is 		ciaa.icr = CIA_ICR_IR_SC | CIA_ICR_SP;
    191  1.31        is 					/* SP interrupt enable */
    192  1.31        is 		ciaa.cra &= ~(1<<6);	/* serial line == input */
    193  1.31        is 		splx(s);
    194  1.31        is 		return;
    195  1.31        is 
    196  1.31        is 	} else {
    197  1.31        is #endif
    198   1.9    chopps 	custom.intena = INTF_SETCLR | INTF_PORTS;
    199   1.9    chopps 	ciaa.icr = CIA_ICR_IR_SC | CIA_ICR_SP;  /* SP interrupt enable */
    200   1.9    chopps 	ciaa.cra &= ~(1<<6);		/* serial line == input */
    201  1.31        is #ifdef DRACO
    202  1.31        is 	}
    203  1.19        is #endif
    204   1.9    chopps 	kbd_softc.k_event_mode = 0;
    205   1.9    chopps 	kbd_softc.k_events.ev_io = 0;
    206   1.9    chopps 	splx(s);
    207   1.1        mw }
    208   1.1        mw 
    209  1.31        is /*
    210  1.31        is  * call this with kbd interupt blocked
    211  1.31        is  */
    212  1.31        is 
    213  1.31        is int
    214  1.31        is drkbdgetc()
    215  1.31        is {
    216  1.31        is 	u_int8_t in;
    217  1.31        is 
    218  1.31        is 	while ((draco_ioct->io_status & DRSTAT_KBDRECV) == 0);
    219  1.31        is 	in = draco_ioct->io_kbddata;
    220  1.31        is 	draco_ioct->io_kbdrst = 0;
    221  1.31        is 
    222  1.31        is 	return in;
    223  1.31        is }
    224  1.31        is 
    225  1.31        is #define WAIT0 if (drkbdwaitfor(0)) goto Ltimeout
    226  1.31        is #define WAIT1 if (drkbdwaitfor(DRSTAT_KBDCLKIN)) goto Ltimeout
    227  1.31        is 
    228  1.31        is int
    229  1.31        is drkbdwaitfor(bit)
    230  1.31        is 	int bit;
    231  1.31        is {
    232  1.31        is 	int i;
    233  1.31        is 
    234  1.31        is 
    235  1.31        is 
    236  1.31        is 	i = 60000;	/* about 50 ms max */
    237  1.31        is 
    238  1.31        is 	do {
    239  1.31        is 		if ((draco_ioct->io_status & DRSTAT_KBDCLKIN) == bit)
    240  1.31        is 			return 0;
    241  1.31        is 
    242  1.31        is 	} while (--i >= 0);
    243  1.31        is 
    244  1.31        is 	return 1;
    245  1.31        is }
    246  1.31        is 
    247  1.31        is /*
    248  1.31        is  * Output a raw byte to the keyboard (+ parity and stop bit).
    249  1.31        is  * return 0 on success, 1 on timeout.
    250  1.31        is  */
    251  1.31        is int
    252  1.31        is drkbdrputc(c)
    253  1.31        is 	u_int8_t c;
    254  1.31        is {
    255  1.31        is 	u_int8_t parity;
    256  1.31        is 	int bitcnt;
    257  1.31        is 
    258  1.31        is 	DATLO; CLKHI; WAIT1;
    259  1.31        is 	parity = 0;
    260  1.31        is 
    261  1.31        is 	for (bitcnt=7; bitcnt >= 0; bitcnt--) {
    262  1.31        is 		WAIT0;
    263  1.31        is 		if (c & 1) {
    264  1.31        is 			DATHI;
    265  1.31        is 		} else {
    266  1.31        is 			++parity;
    267  1.31        is 			DATLO;
    268  1.31        is 		}
    269  1.31        is 		c >>= 1;
    270  1.31        is 		WAIT1;
    271  1.31        is 	}
    272  1.31        is 	WAIT0;
    273  1.31        is 	/* parity bit */
    274  1.31        is 	if (parity & 1) {
    275  1.31        is 		DATLO;
    276  1.31        is 	} else {
    277  1.31        is 		DATHI;
    278  1.31        is 	}
    279  1.31        is 	WAIT1;
    280  1.31        is 	/* stop bit */
    281  1.31        is 	WAIT0; DATHI; WAIT1;
    282  1.31        is 
    283  1.31        is 	WAIT0; /* XXX should check the ack bit here... */
    284  1.31        is 	WAIT1;
    285  1.31        is 	draco_ioct->io_kbdrst = 0;
    286  1.31        is 	return 0;
    287  1.31        is 
    288  1.31        is Ltimeout:
    289  1.31        is 	DATHI;
    290  1.31        is 	draco_ioct->io_kbdrst = 0;
    291  1.31        is 	return 1;
    292  1.31        is }
    293  1.31        is 
    294  1.31        is /*
    295  1.31        is  * Output one cooked byte to the keyboard, with wait for ACK or RESEND,
    296  1.31        is  * and retry if necessary. 0 == success, 1 == timeout
    297  1.31        is  */
    298  1.31        is int
    299  1.31        is drkbdputc(c)
    300  1.31        is 	u_int8_t c;
    301  1.31        is {
    302  1.31        is 	int rc;
    303  1.31        is 
    304  1.31        is 	do {
    305  1.31        is 		if (drkbdrputc(c))
    306  1.31        is 			return(-1);
    307  1.31        is 
    308  1.31        is 		rc = drkbdgetc();
    309  1.31        is 	} while (rc == 0xfe);
    310  1.31        is 	return (!(rc == 0xfa));
    311  1.31        is }
    312  1.31        is 
    313  1.31        is /*
    314  1.31        is  * same for twobyte sequence
    315  1.31        is  */
    316  1.31        is 
    317  1.31        is int
    318  1.31        is drkbdputc2(c1, c2)
    319  1.31        is 	u_int8_t c1, c2;
    320  1.31        is {
    321  1.31        is 	int rc;
    322  1.31        is 
    323  1.31        is 	do {
    324  1.31        is 		do {
    325  1.31        is 			if (drkbdrputc(c1))
    326  1.31        is 				return(-1);
    327  1.31        is 
    328  1.31        is 			rc = drkbdgetc();
    329  1.31        is 		} while (rc == 0xfe);
    330  1.31        is 		if (rc != 0xfa)
    331  1.31        is 			return (-1);
    332  1.31        is 
    333  1.31        is 		if (drkbdrputc(c2))
    334  1.31        is 			return(-1);
    335  1.31        is 
    336  1.31        is 		rc = drkbdgetc();
    337  1.31        is 	} while (rc == 0xfe);
    338  1.31        is 	return (!(rc == 0xfa));
    339  1.31        is }
    340   1.1        mw 
    341   1.1        mw int
    342  1.18     veego kbdopen(dev, flags, mode, p)
    343  1.18     veego 	dev_t dev;
    344  1.18     veego 	int flags, mode;
    345  1.18     veego 	struct proc *p;
    346   1.5        mw {
    347   1.5        mw 
    348  1.30        is 	kbdenable();
    349  1.18     veego 	if (kbd_softc.k_events.ev_io)
    350  1.18     veego 		return EBUSY;
    351   1.5        mw 
    352  1.18     veego 	kbd_softc.k_events.ev_io = p;
    353  1.18     veego 	ev_init(&kbd_softc.k_events);
    354  1.18     veego 	return (0);
    355   1.5        mw }
    356   1.5        mw 
    357   1.5        mw int
    358  1.18     veego kbdclose(dev, flags, mode, p)
    359  1.18     veego 	dev_t dev;
    360  1.18     veego 	int flags, mode;
    361  1.18     veego 	struct proc *p;
    362   1.5        mw {
    363  1.18     veego 
    364  1.18     veego 	/* Turn off event mode, dump the queue */
    365  1.18     veego 	kbd_softc.k_event_mode = 0;
    366  1.18     veego 	ev_fini(&kbd_softc.k_events);
    367  1.18     veego 	kbd_softc.k_events.ev_io = NULL;
    368  1.18     veego 	return (0);
    369   1.5        mw }
    370   1.5        mw 
    371   1.5        mw int
    372  1.18     veego kbdread(dev, uio, flags)
    373  1.18     veego 	dev_t dev;
    374  1.18     veego 	struct uio *uio;
    375  1.18     veego 	int flags;
    376   1.5        mw {
    377  1.18     veego 	return ev_read (&kbd_softc.k_events, uio, flags);
    378   1.5        mw }
    379   1.5        mw 
    380   1.5        mw int
    381  1.18     veego kbdioctl(dev, cmd, data, flag, p)
    382  1.18     veego 	dev_t dev;
    383  1.18     veego 	u_long cmd;
    384  1.18     veego 	register caddr_t data;
    385  1.18     veego 	int flag;
    386  1.18     veego 	struct proc *p;
    387   1.5        mw {
    388  1.18     veego 	register struct kbd_softc *k = &kbd_softc;
    389  1.18     veego 
    390  1.18     veego 	switch (cmd) {
    391  1.18     veego 		case KIOCTRANS:
    392  1.18     veego 			if (*(int *)data == TR_UNTRANS_EVENT)
    393  1.18     veego 				return 0;
    394  1.18     veego 			break;
    395  1.18     veego 
    396  1.18     veego 		case KIOCGTRANS:
    397  1.18     veego 			/* Get translation mode */
    398  1.18     veego 			*(int *)data = TR_UNTRANS_EVENT;
    399  1.18     veego 			return 0;
    400  1.18     veego 
    401  1.18     veego 		case KIOCSDIRECT:
    402  1.18     veego 			k->k_event_mode = *(int *)data;
    403  1.18     veego 			return 0;
    404  1.18     veego 
    405  1.18     veego 		case FIONBIO:	/* we will remove this someday (soon???) */
    406  1.18     veego 			return 0;
    407  1.18     veego 
    408  1.18     veego 		case FIOASYNC:
    409  1.18     veego 			k->k_events.ev_async = *(int *)data != 0;
    410  1.18     veego 			return 0;
    411  1.18     veego 
    412  1.18     veego 		case TIOCSPGRP:
    413  1.18     veego 			if (*(int *)data != k->k_events.ev_io->p_pgid)
    414  1.18     veego 				return EPERM;
    415  1.18     veego 			return 0;
    416  1.18     veego 
    417  1.18     veego 		default:
    418  1.18     veego 			return ENOTTY;
    419  1.18     veego 	}
    420   1.5        mw 
    421  1.18     veego 	/* We identified the ioctl, but we do not handle it. */
    422  1.18     veego 	return EOPNOTSUPP;	/* misuse, but what the heck */
    423   1.5        mw }
    424   1.5        mw 
    425   1.5        mw int
    426  1.25    mhitch kbdpoll(dev, events, p)
    427  1.18     veego 	dev_t dev;
    428  1.25    mhitch 	int events;
    429  1.18     veego 	struct proc *p;
    430   1.5        mw {
    431  1.25    mhitch 	return ev_poll (&kbd_softc.k_events, events, p);
    432   1.5        mw }
    433   1.5        mw 
    434   1.5        mw 
    435  1.18     veego void
    436  1.18     veego kbdintr(mask)
    437  1.18     veego 	int mask;
    438   1.1        mw {
    439  1.18     veego 	u_char c;
    440  1.13    chopps #ifdef KBDRESET
    441  1.18     veego 	static int reset_warn;
    442  1.13    chopps #endif
    443   1.1        mw 
    444  1.19        is 	/*
    445  1.19        is 	 * now only invoked from generic CIA interrupt handler if there *is*
    446  1.18     veego 	 * a keyboard interrupt pending
    447  1.18     veego 	 */
    448   1.1        mw 
    449  1.18     veego 	c = ~ciaa.sdr;	/* keyboard data is inverted */
    450  1.18     veego 	/* ack */
    451  1.18     veego 	ciaa.cra |= (1 << 6);	/* serial line output */
    452  1.13    chopps #ifdef KBDRESET
    453  1.18     veego 	if (reset_warn && c == 0xf0) {
    454  1.13    chopps #ifdef DEBUG
    455  1.26  christos 		printf ("kbdintr: !!!! Reset Warning !!!!\n");
    456  1.13    chopps #endif
    457  1.18     veego 		bootsync();
    458  1.18     veego 		reset_warn = 0;
    459  1.18     veego 		DELAY(30000000);
    460  1.18     veego 	}
    461  1.13    chopps #endif
    462  1.18     veego 	/* wait 200 microseconds (for bloody Cherry keyboards..) */
    463  1.18     veego 	DELAY(2000);			/* fudge delay a bit for some keyboards */
    464  1.18     veego 	ciaa.cra &= ~(1 << 6);
    465  1.18     veego 
    466  1.18     veego 	/* process the character */
    467  1.18     veego 	c = (c >> 1) | (c << 7);	/* rotate right once */
    468   1.1        mw 
    469  1.13    chopps #ifdef KBDRESET
    470  1.18     veego 	if (c == 0x78) {
    471  1.13    chopps #ifdef DEBUG
    472  1.26  christos 		printf ("kbdintr: Reset Warning started\n");
    473  1.13    chopps #endif
    474  1.18     veego 		++reset_warn;
    475  1.18     veego 		return;
    476  1.18     veego 	}
    477  1.13    chopps #endif
    478  1.19        is 	kbdstuffchar(c);
    479  1.19        is }
    480  1.19        is 
    481  1.19        is #ifdef DRACO
    482  1.19        is /* maps MF-II keycodes to Amiga keycodes */
    483  1.19        is 
    484  1.27        is const u_char drkbdtab[] = {
    485  1.19        is 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x50,
    486  1.19        is 	0x45, 0xff, 0xff, 0xff, 0xff, 0x42, 0x00, 0x51,
    487  1.19        is 
    488  1.19        is 	0xff, 0x64, 0x60, 0x30, 0x63, 0x10, 0x01, 0x52,
    489  1.19        is 	0xff, 0x66, 0x31, 0x21, 0x20, 0x11, 0x02, 0x53,
    490  1.19        is 
    491  1.19        is 	0xff, 0x33, 0x32, 0x22, 0x12, 0x04, 0x03, 0x54,
    492  1.19        is 	0xff, 0x40, 0x34, 0x23, 0x14, 0x13, 0x05, 0x55,
    493  1.19        is 
    494  1.19        is 	0xff, 0x36, 0x35, 0x25, 0x24, 0x15, 0x06, 0x56,
    495  1.19        is 	0xff, 0x67, 0x37, 0x26, 0x16, 0x07, 0x08, 0x57,
    496  1.19        is 	/* --- */
    497  1.19        is 	0xff, 0x38, 0x27, 0x17, 0x18, 0x0a, 0x09, 0x58,
    498  1.19        is 	0xff, 0x39, 0x3a, 0x28, 0x29, 0x19, 0x0b, 0x59,
    499  1.19        is 
    500  1.19        is 	0xff, 0xff, 0x2a, 0x2b, 0x1a, 0x0c, 0x4b, 0xff,
    501  1.19        is 	0x65, 0x61, 0x44, 0x1b, 0xff, 0xff, 0x6f, 0xff,
    502  1.19        is 
    503  1.19        is 	0x4d, 0x4f, 0xff, 0x4c, 0x0d, 0xff, 0x41, 0x46,
    504  1.19        is 	0xff, 0x1d, 0x4e, 0x2d, 0x3d, 0x4a, 0x5f, 0x62,
    505  1.19        is 
    506  1.19        is 	0x0f, 0x3c, 0x1e, 0x2e, 0x2f, 0x3e, 0x5a, 0x5b,
    507  1.19        is 	0xff, 0x43, 0x1f, 0xff, 0x5e, 0x3f, 0x5c, 0xff,
    508  1.19        is 	/* --- */
    509  1.19        is 	0xff, 0xff, 0xff, 0xff, 0x5d
    510  1.19        is };
    511  1.19        is #endif
    512  1.19        is 
    513  1.19        is 
    514  1.19        is int
    515  1.19        is kbdgetcn ()
    516  1.19        is {
    517  1.19        is 	int s;
    518  1.19        is 	u_char ints, mask, c, in;
    519  1.19        is 
    520  1.19        is #ifdef DRACO
    521  1.19        is 	/*
    522  1.19        is 	 * XXX todo: if CIA DraCo, get from cia if cia kbd
    523  1.19        is 	 * installed.
    524  1.19        is 	 */
    525  1.31        is 	if (is_draco() && kbd_softc.k_mf2) {
    526  1.31        is 		do {
    527  1.31        is 			c = 0;
    528  1.31        is 			s = spltty ();
    529  1.19        is 			while ((draco_ioct->io_status & DRSTAT_KBDRECV) == 0);
    530  1.19        is 			in = draco_ioct->io_kbddata;
    531  1.19        is 			draco_ioct->io_kbdrst = 0;
    532  1.31        is 			if (in == 0xF0) { /* release prefix */
    533  1.31        is 				c = 0x80;
    534  1.31        is 				while ((draco_ioct->io_status & DRSTAT_KBDRECV) == 0);
    535  1.31        is 				in = draco_ioct->io_kbddata;
    536  1.31        is 				draco_ioct->io_kbdrst = 0;
    537  1.31        is 			}
    538  1.31        is 			splx(s);
    539  1.19        is #ifdef DRACORAWKEYDEBUG
    540  1.31        is 			printf("<%02x>", in);
    541  1.19        is #endif
    542  1.31        is 			c |= in>=sizeof(drkbdtab) ? 0xff : drkbdtab[in];
    543  1.31        is 		} while (c == 0xff);
    544  1.31        is 		return (c);
    545  1.19        is 	}
    546  1.19        is #endif
    547  1.19        is 	s = spltty();
    548  1.19        is 	for (ints = 0; ! ((mask = ciaa.icr) & CIA_ICR_SP);
    549  1.19        is 	    ints |= mask) ;
    550  1.19        is 
    551  1.19        is 	in = ciaa.sdr;
    552  1.19        is 	c = ~in;
    553  1.19        is 
    554  1.19        is 	/* ack */
    555  1.19        is 	ciaa.cra |= (1 << 6);	/* serial line output */
    556  1.19        is 	ciaa.sdr = 0xff;	/* ack */
    557  1.19        is 	/* wait 200 microseconds */
    558  1.19        is 	DELAY(2000);	/* XXXX only works as long as DELAY doesn't
    559  1.19        is 			 * use a timer and waits.. */
    560  1.19        is 	ciaa.cra &= ~(1 << 6);
    561  1.19        is 	ciaa.sdr = in;
    562  1.19        is 
    563  1.19        is 	splx (s);
    564  1.19        is 	c = (c >> 1) | (c << 7);
    565  1.19        is 
    566  1.19        is 	/* take care that no CIA-interrupts are lost */
    567  1.19        is 	if (ints)
    568  1.19        is 		dispatch_cia_ints (0, ints);
    569  1.19        is 
    570  1.19        is 	return c;
    571  1.19        is }
    572  1.19        is 
    573  1.19        is void
    574  1.19        is kbdstuffchar(c)
    575  1.19        is 	u_char c;
    576  1.19        is {
    577  1.19        is 	struct firm_event *fe;
    578  1.19        is 	struct kbd_softc *k = &kbd_softc;
    579  1.19        is 	int put;
    580  1.19        is 
    581  1.19        is 	/*
    582  1.19        is 	 * If not in event mode, deliver straight to ite to process
    583  1.19        is 	 * key stroke
    584  1.19        is 	 */
    585  1.19        is 
    586  1.18     veego 	if (! k->k_event_mode) {
    587  1.18     veego 		ite_filter (c, ITEFILT_TTY);
    588  1.18     veego 		return;
    589  1.18     veego 	}
    590  1.18     veego 
    591  1.19        is 	/*
    592  1.19        is 	 * Keyboard is generating events. Turn this keystroke into an
    593  1.19        is 	 * event and put it in the queue. If the queue is full, the
    594  1.18     veego 	 * keystroke is lost (sorry!).
    595  1.18     veego 	 */
    596  1.19        is 
    597  1.18     veego 	put = k->k_events.ev_put;
    598  1.18     veego 	fe = &k->k_events.ev_q[put];
    599  1.18     veego 	put = (put + 1) % EV_QSIZE;
    600  1.18     veego 	if (put == k->k_events.ev_get) {
    601  1.19        is 		log(LOG_WARNING, "keyboard event queue overflow\n");
    602  1.19        is 			/* ??? */
    603  1.18     veego 		return;
    604  1.18     veego 	}
    605  1.18     veego 	fe->id = KEY_CODE(c);
    606  1.18     veego 	fe->value = KEY_UP(c) ? VKEY_UP : VKEY_DOWN;
    607  1.18     veego 	fe->time = time;
    608  1.18     veego 	k->k_events.ev_put = put;
    609  1.18     veego 	EV_WAKEUP(&k->k_events);
    610   1.1        mw }
    611   1.1        mw 
    612   1.1        mw 
    613  1.19        is #ifdef DRACO
    614  1.19        is void
    615  1.19        is drkbdintr()
    616   1.1        mw {
    617  1.19        is 	u_char in;
    618  1.19        is 	struct kbd_softc *k = &kbd_softc;
    619  1.18     veego 
    620  1.19        is 	in = draco_ioct->io_kbddata;
    621  1.19        is 	draco_ioct->io_kbdrst = 0;
    622   1.1        mw 
    623  1.19        is 	if (in == 0xF0)
    624  1.19        is 		k->k_rlprfx = 0x80;
    625  1.19        is 	else {
    626  1.19        is 		kbdstuffchar(in>=sizeof(drkbdtab) ? 0xff :
    627  1.19        is 		    drkbdtab[in] | k->k_rlprfx);
    628  1.19        is 		k->k_rlprfx = 0;
    629  1.19        is 	}
    630  1.19        is }
    631   1.1        mw 
    632  1.19        is #endif
    633