kbd.c revision 1.3 1 1.1 mw /*
2 1.1 mw * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
3 1.1 mw * All rights reserved.
4 1.1 mw *
5 1.1 mw * Redistribution and use in source and binary forms, with or without
6 1.1 mw * modification, are permitted provided that the following conditions
7 1.1 mw * are met:
8 1.1 mw * 1. Redistributions of source code must retain the above copyright
9 1.1 mw * notice, this list of conditions and the following disclaimer.
10 1.1 mw * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 mw * notice, this list of conditions and the following disclaimer in the
12 1.1 mw * documentation and/or other materials provided with the distribution.
13 1.1 mw * 3. All advertising materials mentioning features or use of this software
14 1.1 mw * must display the following acknowledgement:
15 1.1 mw * This product includes software developed by the University of
16 1.1 mw * California, Berkeley and its contributors.
17 1.1 mw * 4. Neither the name of the University nor the names of its contributors
18 1.1 mw * may be used to endorse or promote products derived from this software
19 1.1 mw * without specific prior written permission.
20 1.1 mw *
21 1.1 mw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1 mw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 mw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 mw * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1 mw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 mw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 mw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 mw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 mw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 mw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 mw * SUCH DAMAGE.
32 1.1 mw *
33 1.3 mw * $Id: kbd.c,v 1.3 1993/09/02 18:08:06 mw Exp $
34 1.1 mw */
35 1.1 mw
36 1.1 mw #include "ite.h"
37 1.1 mw
38 1.1 mw #if NITE > 0
39 1.1 mw #include "sys/param.h"
40 1.1 mw #include "sys/systm.h"
41 1.1 mw #include "sys/ioctl.h"
42 1.1 mw #include "sys/tty.h"
43 1.1 mw #include "sys/proc.h"
44 1.1 mw #include "sys/conf.h"
45 1.1 mw #include "sys/file.h"
46 1.1 mw #include "sys/uio.h"
47 1.1 mw #include "sys/kernel.h"
48 1.1 mw #include "sys/syslog.h"
49 1.1 mw
50 1.1 mw #include "device.h"
51 1.1 mw #include "kbdreg.h"
52 1.1 mw #include "itevar.h"
53 1.1 mw #include "machine/cpu.h"
54 1.1 mw
55 1.1 mw #include "../amiga/custom.h"
56 1.1 mw #include "../amiga/cia.h"
57 1.1 mw
58 1.1 mw void
59 1.1 mw kbdenable ()
60 1.1 mw {
61 1.1 mw int s = spltty();
62 1.1 mw
63 1.1 mw /* collides with external ints from SCSI, watch out for this when
64 1.1 mw enabling/disabling interrupts there !! */
65 1.1 mw custom.intena = INTF_SETCLR | INTF_PORTS;
66 1.3 mw ciaa.icr = CIA_ICR_IR_SC | CIA_ICR_SP; /* SP interrupt enable */
67 1.1 mw ciaa.cra &= ~(1<<6); /* serial line == input */
68 1.1 mw
69 1.1 mw splx (s);
70 1.1 mw }
71 1.1 mw
72 1.1 mw
73 1.1 mw int
74 1.3 mw kbdintr (mask)
75 1.3 mw int mask;
76 1.1 mw {
77 1.1 mw u_char c, in;
78 1.1 mw
79 1.3 mw /* now only invoked from generic CIA interrupt handler if there *is*
80 1.3 mw a keyboard interrupt pending */
81 1.1 mw
82 1.1 mw in = ciaa.sdr;
83 1.1 mw /* ack */
84 1.1 mw ciaa.cra |= (1 << 6); /* serial line output */
85 1.1 mw /* wait 85 microseconds */
86 1.1 mw DELAY(85);
87 1.1 mw ciaa.cra &= ~(1 << 6);
88 1.1 mw
89 1.1 mw c = ~in; /* keyboard data is inverted */
90 1.1 mw
91 1.1 mw /* process the character.
92 1.1 mw
93 1.1 mw Should implement RAW mode for X11 later here !! */
94 1.1 mw c = (c >> 1) | (c << 7); /* rotate right once */
95 1.1 mw
96 1.1 mw itefilter (c, ITEFILT_TTY);
97 1.3 mw
98 1.3 mw /* XXX THIS IS WRONG!!! The screenblanker should route thru ite.c, which
99 1.3 mw should call thru it's driver table, ie. we need a new driver-dependant
100 1.3 mw function for this feature! */
101 1.3 mw cc_unblank ();
102 1.1 mw }
103 1.1 mw
104 1.1 mw
105 1.1 mw int
106 1.1 mw kbdbell()
107 1.1 mw {
108 1.3 mw /* nice, mykes provided audio-support! */
109 1.3 mw cc_bell ();
110 1.1 mw }
111 1.1 mw
112 1.1 mw
113 1.1 mw int
114 1.1 mw kbdgetcn ()
115 1.1 mw {
116 1.1 mw int s = spltty ();
117 1.3 mw u_char ints, mask, c, in;
118 1.1 mw
119 1.3 mw for (ints = 0; ! ((mask = ciaa.icr) & CIA_ICR_SP); ints |= mask) ;
120 1.1 mw
121 1.1 mw in = ciaa.sdr;
122 1.1 mw c = ~in;
123 1.1 mw
124 1.1 mw /* ack */
125 1.1 mw ciaa.cra |= (1 << 6); /* serial line output */
126 1.1 mw ciaa.sdr = 0xff; /* ack */
127 1.1 mw /* wait 85 microseconds */
128 1.1 mw DELAY(85); /* XXXX only works as long as DELAY doesn't use a timer and waits.. */
129 1.1 mw ciaa.cra &= ~(1 << 6);
130 1.1 mw ciaa.sdr = in;
131 1.1 mw
132 1.1 mw splx (s);
133 1.1 mw c = (c >> 1) | (c << 7);
134 1.3 mw
135 1.3 mw /* take care that no CIA-interrupts are lost */
136 1.3 mw if (mask)
137 1.3 mw dispatch_cia_ints (0, mask);
138 1.3 mw
139 1.1 mw return c;
140 1.1 mw }
141 1.1 mw
142 1.1 mw #endif
143