Implemented wglShareLists and wglGetCurrentDC.
[wine.git] / msdos / int16.c
blob8b7a34065512b8c494a83b6a9ab8bfb40c819bd1
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 "windef.h"
15 #include "wingdi.h"
16 #include "winuser.h"
17 #include "miscemu.h"
19 DEFAULT_DEBUG_CHANNEL(int16)
21 /**********************************************************************
22 * INT_Int16Handler
24 * Handler for int 16h (keyboard)
26 * NOTE:
28 * KEYB.COM (DOS >3.2) adds functions to this interrupt, they are
29 * not currently listed here.
32 void WINAPI INT_Int16Handler( CONTEXT86 *context )
34 switch AH_reg(context) {
36 case 0x00: /* Get Keystroke */
37 /* Returns: AH = Scan code
38 AL = ASCII character */
39 TRACE("Get Keystroke\n");
40 CONSOLE_GetKeystroke(&AH_reg(context), &AL_reg(context));
41 break;
43 case 0x01: /* Check for Keystroke */
44 /* Returns: ZF set if no keystroke */
45 /* AH = Scan code */
46 /* AL = ASCII character */
47 TRACE("Check for Keystroke\n");
48 if (!CONSOLE_CheckForKeystroke(&AH_reg(context), &AL_reg(context)))
50 SET_ZFLAG(context);
52 else
54 RESET_ZFLAG(context);
56 break;
58 case 0x02: /* Get Shift Flags */
59 AL_reg(context) = 0;
61 if (GetAsyncKeyState(VK_RSHIFT))
62 AL_reg(context) |= 0x01;
63 if (GetAsyncKeyState(VK_LSHIFT))
64 AL_reg(context) |= 0x02;
65 if (GetAsyncKeyState(VK_LCONTROL) || GetAsyncKeyState(VK_RCONTROL))
66 AL_reg(context) |= 0x04;
67 if (GetAsyncKeyState(VK_LMENU) || GetAsyncKeyState(VK_RMENU))
68 AL_reg(context) |= 0x08;
69 if (GetAsyncKeyState(VK_SCROLL))
70 AL_reg(context) |= 0x10;
71 if (GetAsyncKeyState(VK_NUMLOCK))
72 AL_reg(context) |= 0x20;
73 if (GetAsyncKeyState(VK_CAPITAL))
74 AL_reg(context) |= 0x40;
75 if (GetAsyncKeyState(VK_INSERT))
76 AL_reg(context) |= 0x80;
77 TRACE("Get Shift Flags: returning 0x%02x\n", AL_reg(context));
78 break;
80 case 0x03: /* Set Typematic Rate and Delay */
81 FIXME("Set Typematic Rate and Delay - Not Supported\n");
82 break;
84 case 0x09: /* Get Keyboard Functionality */
85 FIXME("Get Keyboard Functionality - Not Supported\n");
86 /* As a temporary measure, say that "nothing" is supported... */
87 AL_reg(context) = 0;
88 break;
90 case 0x0a: /* Get Keyboard ID */
91 FIXME("Get Keyboard ID - Not Supported\n");
92 break;
94 case 0x10: /* Get Enhanced Keystroke */
95 TRACE("Get Enhanced Keystroke - Partially supported\n");
96 /* Returns: AH = Scan code
97 AL = ASCII character */
98 CONSOLE_GetKeystroke(&AH_reg(context), &AL_reg(context));
99 break;
102 case 0x11: /* Check for Enhanced Keystroke */
103 /* Returns: ZF set if no keystroke */
104 /* AH = Scan code */
105 /* AL = ASCII character */
106 TRACE("Check for Enhanced Keystroke - Partially supported\n");
107 if (!CONSOLE_CheckForKeystroke(&AH_reg(context), &AL_reg(context)))
109 SET_ZFLAG(context);
111 else
113 RESET_ZFLAG(context);
115 break;
117 case 0x12: /* Get Extended Shift States */
118 FIXME("Get Extended Shift States - Not Supported\n");
119 break;
121 default:
122 FIXME("Unknown INT 16 function - 0x%x\n", AH_reg(context));
123 break;
128 int WINAPI INT_Int16ReadChar(BYTE*ascii,BYTE*scan,BOOL peek)
130 BIOSDATA *data = DOSMEM_BiosData();
131 WORD CurOfs = data->NextKbdCharPtr;
133 /* check if there's data in buffer */
134 if (peek) {
135 if (CurOfs == data->FirstKbdCharPtr)
136 return 0;
137 } else {
138 while (CurOfs == data->FirstKbdCharPtr) {
139 /* no input available yet, so wait... */
140 DOSVM_Wait( -1, 0 );
143 /* read from keyboard queue */
144 TRACE("(%p,%p,%d) -> %02x %02x\n",ascii,scan,peek,((BYTE*)data)[CurOfs],((BYTE*)data)[CurOfs+1]);
145 if (ascii) *ascii = ((BYTE*)data)[CurOfs];
146 if (scan) *scan = ((BYTE*)data)[CurOfs+1];
147 if (!peek) {
148 CurOfs += 2;
149 if (CurOfs >= data->KbdBufferEnd) CurOfs = data->KbdBufferStart;
150 data->NextKbdCharPtr = CurOfs;
152 return 1;
155 int WINAPI INT_Int16AddChar(BYTE ascii,BYTE scan)
157 BIOSDATA *data = DOSMEM_BiosData();
158 WORD CurOfs = data->FirstKbdCharPtr;
159 WORD NextOfs = CurOfs + 2;
161 TRACE("(%02x,%02x)\n",ascii,scan);
162 if (NextOfs >= data->KbdBufferEnd) NextOfs = data->KbdBufferStart;
163 /* check if buffer is full */
164 if (NextOfs == data->NextKbdCharPtr) return 0;
166 /* okay, insert character in ring buffer */
167 ((BYTE*)data)[CurOfs] = ascii;
168 ((BYTE*)data)[CurOfs+1] = scan;
170 data->FirstKbdCharPtr = NextOfs;
171 return 1;