|
|
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: *
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:
1.1.1.2 ! root 52: #ifdef notdef
1.1 root 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;
1.1.1.2 ! root 131: #endif
1.1 root 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:
1.1.1.2 ! root 138: u_char odt, bdt;
1.1 root 139:
1.1.1.2 ! root 140: #ifdef notdef
1.1 root 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:
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(ctl && 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: goto loop;
198: }
1.1.1.2 ! root 199: #endif
1.1 root 200:
201: scankbd() {
202: u_char c;
203:
204: c = inb(0x60);
1.1.1.2 ! root 205: if (c == 83) exit();
! 206: /*if (c == 0xaa) return (0);
! 207: if (c == 0xfa) return (0);*/
! 208:
! 209: if (bdt == 0) { bdt = c&0x7f; return(0); }
! 210:
! 211: if(odt) return(1);
! 212:
1.1 root 213: c &= 0x7f;
214:
1.1.1.2 ! root 215: if (bdt == c) return(0);
! 216: odt = c;
! 217: return(1);
1.1 root 218: }
219:
220: kbdreset()
221: {
222: u_char c;
223:
224: /* Enable interrupts and keyboard controller */
225: while (inb(0x64)&2); outb(0x64,0x60);
226: while (inb(0x64)&2); outb(0x60,0x4D);
227:
228: /* Start keyboard stuff RESET */
229: while (inb(0x64)&2); /* wait input ready */
230: outb(0x60,0xFF); /* RESET */
231:
232: while((c=inb(0x60))!=0xFA) ;
233:
234: /* While we are here, defeat gatea20 */
235: while (inb(0x64)&2); /* wait input ready */
236: outb(0x64,0xd1);
237: while (inb(0x64)&2); /* wait input ready */
238: outb(0x60,0xdf);
1.1.1.2 ! root 239: odt = bdt = 0;
! 240: inb(0x60);
1.1 root 241: }
242:
1.1.1.2 ! root 243: #ifdef notdef;
1.1 root 244: u_char getchar() {
245: u_char c;
246:
247: c = kbd();
248: if (c == '\b' || c == '\177') return(c);
249: if (c == '\r') c = '\n';
250: putchar(c);
251: return(c);
252: }
1.1.1.2 ! root 253: #endif
1.1 root 254:
255: reset_cpu() {
256:
257: while (inb(0x64)&2); /* wait input ready */
258: outb(0x64,0xFE); /* Reset Command */
259: wait(4000000);
260: /* NOTREACHED */
261: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.