|
|
1.1 root 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: *
1.1.1.4 ! root 36: * from: @(#)kbd.c 7.4 (Berkeley) 5/4/91
! 37: * kbd.c,v 1.2 1993/05/22 08:02:18 cgd Exp
1.1 root 38: */
39:
40: #define L 0x01 /* locking function */
41: #define SHF 0x02 /* keyboard shift */
42: #define ALT 0x04 /* alternate shift -- alternate chars */
43: #define NUM 0x08 /* numeric shift cursors vs. numeric */
44: #define CTL 0x10 /* control shift -- allows ctl function */
45: #define CPS 0x20 /* caps shift -- swaps case of letter */
46: #define ASCII 0x40 /* ascii code for this key */
47: #define STP 0x80 /* stop output */
48:
49: typedef unsigned char u_char;
50:
51: u_char inb();
52:
1.1.1.2 root 53: #ifdef notdef
1.1 root 54: u_char action[] = {
55: 0, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, /* scan 0- 7 */
56: ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, /* scan 8-15 */
57: ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, /* scan 16-23 */
58: ASCII, ASCII, ASCII, ASCII, ASCII, CTL, ASCII, ASCII, /* scan 24-31 */
59: ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, /* scan 32-39 */
60: ASCII, ASCII, SHF , ASCII, ASCII, ASCII, ASCII, ASCII, /* scan 40-47 */
61: ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, SHF, ASCII, /* scan 48-55 */
62: ALT, ASCII, CPS|L, 0, 0, ASCII, 0, 0, /* scan 56-63 */
63: 0, 0, 0, 0, 0, NUM|L, STP|L, ASCII, /* scan 64-71 */
64: ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, /* scan 72-79 */
65: ASCII, ASCII, ASCII, ASCII, 0, 0, 0, 0, /* scan 80-87 */
66: 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: 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, } ;
69:
70: u_char unshift[] = { /* no shift */
71: 0, 033 , '1' , '2' , '3' , '4' , '5' , '6' , /* scan 0- 7 */
72: '7' , '8' , '9' , '0' , '-' , '=' , 0177 ,'\t' , /* scan 8-15 */
73:
74: 'q' , 'w' , 'e' , 'r' , 't' , 'y' , 'u' , 'i' , /* scan 16-23 */
75: 'o' , 'p' , '[' , ']' , '\r' , CTL , 'a' , 's' , /* scan 24-31 */
76:
77: 'd' , 'f' , 'g' , 'h' , 'j' , 'k' , 'l' , ';' , /* scan 32-39 */
78: '\'' , '`' , SHF , '\\' , 'z' , 'x' , 'c' , 'v' , /* scan 40-47 */
79:
80: 'b' , 'n' , 'm' , ',' , '.' , '/' , SHF , '*', /* scan 48-55 */
81: ALT , ' ' , CPS|L, 0, 0, ' ' , 0, 0, /* scan 56-63 */
82:
83: 0, 0, 0, 0, 0, NUM|L, STP|L, '7', /* scan 64-71 */
84: '8', '9', '-', '4', '5', '6', '+', '1', /* scan 72-79 */
85:
86: '2', '3', '0', '.', 0, 0, 0, 0, /* scan 80-87 */
87: 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: 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, } ;
90:
91: u_char shift[] = { /* shift shift */
92: 0, 033 , '!' , '@' , '#' , '$' , '%' , '^' , /* scan 0- 7 */
93: '&' , '*' , '(' , ')' , '_' , '+' , 0177 ,'\t' , /* scan 8-15 */
94: 'Q' , 'W' , 'E' , 'R' , 'T' , 'Y' , 'U' , 'I' , /* scan 16-23 */
95: 'O' , 'P' , '[' , ']' , '\r' , CTL , 'A' , 'S' , /* scan 24-31 */
96: 'D' , 'F' , 'G' , 'H' , 'J' , 'K' , 'L' , ':' , /* scan 32-39 */
97: '"' , '~' , SHF , '|' , 'Z' , 'X' , 'C' , 'V' , /* scan 40-47 */
98: 'B' , 'N' , 'M' , '<' , '>' , '?' , SHF , '*', /* scan 48-55 */
99: ALT , ' ' , CPS|L, 0, 0, ' ' , 0, 0, /* scan 56-63 */
100: 0, 0, 0, 0, 0, NUM|L, STP|L, '7', /* scan 64-71 */
101: '8', '9', '-', '4', '5', '6', '+', '1', /* scan 72-79 */
102: '2', '3', '0', '.', 0, 0, 0, 0, /* scan 80-87 */
103: 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: 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, } ;
106:
107: u_char ctl[] = { /* CTL shift */
108: 0, 033 , '!' , 000 , '#' , '$' , '%' , 036 , /* scan 0- 7 */
109: '&' , '*' , '(' , ')' , 037 , '+' , 034 ,'\177', /* scan 8-15 */
110: 021 , 027 , 005 , 022 , 024 , 031 , 025 , 011 , /* scan 16-23 */
111: 017 , 020 , 033 , 035 , '\r' , CTL , 001 , 013 , /* scan 24-31 */
112: 004 , 006 , 007 , 010 , 012 , 013 , 014 , ';' , /* scan 32-39 */
113: '\'' , '`' , SHF , 034 , 032 , 030 , 003 , 026 , /* scan 40-47 */
114: 002 , 016 , 015 , '<' , '>' , '?' , SHF , '*', /* scan 48-55 */
115: ALT , ' ' , CPS|L, 0, 0, ' ' , 0, 0, /* scan 56-63 */
116: CPS|L, 0, 0, 0, 0, 0, 0, 0, /* scan 64-71 */
117: 0, 0, 0, 0, 0, 0, 0, 0, /* scan 72-79 */
118: 0, 0, 0, 0, 0, 0, 0, 0, /* scan 80-87 */
119: 0, 0, 033, '7' , '4' , '1' , 0, NUM|L, /* scan 88-95 */
120: '8' , '5' , '2' , 0, STP|L, '9' , '6' , '3' , /*scan 96-103*/
121: '.' , 0, '*' , '-' , '+' , 0, 0, 0, /*scan 104-111*/
122: 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, } ;
123:
124: #ifdef notdef
125: struct key {
126: u_short action; /* how this key functions */
127: char ascii[8]; /* ascii result character indexed by shifts */
128: };
129: #endif
130:
131: u_char shfts, ctls, alts, caps, num, stp;
1.1.1.2 root 132: #endif
1.1 root 133:
134: #define KBSTATP 0x64 /* kbd status port */
135: #define KBS_INP_BUF_FUL 0x02 /* kbd char ready */
136: #define KBDATAP 0x60 /* kbd data port */
137: #define KBSTATUSPORT 0x61 /* kbd status */
138:
1.1.1.2 root 139: u_char odt, bdt;
1.1 root 140:
141: u_char kbd() {
142: u_char dt, brk, act;
143:
144: loop:
145: while(inb(0x64)&1 == 0);
146: dt = inb(0x60);
147: do {
148: while(inb(0x64)&1 == 0);
149: } while(dt == inb(0x60));
150: odt = dt;
151:
152: brk = dt & 0x80 ; dt = dt & 0x7f ;
153:
1.1.1.3 root 154: #ifdef notdef
1.1 root 155: act = action[dt];
156: if (act&SHF) {
157: if(brk) shfts = 0; else shfts = 1;
158: }
159: if (act&ALT) {
160: if(brk) alts = 0; else alts = 1;
161: }
162: if (act&NUM) {
163: if (act&L) {
164: if(!brk) num ^= 1;
165: } else if(brk) num = 0; else num = 1;
166: }
167: if (act&CTL) {
168: if(brk) ctls = 0; else ctls = 1;
169: }
170: if (act&CPS) {
171: if (act&L) {
172: if(!brk) caps ^= 1;
173: } else if(brk) caps = 0; else caps = 1;
174: }
175: if (act&STP) {
176: if (act&L) {
177: if(!brk) stp ^= 1;
178: } else if(brk) stp = 0; else stp = 1;
179: }
1.1.1.3 root 180: if(ctls && alts && dt == 83) exit();
1.1 root 181: if ((act&ASCII) && !brk) {
182: u_char chr;
183:
184: if (shfts){
185: chr = shift[dt] ; } else {
186: if (ctls) {
187: chr = ctl[dt] ; } else {
188: chr = unshift[dt] ; } }
189: if (caps && (chr >= 'a' && chr <= 'z')) {
190: chr -= 'a' - 'A' ;
191: }
192: /*do
193: while(inb(0x64)&1 == 0) ;
194: while (inb(0x60) == (chr | 0x80));
195: while(inb(0x64)&1 == 1) inb(0x60);A*/
196: return(chr);
197: }
1.1.1.3 root 198: #else
199: if (brk)
200: return(1);
201: #endif
1.1 root 202: goto loop;
203: }
204:
205: scankbd() {
206: u_char c;
207:
1.1.1.3 root 208: #ifdef notdef
1.1 root 209: c = inb(0x60);
1.1.1.2 root 210: if (c == 83) exit();
211: /*if (c == 0xaa) return (0);
212: if (c == 0xfa) return (0);*/
213:
214: if (bdt == 0) { bdt = c&0x7f; return(0); }
215:
216: if(odt) return(1);
217:
1.1 root 218: c &= 0x7f;
219:
1.1.1.2 root 220: if (bdt == c) return(0);
221: odt = c;
1.1.1.3 root 222: #endif
1.1.1.2 root 223: return(1);
1.1 root 224: }
225:
226: kbdreset()
227: {
228: u_char c;
229:
230: /* Enable interrupts and keyboard controller */
231: while (inb(0x64)&2); outb(0x64,0x60);
232: while (inb(0x64)&2); outb(0x60,0x4D);
233:
234: /* Start keyboard stuff RESET */
235: while (inb(0x64)&2); /* wait input ready */
236: outb(0x60,0xFF); /* RESET */
237:
238: while((c=inb(0x60))!=0xFA) ;
239:
240: /* While we are here, defeat gatea20 */
241: while (inb(0x64)&2); /* wait input ready */
242: outb(0x64,0xd1);
243: while (inb(0x64)&2); /* wait input ready */
244: outb(0x60,0xdf);
1.1.1.3 root 245: while (inb(0x64)&2); /* wait input ready */
1.1.1.2 root 246: odt = bdt = 0;
247: inb(0x60);
1.1 root 248: }
249:
1.1.1.2 root 250: #ifdef notdef;
1.1 root 251: u_char getchar() {
252: u_char c;
253:
254: c = kbd();
255: if (c == '\b' || c == '\177') return(c);
256: if (c == '\r') c = '\n';
257: putchar(c);
258: return(c);
259: }
1.1.1.2 root 260: #endif
1.1 root 261:
262: reset_cpu() {
263:
264: while (inb(0x64)&2); /* wait input ready */
265: outb(0x64,0xFE); /* Reset Command */
266: wait(4000000);
267: /* NOTREACHED */
268: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.