Added timeout to critical section waiting.
[wine/multimedia.git] / msdos / xms.c
blob17802fa17a83fb329638dc9733c6b16042c3159f
1 /*
2 * XMS v2+ emulation
4 * Copyright 1998 Ove Kåven
6 * This XMS emulation is hooked through the DPMI interrupt.
7 */
9 #include <unistd.h>
10 #include <string.h>
11 #include "winbase.h"
12 #include "global.h"
13 #include "module.h"
14 #include "miscemu.h"
15 #include "toolhelp.h"
16 #include "debug.h"
17 #include "selectors.h"
19 typedef struct {
20 WORD Handle;
21 DWORD Offset;
22 } WINE_PACKED MOVEOFS;
24 typedef struct {
25 DWORD Length;
26 MOVEOFS Source;
27 MOVEOFS Dest;
28 } WINE_PACKED MOVESTRUCT;
30 static BYTE * XMS_Offset( MOVEOFS *ofs )
32 if (ofs->Handle) return (BYTE*)GlobalLock16(ofs->Handle)+ofs->Offset;
33 else return (BYTE*)DOSMEM_MapRealToLinear(ofs->Offset);
36 /**********************************************************************
37 * XMS_Handler
40 void WINAPI XMS_Handler( CONTEXT *context )
42 switch(AH_reg(context))
44 case 0x00: /* Get XMS version number */
45 TRACE(int31, "get XMS version number\n");
46 AX_reg(context) = 0x0200; /* 2.0 */
47 BX_reg(context) = 0x0000; /* internal revision */
48 DX_reg(context) = 0x0001; /* HMA exists */
49 break;
50 case 0x08: /* Query Free Extended Memory */
52 MEMMANINFO mmi;
54 TRACE(int31, "query free extended memory\n");
55 mmi.dwSize = sizeof(mmi);
56 MemManInfo16(&mmi);
57 AX_reg(context) = mmi.dwLargestFreeBlock >> 10;
58 DX_reg(context) = (mmi.dwFreePages * VIRTUAL_GetPageSize()) >> 10;
59 TRACE(int31, "returning largest %dK, total %dK\n", AX_reg(context), DX_reg(context));
61 break;
62 case 0x09: /* Allocate Extended Memory Block */
63 TRACE(int31, "allocate extended memory block (%dK)\n",
64 DX_reg(context));
65 DX_reg(context) = GlobalAlloc16(GMEM_MOVEABLE,
66 (DWORD)DX_reg(context)<<10);
67 AX_reg(context) = DX_reg(context) ? 1 : 0;
68 if (!DX_reg(context)) BL_reg(context) = 0xA0; /* out of memory */
69 break;
70 case 0x0a: /* Free Extended Memory Block */
71 TRACE(int31, "free extended memory block %04x\n",DX_reg(context));
72 GlobalFree16(DX_reg(context));
73 break;
74 case 0x0b: /* Move Extended Memory Block */
76 MOVESTRUCT*move=CTX_SEG_OFF_TO_LIN(context,
77 DS_reg(context),ESI_reg(context));
78 BYTE*src,*dst;
79 TRACE(int31, "move extended memory block\n");
80 src=XMS_Offset(&move->Source);
81 dst=XMS_Offset(&move->Dest);
82 memcpy(dst,src,move->Length);
83 if (move->Source.Handle) GlobalUnlock16(move->Source.Handle);
84 if (move->Dest.Handle) GlobalUnlock16(move->Dest.Handle);
85 break;
87 default:
88 INT_BARF( context, 0x31 );
89 AX_reg(context) = 0x0000; /* failure */
90 BL_reg(context) = 0x80; /* function not implemented */
91 break;