kernel: Use hashdestroy() to free hash tables allocated with hashinit().
[dragonfly.git] / usr.bin / doscmd / int16.c
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1992, 1993, 1996
3 * Berkeley Software Design, Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Berkeley Software
16 * Design, Inc.
17 *
18 * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * BSDI int16.c,v 2.2 1996/04/08 19:32:47 bostic Exp
1de703da
MD
31 *
32 * $FreeBSD: src/usr.bin/doscmd/int16.c,v 1.2.2.2 2002/04/25 11:04:51 tg Exp $
33 * $DragonFly: src/usr.bin/doscmd/int16.c,v 1.2 2003/06/17 04:29:26 dillon Exp $
984263bc
MD
34 */
35
984263bc
MD
36#include "doscmd.h"
37#include "tty.h"
38
39#define K_NEXT *(u_short *)0x41a
40#define K_FREE *(u_short *)0x41c
41
42#define HWM 16
43volatile int poll_cnt = 0;
44
45void
46wakeup_poll(void)
47{
48 if (poll_cnt <= 0)
49 poll_cnt = HWM;
50}
51
52void
53reset_poll(void)
54{
55 poll_cnt = HWM;
56}
57
58void
59sleep_poll(void)
60{
61#if 0
62 printf("sleep_poll: poll_cnt=%d\n", poll_cnt);
63 if (poll_cnt == 14)
64 tmode = 1;
65#endif
66 if (--poll_cnt <= 0) {
67 poll_cnt = 0;
68 while (KbdEmpty() && poll_cnt <= 0) {
69#if 0
70 softint(0x28);
71#endif
72 if (KbdEmpty() && poll_cnt <= 0)
73 tty_pause();
74 }
75 }
76}
77
78void
79int16(regcontext_t *REGS)
80{
81 if (!xmode && !raw_kbd) {
82 if (vflag) dump_regs(REGS);
83 fatal ("int16 func 0x%x only supported in X mode\n", R_AH);
84 }
85 switch(R_AH) {
86 case 0x00:
87 case 0x10: /* Get enhanced keystroke */
88 poll_cnt = 16;
89 while (KbdEmpty())
90 tty_pause();
91 R_AX = KbdRead();
92 break;
93
94 case 0x01: /* Get keystroke */
95 case 0x11: /* Get enhanced keystroke */
96 if (KbdEmpty()) {
97 R_FLAGS |= PSL_Z;
98 break;
99 }
100 R_FLAGS &= ~PSL_Z;
101 R_AX = KbdPeek();
102 break;
103
104 case 0x02:
105 R_AL = tty_state();
106 break;
107
108 case 0x12:
109 R_AH = tty_estate();
110 R_AL = tty_state();
111 break;
112
113 case 0x03: /* Set typematic and delay rate */
114 break;
115
116 case 0x05:
117 KbdWrite(R_CX);
118 break;
119
120 case 0x55:
121 R_AX = 0x43af; /* Empirical value ... */
122 break;
123
124 case 0x92:
125 R_AH = 0x00;
126 break;
127
128 case 0xa2:
129 debug(D_HALF, "122-key keyboard support check\n");
130 break;
131
132 default:
133 unknown_int2(0x16, R_AH, REGS);
134 break;
135 }
136}