BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / i386 / stand / kbd.c
index 6915494..fdf7645 100644 (file)
@@ -5,9 +5,35 @@
  * This code is derived from software contributed to Berkeley by
  * William Jolitz.
  *
  * This code is derived from software contributed to Berkeley by
  * William Jolitz.
  *
- * %sccs.include.noredist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
  *
- *     @(#)kbd.c       7.1 (Berkeley) %G%
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)kbd.c       7.4 (Berkeley) 5/4/91
  */
 
 #define        L               0x01    /* locking function */
  */
 
 #define        L               0x01    /* locking function */
@@ -113,10 +139,11 @@ u_char kbd() {
        u_char dt, brk, act;
        
 loop:
        u_char dt, brk, act;
        
 loop:
+       while(inb(0x64)&1 == 0);
+       dt = inb(0x60);
        do {
        do {
-               while (inb(0x64)&2) ;
-               dt = inb(0x60);
-       } while (dt == odt);
+               while(inb(0x64)&1 == 0);
+       } while(dt == inb(0x60));
        odt = dt;
 
        brk = dt & 0x80 ; dt = dt & 0x7f ;
        odt = dt;
 
        brk = dt & 0x80 ; dt = dt & 0x7f ;
@@ -146,6 +173,7 @@ loop:
                        if(!brk) stp ^= 1;
                } else if(brk)  stp = 0; else stp = 1;
        }
                        if(!brk) stp ^= 1;
                } else if(brk)  stp = 0; else stp = 1;
        }
+       if(ctl && alts && dt == 83) exit();
        if ((act&ASCII) && !brk) {
                u_char chr;
 
        if ((act&ASCII) && !brk) {
                u_char chr;
 
@@ -157,7 +185,63 @@ loop:
                if (caps && (chr >= 'a' && chr <= 'z')) {
                        chr -= 'a' - 'A' ;
                }
                if (caps && (chr >= 'a' && chr <= 'z')) {
                        chr -= 'a' - 'A' ;
                }
+               /*do
+                       while(inb(0x64)&1 == 0) ;
+               while (inb(0x60) == (chr | 0x80));
+               while(inb(0x64)&1 == 1) inb(0x60);A*/
                return(chr);
        }
        goto loop;
 }
                return(chr);
        }
        goto loop;
 }
+
+scankbd() {
+u_char c;
+       
+       c = inb(0x60);
+       if (c == 0xaa) { odt = 0x2a; return (0); }
+       if (c == 0xfa) { odt = 0x7a; return (0); }
+       c &= 0x7f;
+       
+       if ( (odt&0x7f) == c )return(0);
+       if(odt == 0) { odt = c;  return(0); }
+       return(kbd());
+}
+
+kbdreset()
+{
+       u_char c;
+
+       /* Enable interrupts and keyboard controller */
+       while (inb(0x64)&2); outb(0x64,0x60);
+       while (inb(0x64)&2); outb(0x60,0x4D);
+
+       /* Start keyboard stuff RESET */
+       while (inb(0x64)&2);    /* wait input ready */
+       outb(0x60,0xFF);        /* RESET */
+
+       while((c=inb(0x60))!=0xFA) ;
+
+       /* While we are here, defeat gatea20 */
+       while (inb(0x64)&2);    /* wait input ready */
+       outb(0x64,0xd1);        
+       while (inb(0x64)&2);    /* wait input ready */
+       outb(0x60,0xdf);        
+}
+
+u_char getchar() {
+       u_char c;
+
+       c = kbd();
+       if (c == '\b' || c == '\177') return(c);
+       if (c == '\r') c = '\n';
+       putchar(c);
+       return(c);
+}
+
+reset_cpu() {
+
+       while (inb(0x64)&2);    /* wait input ready */
+       outb(0x64,0xFE);        /* Reset Command */
+       wait(4000000);
+       /* NOTREACHED */
+}