Added include protection for unistd.h and sys/time.h.
[wine/multimedia.git] / dlls / winedos / xms.c
blob0b99736003501269763c98cf94d0e102d6ac3a5e
1 /*
2 * XMS v2+ emulation
4 * Copyright 1998 Ove Kåven
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * Note: This XMS emulation is hooked through the DPMI interrupt.
23 #include "config.h"
25 #ifdef HAVE_UNISTD_H
26 # include <unistd.h>
27 #endif
28 #include <string.h>
29 #include "winbase.h"
30 #include "wine/winbase16.h"
31 #include "module.h"
32 #include "miscemu.h"
33 #include "toolhelp.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(int31);
38 typedef struct {
39 WORD Handle;
40 DWORD Offset;
41 } WINE_PACKED MOVEOFS;
43 typedef struct {
44 DWORD Length;
45 MOVEOFS Source;
46 MOVEOFS Dest;
47 } WINE_PACKED MOVESTRUCT;
49 static BYTE * XMS_Offset( MOVEOFS *ofs )
51 if (ofs->Handle) return (BYTE*)GlobalLock16(ofs->Handle)+ofs->Offset;
52 else return (BYTE*)DOSMEM_MapRealToLinear(ofs->Offset);
55 /**********************************************************************
56 * XMS_Handler
59 void WINAPI XMS_Handler( CONTEXT86 *context )
61 switch(AH_reg(context))
63 case 0x00: /* Get XMS version number */
64 TRACE("get XMS version number\n");
65 AX_reg(context) = 0x0200; /* 2.0 */
66 BX_reg(context) = 0x0000; /* internal revision */
67 DX_reg(context) = 0x0001; /* HMA exists */
68 break;
69 case 0x08: /* Query Free Extended Memory */
71 MEMMANINFO mmi;
73 TRACE("query free extended memory\n");
74 mmi.dwSize = sizeof(mmi);
75 MemManInfo16(&mmi);
76 AX_reg(context) = mmi.dwLargestFreeBlock >> 10;
77 DX_reg(context) = (mmi.dwFreePages * mmi.wPageSize) >> 10;
78 TRACE("returning largest %dK, total %dK\n", AX_reg(context), DX_reg(context));
80 break;
81 case 0x09: /* Allocate Extended Memory Block */
82 TRACE("allocate extended memory block (%dK)\n",
83 DX_reg(context));
84 DX_reg(context) = GlobalAlloc16(GMEM_MOVEABLE,
85 (DWORD)DX_reg(context)<<10);
86 AX_reg(context) = DX_reg(context) ? 1 : 0;
87 if (!DX_reg(context)) BL_reg(context) = 0xA0; /* out of memory */
88 break;
89 case 0x0a: /* Free Extended Memory Block */
90 TRACE("free extended memory block %04x\n",DX_reg(context));
91 if(!DX_reg(context) || GlobalFree16(DX_reg(context))) {
92 AX_reg(context) = 0; /* failure */
93 BL_reg(context) = 0xa2; /* invalid handle */
94 } else
95 AX_reg(context) = 1; /* success */
96 break;
97 case 0x0b: /* Move Extended Memory Block */
99 MOVESTRUCT*move=CTX_SEG_OFF_TO_LIN(context,
100 context->SegDs,context->Esi);
101 BYTE*src,*dst;
102 TRACE("move extended memory block\n");
103 src=XMS_Offset(&move->Source);
104 dst=XMS_Offset(&move->Dest);
105 memcpy(dst,src,move->Length);
106 if (move->Source.Handle) GlobalUnlock16(move->Source.Handle);
107 if (move->Dest.Handle) GlobalUnlock16(move->Dest.Handle);
108 break;
110 default:
111 INT_BARF( context, 0x31 );
112 AX_reg(context) = 0x0000; /* failure */
113 BL_reg(context) = 0x80; /* function not implemented */
114 break;