date and time created 90/04/24 19:56:56 by william
[unix-history] / usr / src / sys / i386 / stand / kbd.c
CommitLineData
a7ab625b
WN
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 * %sccs.include.noredist.c%
9 *
10 * @(#)kbd.c 7.1 (Berkeley) %G%
11 */
12
13#define L 0x01 /* locking function */
14#define SHF 0x02 /* keyboard shift */
15#define ALT 0x04 /* alternate shift -- alternate chars */
16#define NUM 0x08 /* numeric shift cursors vs. numeric */
17#define CTL 0x10 /* control shift -- allows ctl function */
18#define CPS 0x20 /* caps shift -- swaps case of letter */
19#define ASCII 0x40 /* ascii code for this key */
20#define STP 0x80 /* stop output */
21
22typedef unsigned char u_char;
23
24u_char inb();
25
26u_char action[] = {
270, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, /* scan 0- 7 */
28ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, /* scan 8-15 */
29ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, /* scan 16-23 */
30ASCII, ASCII, ASCII, ASCII, ASCII, CTL, ASCII, ASCII, /* scan 24-31 */
31ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, /* scan 32-39 */
32ASCII, ASCII, SHF , ASCII, ASCII, ASCII, ASCII, ASCII, /* scan 40-47 */
33ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, SHF, ASCII, /* scan 48-55 */
34 ALT, ASCII, CPS|L, 0, 0, ASCII, 0, 0, /* scan 56-63 */
35 0, 0, 0, 0, 0, NUM|L, STP|L, ASCII, /* scan 64-71 */
36ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, /* scan 72-79 */
37ASCII, ASCII, ASCII, ASCII, 0, 0, 0, 0, /* scan 80-87 */
380,0,0,0,0,0,0,0,
390,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
400,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, } ;
41
42u_char unshift[] = { /* no shift */
430, 033 , '1' , '2' , '3' , '4' , '5' , '6' , /* scan 0- 7 */
44'7' , '8' , '9' , '0' , '-' , '=' , 0177 ,'\t' , /* scan 8-15 */
45
46'q' , 'w' , 'e' , 'r' , 't' , 'y' , 'u' , 'i' , /* scan 16-23 */
47'o' , 'p' , '[' , ']' , '\r' , CTL , 'a' , 's' , /* scan 24-31 */
48
49'd' , 'f' , 'g' , 'h' , 'j' , 'k' , 'l' , ';' , /* scan 32-39 */
50'\'' , '`' , SHF , '\\' , 'z' , 'x' , 'c' , 'v' , /* scan 40-47 */
51
52'b' , 'n' , 'm' , ',' , '.' , '/' , SHF , '*', /* scan 48-55 */
53ALT , ' ' , CPS|L, 0, 0, ' ' , 0, 0, /* scan 56-63 */
54
55 0, 0, 0, 0, 0, NUM|L, STP|L, '7', /* scan 64-71 */
56 '8', '9', '-', '4', '5', '6', '+', '1', /* scan 72-79 */
57
58 '2', '3', '0', '.', 0, 0, 0, 0, /* scan 80-87 */
590,0,0,0,0,0,0,0,
600,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
610,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, } ;
62
63u_char shift[] = { /* shift shift */
640, 033 , '!' , '@' , '#' , '$' , '%' , '^' , /* scan 0- 7 */
65'&' , '*' , '(' , ')' , '_' , '+' , 0177 ,'\t' , /* scan 8-15 */
66'Q' , 'W' , 'E' , 'R' , 'T' , 'Y' , 'U' , 'I' , /* scan 16-23 */
67'O' , 'P' , '[' , ']' , '\r' , CTL , 'A' , 'S' , /* scan 24-31 */
68'D' , 'F' , 'G' , 'H' , 'J' , 'K' , 'L' , ':' , /* scan 32-39 */
69'"' , '~' , SHF , '|' , 'Z' , 'X' , 'C' , 'V' , /* scan 40-47 */
70'B' , 'N' , 'M' , '<' , '>' , '?' , SHF , '*', /* scan 48-55 */
71ALT , ' ' , CPS|L, 0, 0, ' ' , 0, 0, /* scan 56-63 */
72 0, 0, 0, 0, 0, NUM|L, STP|L, '7', /* scan 64-71 */
73 '8', '9', '-', '4', '5', '6', '+', '1', /* scan 72-79 */
74 '2', '3', '0', '.', 0, 0, 0, 0, /* scan 80-87 */
750,0,0,0,0,0,0,0,
760,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
770,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, } ;
78
79u_char ctl[] = { /* CTL shift */
800, 033 , '!' , 000 , '#' , '$' , '%' , 036 , /* scan 0- 7 */
81'&' , '*' , '(' , ')' , 037 , '+' , 034 ,'\177', /* scan 8-15 */
82021 , 027 , 005 , 022 , 024 , 031 , 025 , 011 , /* scan 16-23 */
83017 , 020 , 033 , 035 , '\r' , CTL , 001 , 013 , /* scan 24-31 */
84004 , 006 , 007 , 010 , 012 , 013 , 014 , ';' , /* scan 32-39 */
85'\'' , '`' , SHF , 034 , 032 , 030 , 003 , 026 , /* scan 40-47 */
86002 , 016 , 015 , '<' , '>' , '?' , SHF , '*', /* scan 48-55 */
87ALT , ' ' , CPS|L, 0, 0, ' ' , 0, 0, /* scan 56-63 */
88CPS|L, 0, 0, 0, 0, 0, 0, 0, /* scan 64-71 */
89 0, 0, 0, 0, 0, 0, 0, 0, /* scan 72-79 */
90 0, 0, 0, 0, 0, 0, 0, 0, /* scan 80-87 */
91 0, 0, 033, '7' , '4' , '1' , 0, NUM|L, /* scan 88-95 */
92'8' , '5' , '2' , 0, STP|L, '9' , '6' , '3' , /*scan 96-103*/
93'.' , 0, '*' , '-' , '+' , 0, 0, 0, /*scan 104-111*/
940,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, } ;
95
96#ifdef notdef
97struct key {
98 u_short action; /* how this key functions */
99 char ascii[8]; /* ascii result character indexed by shifts */
100};
101#endif
102
103u_char shfts, ctls, alts, caps, num, stp;
104
105#define KBSTATP 0x64 /* kbd status port */
106#define KBS_INP_BUF_FUL 0x02 /* kbd char ready */
107#define KBDATAP 0x60 /* kbd data port */
108#define KBSTATUSPORT 0x61 /* kbd status */
109
110u_char odt;
111
112u_char kbd() {
113 u_char dt, brk, act;
114
115loop:
116 do {
117 while (inb(0x64)&2) ;
118 dt = inb(0x60);
119 } while (dt == odt);
120 odt = dt;
121
122 brk = dt & 0x80 ; dt = dt & 0x7f ;
123
124 act = action[dt];
125 if (act&SHF) {
126 if(brk) shfts = 0; else shfts = 1;
127 }
128 if (act&ALT) {
129 if(brk) alts = 0; else alts = 1;
130 }
131 if (act&NUM) {
132 if (act&L) {
133 if(!brk) num ^= 1;
134 } else if(brk) num = 0; else num = 1;
135 }
136 if (act&CTL) {
137 if(brk) ctls = 0; else ctls = 1;
138 }
139 if (act&CPS) {
140 if (act&L) {
141 if(!brk) caps ^= 1;
142 } else if(brk) caps = 0; else caps = 1;
143 }
144 if (act&STP) {
145 if (act&L) {
146 if(!brk) stp ^= 1;
147 } else if(brk) stp = 0; else stp = 1;
148 }
149 if ((act&ASCII) && !brk) {
150 u_char chr;
151
152 if (shfts){
153 chr = shift[dt] ; } else {
154 if (ctls) {
155 chr = ctl[dt] ; } else {
156 chr = unshift[dt] ; } }
157 if (caps && (chr >= 'a' && chr <= 'z')) {
158 chr -= 'a' - 'A' ;
159 }
160 return(chr);
161 }
162 goto loop;
163}