Adds support for EMR_STRETCHDIBITS in EMFs.
[wine/wine64.git] / msdos / xms.c
blob07d10378d79c8a6a62d2e0539ef4015a3e6dc45f
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 "windows.h"
12 #include "module.h"
13 #include "miscemu.h"
14 #include "toolhelp.h"
15 #include "debug.h"
16 #include "selectors.h"
18 typedef struct {
19 WORD Handle;
20 DWORD Offset;
21 } WINE_PACKED MOVEOFS;
23 typedef struct {
24 DWORD Length;
25 MOVEOFS Source;
26 MOVEOFS Dest;
27 } WINE_PACKED MOVESTRUCT;
29 static BYTE * XMS_Offset( MOVEOFS *ofs )
31 if (ofs->Handle) return (BYTE*)GlobalLock16(ofs->Handle)+ofs->Offset;
32 else return (BYTE*)DOSMEM_MapRealToLinear(ofs->Offset);
35 /**********************************************************************
36 * XMS_Handler
39 void WINAPI XMS_Handler( CONTEXT *context )
41 switch(AH_reg(context))
43 case 0x00: /* Get XMS version number */
44 TRACE(int31, "get XMS version number\n");
45 AX_reg(context) = 0x0200; /* 2.0 */
46 BX_reg(context) = 0x0000; /* internal revision */
47 DX_reg(context) = 0x0001; /* HMA exists */
48 break;
49 case 0x08: /* Query Free Extended Memory */
51 MEMMANINFO mmi;
53 TRACE(int31, "query free extended memory\n");
54 mmi.dwSize = sizeof(mmi);
55 MemManInfo(&mmi);
56 AX_reg(context) = mmi.dwLargestFreeBlock >> 10;
57 DX_reg(context) = (mmi.dwFreePages * VIRTUAL_GetPageSize()) >> 10;
58 TRACE(int31, "returning largest %dK, total %dK\n", AX_reg(context), DX_reg(context));
60 break;
61 case 0x09: /* Allocate Extended Memory Block */
62 TRACE(int31, "allocate extended memory block (%dK)\n",
63 DX_reg(context));
64 DX_reg(context) = GlobalAlloc16(GMEM_MOVEABLE,
65 (DWORD)DX_reg(context)<<10);
66 AX_reg(context) = DX_reg(context) ? 1 : 0;
67 if (!DX_reg(context)) BL_reg(context) = 0xA0; /* out of memory */
68 break;
69 case 0x0a: /* Free Extended Memory Block */
70 TRACE(int31, "free extended memory block %04x\n",DX_reg(context));
71 GlobalFree16(DX_reg(context));
72 break;
73 case 0x0b: /* Move Extended Memory Block */
75 MOVESTRUCT*move=CTX_SEG_OFF_TO_LIN(context,
76 DS_reg(context),ESI_reg(context));
77 BYTE*src,*dst;
78 TRACE(int31, "move extended memory block\n");
79 src=XMS_Offset(&move->Source);
80 dst=XMS_Offset(&move->Dest);
81 memcpy(dst,src,move->Length);
82 if (move->Source.Handle) GlobalUnlock16(move->Source.Handle);
83 if (move->Dest.Handle) GlobalUnlock16(move->Dest.Handle);
84 break;
86 default:
87 INT_BARF( context, 0x31 );
88 AX_reg(context) = 0x0000; /* failure */
89 BL_reg(context) = 0x80; /* function not implemented */
90 break;