Added comment explaining why we have an ERR rather than a WARN.
[wine/multimedia.git] / msdos / xms.c
blobd4f8e3213771a3f4fe9a833a6d4129fa6be93c40
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 "wine/winbase16.h"
13 #include "global.h"
14 #include "module.h"
15 #include "miscemu.h"
16 #include "toolhelp.h"
17 #include "debugtools.h"
18 #include "selectors.h"
20 DEFAULT_DEBUG_CHANNEL(int31);
22 typedef struct {
23 WORD Handle;
24 DWORD Offset;
25 } WINE_PACKED MOVEOFS;
27 typedef struct {
28 DWORD Length;
29 MOVEOFS Source;
30 MOVEOFS Dest;
31 } WINE_PACKED MOVESTRUCT;
33 static BYTE * XMS_Offset( MOVEOFS *ofs )
35 if (ofs->Handle) return (BYTE*)GlobalLock16(ofs->Handle)+ofs->Offset;
36 else return (BYTE*)DOSMEM_MapRealToLinear(ofs->Offset);
39 /**********************************************************************
40 * XMS_Handler
43 void WINAPI XMS_Handler( CONTEXT86 *context )
45 switch(AH_reg(context))
47 case 0x00: /* Get XMS version number */
48 TRACE("get XMS version number\n");
49 AX_reg(context) = 0x0200; /* 2.0 */
50 BX_reg(context) = 0x0000; /* internal revision */
51 DX_reg(context) = 0x0001; /* HMA exists */
52 break;
53 case 0x08: /* Query Free Extended Memory */
55 MEMMANINFO mmi;
57 TRACE("query free extended memory\n");
58 mmi.dwSize = sizeof(mmi);
59 MemManInfo16(&mmi);
60 AX_reg(context) = mmi.dwLargestFreeBlock >> 10;
61 DX_reg(context) = (mmi.dwFreePages * VIRTUAL_GetPageSize()) >> 10;
62 TRACE("returning largest %dK, total %dK\n", AX_reg(context), DX_reg(context));
64 break;
65 case 0x09: /* Allocate Extended Memory Block */
66 TRACE("allocate extended memory block (%dK)\n",
67 DX_reg(context));
68 DX_reg(context) = GlobalAlloc16(GMEM_MOVEABLE,
69 (DWORD)DX_reg(context)<<10);
70 AX_reg(context) = DX_reg(context) ? 1 : 0;
71 if (!DX_reg(context)) BL_reg(context) = 0xA0; /* out of memory */
72 break;
73 case 0x0a: /* Free Extended Memory Block */
74 TRACE("free extended memory block %04x\n",DX_reg(context));
75 GlobalFree16(DX_reg(context));
76 break;
77 case 0x0b: /* Move Extended Memory Block */
79 MOVESTRUCT*move=CTX_SEG_OFF_TO_LIN(context,
80 context->SegDs,context->Esi);
81 BYTE*src,*dst;
82 TRACE("move extended memory block\n");
83 src=XMS_Offset(&move->Source);
84 dst=XMS_Offset(&move->Dest);
85 memcpy(dst,src,move->Length);
86 if (move->Source.Handle) GlobalUnlock16(move->Source.Handle);
87 if (move->Dest.Handle) GlobalUnlock16(move->Dest.Handle);
88 break;
90 default:
91 INT_BARF( context, 0x31 );
92 AX_reg(context) = 0x0000; /* failure */
93 BL_reg(context) = 0x80; /* function not implemented */
94 break;