Added YUV routines needed for v4l driver, and in the future possibly
[wine/gsoc-2012-control.git] / dlls / winedos / xms.c
blobac99409dab4ea15f9ad7b1c63fae786e76e63d3f
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 <stdarg.h>
29 #include <string.h>
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wine/winbase16.h"
33 #include "dosexe.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(int31);
38 #include "pshpack1.h"
40 typedef struct {
41 WORD Handle;
42 DWORD Offset;
43 } MOVEOFS;
45 typedef struct {
46 DWORD Length;
47 MOVEOFS Source;
48 MOVEOFS Dest;
49 } MOVESTRUCT;
51 #include "poppack.h"
53 static BYTE * XMS_Offset( MOVEOFS *ofs )
55 if (ofs->Handle) return (BYTE*)GlobalLock16(ofs->Handle)+ofs->Offset;
56 else return (BYTE*)PTR_REAL_TO_LIN(SELECTOROF(ofs->Offset),OFFSETOF(ofs->Offset));
59 /**********************************************************************
60 * XMS_Handler
63 void WINAPI XMS_Handler( CONTEXT86 *context )
65 switch(AH_reg(context))
67 case 0x00: /* Get XMS version number */
68 TRACE("get XMS version number\n");
69 SET_AX( context, 0x0200 ); /* 2.0 */
70 SET_BX( context, 0x0000 ); /* internal revision */
71 SET_DX( context, 0x0001 ); /* HMA exists */
72 break;
73 case 0x08: /* Query Free Extended Memory */
75 MEMORYSTATUS status;
77 TRACE("query free extended memory\n");
78 GlobalMemoryStatus( &status );
79 SET_DX( context, status.dwAvailVirtual >> 10 );
80 SET_AX( context, status.dwAvailVirtual >> 10 );
81 TRACE("returning largest %dK, total %dK\n", AX_reg(context), DX_reg(context));
83 break;
84 case 0x09: /* Allocate Extended Memory Block */
85 TRACE("allocate extended memory block (%dK)\n",
86 DX_reg(context));
87 SET_DX( context, GlobalAlloc16(GMEM_MOVEABLE, (DWORD)DX_reg(context)<<10) );
88 SET_AX( context, DX_reg(context) ? 1 : 0 );
89 if (!DX_reg(context)) SET_BL( context, 0xA0 ); /* out of memory */
90 break;
91 case 0x0a: /* Free Extended Memory Block */
92 TRACE("free extended memory block %04x\n",DX_reg(context));
93 if(!DX_reg(context) || GlobalFree16(DX_reg(context))) {
94 SET_AX( context, 0 ); /* failure */
95 SET_BL( context, 0xa2 ); /* invalid handle */
96 } else
97 SET_AX( context, 1 ); /* success */
98 break;
99 case 0x0b: /* Move Extended Memory Block */
101 MOVESTRUCT*move=CTX_SEG_OFF_TO_LIN(context,
102 context->SegDs,context->Esi);
103 BYTE*src,*dst;
104 TRACE("move extended memory block\n");
105 src=XMS_Offset(&move->Source);
106 dst=XMS_Offset(&move->Dest);
107 memcpy(dst,src,move->Length);
108 if (move->Source.Handle) GlobalUnlock16(move->Source.Handle);
109 if (move->Dest.Handle) GlobalUnlock16(move->Dest.Handle);
110 break;
112 case 0x88: /* Query Any Free Extended Memory */
114 MEMORYSTATUS status;
115 SYSTEM_INFO info;
117 TRACE("query any free extended memory\n");
119 GlobalMemoryStatus( &status );
120 GetSystemInfo( &info );
121 context->Eax = status.dwAvailVirtual >> 10;
122 context->Edx = status.dwAvailVirtual >> 10;
123 context->Ecx = (DWORD)info.lpMaximumApplicationAddress;
124 SET_BL( context, 0 ); /* No errors. */
126 TRACE("returning largest %ldK, total %ldK, highest 0x%lx\n",
127 context->Eax, context->Edx, context->Ecx);
129 break;
130 default:
131 INT_BARF( context, 0x31 );
132 SET_AX( context, 0x0000 ); /* failure */
133 SET_BL( context, 0x80 ); /* function not implemented */
134 break;