Created an ACM MS ADPCM codec.
[wine/wine-kai.git] / dlls / winedos / int09.c
blob8f5e8ac7a40a2b3179b04b4852ec42f902e277b6
1 /*
2 * DOS interrupt 09h handler (IRQ1 - KEYBOARD)
4 * Copyright 1999 Ove Kåven
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <stdlib.h>
22 #include <string.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "miscemu.h"
29 #include "wine/debug.h"
30 #include "dosexe.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(int);
34 #define QUEUELEN 31
36 static struct
38 BYTE queuelen,queue[QUEUELEN],ascii[QUEUELEN];
39 } kbdinfo;
42 /**********************************************************************
43 * DOSVM_Int09Handler
45 * Handler for int 09h.
47 void WINAPI DOSVM_Int09Handler( CONTEXT86 *context )
49 BYTE ascii, scan = DOSVM_Int09ReadScan(&ascii);
50 BYTE ch[2];
51 int cnt, c2;
53 TRACE("scan=%02x\n",scan);
54 if (!(scan & 0x80)) {
55 if (ascii) {
56 /* we already have an ASCII code, no translation necessary */
57 ch[0] = ascii;
58 cnt = 1;
59 } else {
60 UINT vkey = MapVirtualKeyA(scan&0x7f, 1);
61 BYTE keystate[256];
62 GetKeyboardState(keystate);
63 cnt = ToAscii(vkey, scan, keystate, (LPWORD)ch, 0);
65 if (cnt>0) {
66 for (c2=0; c2<cnt; c2++)
67 DOSVM_Int16AddChar(ch[c2], scan);
68 } else
69 if (cnt==0) {
70 /* FIXME: need to handle things like shift-F-keys,
71 * 0xE0 extended keys, etc */
72 DOSVM_Int16AddChar(0, scan);
75 DOSVM_PIC_ioport_out( 0x20, 0x20 ); /* send EOI */
78 static void KbdRelay( CONTEXT86 *context, void *data )
80 if (kbdinfo.queuelen) {
81 /* cleanup operation, called from DOSVM_PIC_ioport_out:
82 * we'll remove current scancode from keyboard buffer here,
83 * rather than in ReadScan, because some DOS apps depend on
84 * the scancode being available for reading multiple times... */
85 if (--kbdinfo.queuelen) {
86 memmove(kbdinfo.queue,kbdinfo.queue+1,kbdinfo.queuelen);
87 memmove(kbdinfo.ascii,kbdinfo.ascii+1,kbdinfo.queuelen);
92 void WINAPI DOSVM_Int09SendScan( BYTE scan, BYTE ascii )
94 if (kbdinfo.queuelen == QUEUELEN) {
95 ERR("keyboard queue overflow\n");
96 return;
98 /* add scancode to queue */
99 kbdinfo.queue[kbdinfo.queuelen] = scan;
100 kbdinfo.ascii[kbdinfo.queuelen++] = ascii;
101 /* tell app to read it by triggering IRQ 1 (int 09) */
102 DOSVM_QueueEvent(1,DOS_PRIORITY_KEYBOARD,KbdRelay,NULL);
105 /**********************************************************************
106 * KbdReadScan (WINEDOS.@)
108 BYTE WINAPI DOSVM_Int09ReadScan( BYTE*ascii )
110 if (ascii) *ascii = kbdinfo.ascii[0];
111 return kbdinfo.queue[0];