Added ListView_EditLabel macros.
[wine/multimedia.git] / msdos / int16.c
blob6287073af5b29a01030ae5ba62c91a51b724f148
1 /*
2 * DOS interrupt 16h handler
3 */
5 #include <stdlib.h>
6 #include <string.h>
7 #include <unistd.h>
9 #include "config.h"
10 #include "module.h"
11 #include "console.h"
12 #include "wincon.h"
13 #include "debugtools.h"
14 #include "winuser.h"
15 #include "miscemu.h"
17 DEFAULT_DEBUG_CHANNEL(int16)
19 /**********************************************************************
20 * INT_Int16Handler
22 * Handler for int 16h (keyboard)
24 * NOTE:
26 * KEYB.COM (DOS >3.2) adds functions to this interrupt, they are
27 * not currently listed here.
30 void WINAPI INT_Int16Handler( CONTEXT86 *context )
32 switch AH_reg(context) {
34 case 0x00: /* Get Keystroke */
35 /* Returns: AH = Scan code
36 AL = ASCII character */
37 TRACE("Get Keystroke\n");
38 CONSOLE_GetKeystroke(&AH_reg(context), &AL_reg(context));
39 break;
41 case 0x01: /* Check for Keystroke */
42 /* Returns: ZF set if no keystroke */
43 /* AH = Scan code */
44 /* AL = ASCII character */
45 TRACE("Check for Keystroke\n");
46 if (!CONSOLE_CheckForKeystroke(&AH_reg(context), &AL_reg(context)))
48 SET_ZFLAG(context);
50 else
52 RESET_ZFLAG(context);
54 break;
56 case 0x02: /* Get Shift Flags */
57 AL_reg(context) = 0;
59 if (GetAsyncKeyState(VK_RSHIFT))
60 AL_reg(context) |= 0x01;
61 if (GetAsyncKeyState(VK_LSHIFT))
62 AL_reg(context) |= 0x02;
63 if (GetAsyncKeyState(VK_LCONTROL) || GetAsyncKeyState(VK_RCONTROL))
64 AL_reg(context) |= 0x04;
65 if (GetAsyncKeyState(VK_LMENU) || GetAsyncKeyState(VK_RMENU))
66 AL_reg(context) |= 0x08;
67 if (GetAsyncKeyState(VK_SCROLL))
68 AL_reg(context) |= 0x10;
69 if (GetAsyncKeyState(VK_NUMLOCK))
70 AL_reg(context) |= 0x20;
71 if (GetAsyncKeyState(VK_CAPITAL))
72 AL_reg(context) |= 0x40;
73 if (GetAsyncKeyState(VK_INSERT))
74 AL_reg(context) |= 0x80;
75 TRACE("Get Shift Flags: returning 0x%02x\n", AL_reg(context));
76 break;
78 case 0x03: /* Set Typematic Rate and Delay */
79 FIXME("Set Typematic Rate and Delay - Not Supported\n");
80 break;
82 case 0x09: /* Get Keyboard Functionality */
83 FIXME("Get Keyboard Functionality - Not Supported\n");
84 /* As a temporary measure, say that "nothing" is supported... */
85 AL_reg(context) = 0;
86 break;
88 case 0x0a: /* Get Keyboard ID */
89 FIXME("Get Keyboard ID - Not Supported\n");
90 break;
92 case 0x10: /* Get Enhanced Keystroke */
93 TRACE("Get Enhanced Keystroke - Partially supported\n");
94 /* Returns: AH = Scan code
95 AL = ASCII character */
96 CONSOLE_GetKeystroke(&AH_reg(context), &AL_reg(context));
97 break;
100 case 0x11: /* Check for Enhanced Keystroke */
101 /* Returns: ZF set if no keystroke */
102 /* AH = Scan code */
103 /* AL = ASCII character */
104 TRACE("Check for Enhanced Keystroke - Partially supported\n");
105 if (!CONSOLE_CheckForKeystroke(&AH_reg(context), &AL_reg(context)))
107 SET_ZFLAG(context);
109 else
111 RESET_ZFLAG(context);
113 break;
115 case 0x12: /* Get Extended Shift States */
116 FIXME("Get Extended Shift States - Not Supported\n");
117 break;
119 default:
120 FIXME("Unknown INT 16 function - 0x%x\n", AH_reg(context));
121 break;
126 int WINAPI INT_Int16ReadChar(BYTE*ascii,BYTE*scan,BOOL peek)
128 BIOSDATA *data = DOSMEM_BiosData();
129 WORD CurOfs = data->NextKbdCharPtr;
131 /* check if there's data in buffer */
132 if (peek) {
133 if (CurOfs == data->FirstKbdCharPtr)
134 return 0;
135 } else {
136 while (CurOfs == data->FirstKbdCharPtr) {
137 /* no input available yet, so wait... */
138 DOSVM_Wait( -1, 0 );
141 /* read from keyboard queue */
142 TRACE("(%p,%p,%d) -> %02x %02x\n",ascii,scan,peek,((BYTE*)data)[CurOfs],((BYTE*)data)[CurOfs+1]);
143 if (ascii) *ascii = ((BYTE*)data)[CurOfs];
144 if (scan) *scan = ((BYTE*)data)[CurOfs+1];
145 if (!peek) {
146 CurOfs += 2;
147 if (CurOfs >= data->KbdBufferEnd) CurOfs = data->KbdBufferStart;
148 data->NextKbdCharPtr = CurOfs;
150 return 1;
153 int WINAPI INT_Int16AddChar(BYTE ascii,BYTE scan)
155 BIOSDATA *data = DOSMEM_BiosData();
156 WORD CurOfs = data->FirstKbdCharPtr;
157 WORD NextOfs = CurOfs + 2;
159 TRACE("(%02x,%02x)\n",ascii,scan);
160 if (NextOfs >= data->KbdBufferEnd) NextOfs = data->KbdBufferStart;
161 /* check if buffer is full */
162 if (NextOfs == data->NextKbdCharPtr) return 0;
164 /* okay, insert character in ring buffer */
165 ((BYTE*)data)[CurOfs] = ascii;
166 ((BYTE*)data)[CurOfs+1] = scan;
168 data->FirstKbdCharPtr = NextOfs;
169 return 1;