4 * Copyright 1998 Ove Kåven
6 * This XMS emulation is hooked through the DPMI interrupt.
12 #include "wine/winbase16.h"
16 #include "debugtools.h"
18 DEFAULT_DEBUG_CHANNEL(int31);
23 } WINE_PACKED MOVEOFS;
29 } WINE_PACKED MOVESTRUCT;
31 static BYTE * XMS_Offset( MOVEOFS *ofs )
33 if (ofs->Handle) return (BYTE*)GlobalLock16(ofs->Handle)+ofs->Offset;
34 else return (BYTE*)DOSMEM_MapRealToLinear(ofs->Offset);
37 /**********************************************************************
41 void WINAPI XMS_Handler( CONTEXT86 *context )
43 switch(AH_reg(context))
45 case 0x00: /* Get XMS version number */
46 TRACE("get XMS version number\n");
47 AX_reg(context) = 0x0200; /* 2.0 */
48 BX_reg(context) = 0x0000; /* internal revision */
49 DX_reg(context) = 0x0001; /* HMA exists */
51 case 0x08: /* Query Free Extended Memory */
55 TRACE("query free extended memory\n");
56 mmi.dwSize = sizeof(mmi);
58 AX_reg(context) = mmi.dwLargestFreeBlock >> 10;
59 DX_reg(context) = (mmi.dwFreePages * mmi.wPageSize) >> 10;
60 TRACE("returning largest %dK, total %dK\n", AX_reg(context), DX_reg(context));
63 case 0x09: /* Allocate Extended Memory Block */
64 TRACE("allocate extended memory block (%dK)\n",
66 DX_reg(context) = GlobalAlloc16(GMEM_MOVEABLE,
67 (DWORD)DX_reg(context)<<10);
68 AX_reg(context) = DX_reg(context) ? 1 : 0;
69 if (!DX_reg(context)) BL_reg(context) = 0xA0; /* out of memory */
71 case 0x0a: /* Free Extended Memory Block */
72 TRACE("free extended memory block %04x\n",DX_reg(context));
73 GlobalFree16(DX_reg(context));
75 case 0x0b: /* Move Extended Memory Block */
77 MOVESTRUCT*move=CTX_SEG_OFF_TO_LIN(context,
78 context->SegDs,context->Esi);
80 TRACE("move extended memory block\n");
81 src=XMS_Offset(&move->Source);
82 dst=XMS_Offset(&move->Dest);
83 memcpy(dst,src,move->Length);
84 if (move->Source.Handle) GlobalUnlock16(move->Source.Handle);
85 if (move->Dest.Handle) GlobalUnlock16(move->Dest.Handle);
89 INT_BARF( context, 0x31 );
90 AX_reg(context) = 0x0000; /* failure */
91 BL_reg(context) = 0x80; /* function not implemented */