Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * This code is derived from software contributed to Berkeley by | |
6 | * William Jolitz. | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | |
15 | * documentation and/or other materials provided with the distribution. | |
16 | * 3. All advertising materials mentioning features or use of this software | |
17 | * must display the following acknowledgement: | |
18 | * This product includes software developed by the University of | |
19 | * California, Berkeley and its contributors. | |
20 | * 4. Neither the name of the University nor the names of its contributors | |
21 | * may be used to endorse or promote products derived from this software | |
22 | * without specific prior written permission. | |
23 | * | |
24 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
34 | * SUCH DAMAGE. | |
35 | * | |
36 | * @(#)kbd.c 7.4 (Berkeley) 5/4/91 | |
37 | */ | |
38 | ||
39 | #define L 0x01 /* locking function */ | |
40 | #define SHF 0x02 /* keyboard shift */ | |
41 | #define ALT 0x04 /* alternate shift -- alternate chars */ | |
42 | #define NUM 0x08 /* numeric shift cursors vs. numeric */ | |
43 | #define CTL 0x10 /* control shift -- allows ctl function */ | |
44 | #define CPS 0x20 /* caps shift -- swaps case of letter */ | |
45 | #define ASCII 0x40 /* ascii code for this key */ | |
46 | #define STP 0x80 /* stop output */ | |
47 | ||
48 | typedef unsigned char u_char; | |
49 | ||
50 | u_char inb(); | |
51 | ||
52 | #ifdef notdef | |
53 | u_char action[] = { | |
54 | 0, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, /* scan 0- 7 */ | |
55 | ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, /* scan 8-15 */ | |
56 | ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, /* scan 16-23 */ | |
57 | ASCII, ASCII, ASCII, ASCII, ASCII, CTL, ASCII, ASCII, /* scan 24-31 */ | |
58 | ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, /* scan 32-39 */ | |
59 | ASCII, ASCII, SHF , ASCII, ASCII, ASCII, ASCII, ASCII, /* scan 40-47 */ | |
60 | ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, SHF, ASCII, /* scan 48-55 */ | |
61 | ALT, ASCII, CPS|L, 0, 0, ASCII, 0, 0, /* scan 56-63 */ | |
62 | 0, 0, 0, 0, 0, NUM|L, STP|L, ASCII, /* scan 64-71 */ | |
63 | ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, /* scan 72-79 */ | |
64 | ASCII, ASCII, ASCII, ASCII, 0, 0, 0, 0, /* scan 80-87 */ | |
65 | 0,0,0,0,0,0,0,0, | |
66 | 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, | |
67 | 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, } ; | |
68 | ||
69 | u_char unshift[] = { /* no shift */ | |
70 | 0, 033 , '1' , '2' , '3' , '4' , '5' , '6' , /* scan 0- 7 */ | |
71 | '7' , '8' , '9' , '0' , '-' , '=' , 0177 ,'\t' , /* scan 8-15 */ | |
72 | ||
73 | 'q' , 'w' , 'e' , 'r' , 't' , 'y' , 'u' , 'i' , /* scan 16-23 */ | |
74 | 'o' , 'p' , '[' , ']' , '\r' , CTL , 'a' , 's' , /* scan 24-31 */ | |
75 | ||
76 | 'd' , 'f' , 'g' , 'h' , 'j' , 'k' , 'l' , ';' , /* scan 32-39 */ | |
77 | '\'' , '`' , SHF , '\\' , 'z' , 'x' , 'c' , 'v' , /* scan 40-47 */ | |
78 | ||
79 | 'b' , 'n' , 'm' , ',' , '.' , '/' , SHF , '*', /* scan 48-55 */ | |
80 | ALT , ' ' , CPS|L, 0, 0, ' ' , 0, 0, /* scan 56-63 */ | |
81 | ||
82 | 0, 0, 0, 0, 0, NUM|L, STP|L, '7', /* scan 64-71 */ | |
83 | '8', '9', '-', '4', '5', '6', '+', '1', /* scan 72-79 */ | |
84 | ||
85 | '2', '3', '0', '.', 0, 0, 0, 0, /* scan 80-87 */ | |
86 | 0,0,0,0,0,0,0,0, | |
87 | 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, | |
88 | 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, } ; | |
89 | ||
90 | u_char shift[] = { /* shift shift */ | |
91 | 0, 033 , '!' , '@' , '#' , '$' , '%' , '^' , /* scan 0- 7 */ | |
92 | '&' , '*' , '(' , ')' , '_' , '+' , 0177 ,'\t' , /* scan 8-15 */ | |
93 | 'Q' , 'W' , 'E' , 'R' , 'T' , 'Y' , 'U' , 'I' , /* scan 16-23 */ | |
94 | 'O' , 'P' , '[' , ']' , '\r' , CTL , 'A' , 'S' , /* scan 24-31 */ | |
95 | 'D' , 'F' , 'G' , 'H' , 'J' , 'K' , 'L' , ':' , /* scan 32-39 */ | |
96 | '"' , '~' , SHF , '|' , 'Z' , 'X' , 'C' , 'V' , /* scan 40-47 */ | |
97 | 'B' , 'N' , 'M' , '<' , '>' , '?' , SHF , '*', /* scan 48-55 */ | |
98 | ALT , ' ' , CPS|L, 0, 0, ' ' , 0, 0, /* scan 56-63 */ | |
99 | 0, 0, 0, 0, 0, NUM|L, STP|L, '7', /* scan 64-71 */ | |
100 | '8', '9', '-', '4', '5', '6', '+', '1', /* scan 72-79 */ | |
101 | '2', '3', '0', '.', 0, 0, 0, 0, /* scan 80-87 */ | |
102 | 0,0,0,0,0,0,0,0, | |
103 | 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, | |
104 | 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, } ; | |
105 | ||
106 | u_char ctl[] = { /* CTL shift */ | |
107 | 0, 033 , '!' , 000 , '#' , '$' , '%' , 036 , /* scan 0- 7 */ | |
108 | '&' , '*' , '(' , ')' , 037 , '+' , 034 ,'\177', /* scan 8-15 */ | |
109 | 021 , 027 , 005 , 022 , 024 , 031 , 025 , 011 , /* scan 16-23 */ | |
110 | 017 , 020 , 033 , 035 , '\r' , CTL , 001 , 013 , /* scan 24-31 */ | |
111 | 004 , 006 , 007 , 010 , 012 , 013 , 014 , ';' , /* scan 32-39 */ | |
112 | '\'' , '`' , SHF , 034 , 032 , 030 , 003 , 026 , /* scan 40-47 */ | |
113 | 002 , 016 , 015 , '<' , '>' , '?' , SHF , '*', /* scan 48-55 */ | |
114 | ALT , ' ' , CPS|L, 0, 0, ' ' , 0, 0, /* scan 56-63 */ | |
115 | CPS|L, 0, 0, 0, 0, 0, 0, 0, /* scan 64-71 */ | |
116 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 72-79 */ | |
117 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 80-87 */ | |
118 | 0, 0, 033, '7' , '4' , '1' , 0, NUM|L, /* scan 88-95 */ | |
119 | '8' , '5' , '2' , 0, STP|L, '9' , '6' , '3' , /*scan 96-103*/ | |
120 | '.' , 0, '*' , '-' , '+' , 0, 0, 0, /*scan 104-111*/ | |
121 | 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, } ; | |
122 | ||
123 | #ifdef notdef | |
124 | struct key { | |
125 | u_short action; /* how this key functions */ | |
126 | char ascii[8]; /* ascii result character indexed by shifts */ | |
127 | }; | |
128 | #endif | |
129 | ||
130 | u_char shfts, ctls, alts, caps, num, stp; | |
131 | #endif | |
132 | ||
133 | #define KBSTATP 0x64 /* kbd status port */ | |
134 | #define KBS_INP_BUF_FUL 0x02 /* kbd char ready */ | |
135 | #define KBDATAP 0x60 /* kbd data port */ | |
136 | #define KBSTATUSPORT 0x61 /* kbd status */ | |
137 | ||
138 | u_char odt, bdt; | |
139 | ||
140 | u_char kbd() { | |
141 | u_char dt, brk, act; | |
142 | ||
143 | loop: | |
144 | while(inb(0x64)&1 == 0); | |
145 | dt = inb(0x60); | |
146 | do { | |
147 | while(inb(0x64)&1 == 0); | |
148 | } while(dt == inb(0x60)); | |
149 | odt = dt; | |
150 | ||
151 | brk = dt & 0x80 ; dt = dt & 0x7f ; | |
152 | ||
153 | #ifdef notdef | |
154 | act = action[dt]; | |
155 | if (act&SHF) { | |
156 | if(brk) shfts = 0; else shfts = 1; | |
157 | } | |
158 | if (act&ALT) { | |
159 | if(brk) alts = 0; else alts = 1; | |
160 | } | |
161 | if (act&NUM) { | |
162 | if (act&L) { | |
163 | if(!brk) num ^= 1; | |
164 | } else if(brk) num = 0; else num = 1; | |
165 | } | |
166 | if (act&CTL) { | |
167 | if(brk) ctls = 0; else ctls = 1; | |
168 | } | |
169 | if (act&CPS) { | |
170 | if (act&L) { | |
171 | if(!brk) caps ^= 1; | |
172 | } else if(brk) caps = 0; else caps = 1; | |
173 | } | |
174 | if (act&STP) { | |
175 | if (act&L) { | |
176 | if(!brk) stp ^= 1; | |
177 | } else if(brk) stp = 0; else stp = 1; | |
178 | } | |
179 | if(ctls && alts && dt == 83) exit(); | |
180 | if ((act&ASCII) && !brk) { | |
181 | u_char chr; | |
182 | ||
183 | if (shfts){ | |
184 | chr = shift[dt] ; } else { | |
185 | if (ctls) { | |
186 | chr = ctl[dt] ; } else { | |
187 | chr = unshift[dt] ; } } | |
188 | if (caps && (chr >= 'a' && chr <= 'z')) { | |
189 | chr -= 'a' - 'A' ; | |
190 | } | |
191 | /*do | |
192 | while(inb(0x64)&1 == 0) ; | |
193 | while (inb(0x60) == (chr | 0x80)); | |
194 | while(inb(0x64)&1 == 1) inb(0x60);A*/ | |
195 | return(chr); | |
196 | } | |
197 | #else | |
198 | if (brk) | |
199 | return(1); | |
200 | #endif | |
201 | goto loop; | |
202 | } | |
203 | ||
204 | scankbd() { | |
205 | u_char c; | |
206 | ||
207 | #ifdef notdef | |
208 | c = inb(0x60); | |
209 | if (c == 83) exit(); | |
210 | /*if (c == 0xaa) return (0); | |
211 | if (c == 0xfa) return (0);*/ | |
212 | ||
213 | if (bdt == 0) { bdt = c&0x7f; return(0); } | |
214 | ||
215 | if(odt) return(1); | |
216 | ||
217 | c &= 0x7f; | |
218 | ||
219 | if (bdt == c) return(0); | |
220 | odt = c; | |
221 | #endif | |
222 | return(1); | |
223 | } | |
224 | ||
225 | kbdreset() | |
226 | { | |
227 | u_char c; | |
228 | ||
229 | /* Enable interrupts and keyboard controller */ | |
230 | while (inb(0x64)&2); outb(0x64,0x60); | |
231 | while (inb(0x64)&2); outb(0x60,0x4D); | |
232 | ||
233 | /* Start keyboard stuff RESET */ | |
234 | while (inb(0x64)&2); /* wait input ready */ | |
235 | outb(0x60,0xFF); /* RESET */ | |
236 | ||
237 | while((c=inb(0x60))!=0xFA) ; | |
238 | ||
239 | /* While we are here, defeat gatea20 */ | |
240 | while (inb(0x64)&2); /* wait input ready */ | |
241 | outb(0x64,0xd1); | |
242 | while (inb(0x64)&2); /* wait input ready */ | |
243 | outb(0x60,0xdf); | |
244 | while (inb(0x64)&2); /* wait input ready */ | |
245 | odt = bdt = 0; | |
246 | inb(0x60); | |
247 | } | |
248 | ||
249 | #ifdef notdef; | |
250 | u_char getchar() { | |
251 | u_char c; | |
252 | ||
253 | c = kbd(); | |
254 | if (c == '\b' || c == '\177') return(c); | |
255 | if (c == '\r') c = '\n'; | |
256 | putchar(c); | |
257 | return(c); | |
258 | } | |
259 | #endif | |
260 | ||
261 | reset_cpu() { | |
262 | ||
263 | while (inb(0x64)&2); /* wait input ready */ | |
264 | outb(0x64,0xFE); /* Reset Command */ | |
265 | wait(4000000); | |
266 | /* NOTREACHED */ | |
267 | } |