]> 4ch.mooo.com Git - 16.git/blob - src/lib/doslib/hw/8042/8042.c
added a bunch of things~ and midi stuff~
[16.git] / src / lib / doslib / hw / 8042 / 8042.c
1 /* 8042.c
2  *
3  * Intel 8042 keyboard controller library.
4  * (C) 2008-2012 Jonathan Campbell.
5  * Hackipedia DOS library.
6  *
7  * This code is licensed under the LGPL.
8  * <insert LGPL legal text here>
9  *
10  * Compiles for intended target environments:
11  *   - MS-DOS [pure DOS mode, or Windows or OS/2 DOS Box]
12  *
13  * On "IBM compatible" hardware the keyboard controller is responsible for
14  * receiving scan codes from the keyboard. On newer (post 1990) systems,
15  * the controller also handles PS/2 mouse input and communication (AUX).
16  *
17  * Note that on recent hardware (1999 or later) it's entirely possible the
18  * BIOS is using System Management Mode and/or a USB mouse & keyboard to
19  * fake 8042 I/O ports and communications for backwards compatibility. */
20
21 #include <stdio.h>
22 #include <conio.h> /* this is where Open Watcom hides the outp() etc. functions */
23 #include <stdlib.h>
24
25 #include <hw/cpu/cpu.h>
26 #include <hw/8042/8042.h>
27
28 unsigned char           k8042_flags = 0;
29 unsigned char           k8042_last_status = 0;
30
31 /* drain the 8042 buffer entirely */
32 void k8042_drain_buffer() {
33         unsigned char c;
34
35         do {
36                 inp(K8042_DATA);
37                 c = inp(K8042_STATUS);
38         } while (c&3);
39         k8042_last_status = c;
40 }
41
42 /* probe for the existence of the 8042 controller I/O ports.
43  * obviously as a DOS program the ports are there. but someday...
44  * it's possible the newer BIOSes will stop emulating it sooner or later. */
45 int k8042_probe() {
46         if (inp(K8042_STATUS) == 0xFF)
47                 return 0;
48
49         return 1;
50 }
51