Use case insensitive comparison while searching for new modules.
[wine.git] / msdos / xms.c
blobc1dbfb7b520b94b686158db879f01e1693736bbf
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 "debugtools.h"
17 #include "selectors.h"
19 DEFAULT_DEBUG_CHANNEL(int31)
21 typedef struct {
22 WORD Handle;
23 DWORD Offset;
24 } WINE_PACKED MOVEOFS;
26 typedef struct {
27 DWORD Length;
28 MOVEOFS Source;
29 MOVEOFS Dest;
30 } WINE_PACKED MOVESTRUCT;
32 static BYTE * XMS_Offset( MOVEOFS *ofs )
34 if (ofs->Handle) return (BYTE*)GlobalLock16(ofs->Handle)+ofs->Offset;
35 else return (BYTE*)DOSMEM_MapRealToLinear(ofs->Offset);
38 /**********************************************************************
39 * XMS_Handler
42 void WINAPI XMS_Handler( CONTEXT86 *context )
44 switch(AH_reg(context))
46 case 0x00: /* Get XMS version number */
47 TRACE("get XMS version number\n");
48 AX_reg(context) = 0x0200; /* 2.0 */
49 BX_reg(context) = 0x0000; /* internal revision */
50 DX_reg(context) = 0x0001; /* HMA exists */
51 break;
52 case 0x08: /* Query Free Extended Memory */
54 MEMMANINFO mmi;
56 TRACE("query free extended memory\n");
57 mmi.dwSize = sizeof(mmi);
58 MemManInfo16(&mmi);
59 AX_reg(context) = mmi.dwLargestFreeBlock >> 10;
60 DX_reg(context) = (mmi.dwFreePages * VIRTUAL_GetPageSize()) >> 10;
61 TRACE("returning largest %dK, total %dK\n", AX_reg(context), DX_reg(context));
63 break;
64 case 0x09: /* Allocate Extended Memory Block */
65 TRACE("allocate extended memory block (%dK)\n",
66 DX_reg(context));
67 DX_reg(context) = GlobalAlloc16(GMEM_MOVEABLE,
68 (DWORD)DX_reg(context)<<10);
69 AX_reg(context) = DX_reg(context) ? 1 : 0;
70 if (!DX_reg(context)) BL_reg(context) = 0xA0; /* out of memory */
71 break;
72 case 0x0a: /* Free Extended Memory Block */
73 TRACE("free extended memory block %04x\n",DX_reg(context));
74 GlobalFree16(DX_reg(context));
75 break;
76 case 0x0b: /* Move Extended Memory Block */
78 MOVESTRUCT*move=CTX_SEG_OFF_TO_LIN(context,
79 DS_reg(context),ESI_reg(context));
80 BYTE*src,*dst;
81 TRACE("move extended memory block\n");
82 src=XMS_Offset(&move->Source);
83 dst=XMS_Offset(&move->Dest);
84 memcpy(dst,src,move->Length);
85 if (move->Source.Handle) GlobalUnlock16(move->Source.Handle);
86 if (move->Dest.Handle) GlobalUnlock16(move->Dest.Handle);
87 break;
89 default:
90 INT_BARF( context, 0x31 );
91 AX_reg(context) = 0x0000; /* failure */
92 BL_reg(context) = 0x80; /* function not implemented */
93 break;