4 * Copyright 1998 Ove Kåven
6 * This XMS emulation is hooked through the DPMI interrupt.
12 #include "wine/winbase16.h"
17 #include "debugtools.h"
18 #include "selectors.h"
20 DEFAULT_DEBUG_CHANNEL(int31
);
25 } WINE_PACKED MOVEOFS
;
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 /**********************************************************************
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 */
53 case 0x08: /* Query Free Extended Memory */
57 TRACE("query free extended memory\n");
58 mmi
.dwSize
= sizeof(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
));
65 case 0x09: /* Allocate Extended Memory Block */
66 TRACE("allocate extended memory block (%dK)\n",
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 */
73 case 0x0a: /* Free Extended Memory Block */
74 TRACE("free extended memory block %04x\n",DX_reg(context
));
75 GlobalFree16(DX_reg(context
));
77 case 0x0b: /* Move Extended Memory Block */
79 MOVESTRUCT
*move
=CTX_SEG_OFF_TO_LIN(context
,
80 context
->SegDs
,context
->Esi
);
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
);
91 INT_BARF( context
, 0x31 );
92 AX_reg(context
) = 0x0000; /* failure */
93 BL_reg(context
) = 0x80; /* function not implemented */