-
Notifications
You must be signed in to change notification settings - Fork 2
/
key_code.c
42 lines (40 loc) · 937 Bytes
/
key_code.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <dos.h>
#include "key_code.h"
uint16_t key_read(uint8_t what) {
struct SREGS sr;
union REGS rs;
rs.x.bx = 0; /* only for KEY_FAST */
rs.h.ah = what & 0x03;
segread(&sr);
int86x(0x16, &rs, &rs, &sr);
switch (what & 0x03) {
case KEY_READ:
break;
case KEY_TEST:
/* check zero flag */
rs.x.ax = (rs.x.flags & 0x40) ? 0 : rs.x.ax;
/* check other what bits */
what ^= KEY_TEST;
if (what & (KEY_DROP | KEY_WAIT)) {
if (rs.x.ax) {
/* read first pressed key if any */
rs.x.ax = key_read(KEY_READ);
}
/* drop everything else */
while (key_read(KEY_TEST)) {
key_read(KEY_READ);
}
if (what & KEY_WAIT) {
rs.x.ax = key_read(KEY_READ);
}
}
break;
case KEY_FLAG:
rs.x.ax &= 0xFF;
break;
case KEY_FAST:
rs.x.ax = 0;
break;
}
return(rs.x.ax);
}