1998-10-11 14:16:56 +02:00
|
|
|
|
/*
|
|
|
|
|
* XMS v2+ emulation
|
|
|
|
|
*
|
|
|
|
|
* Copyright 1998 Ove K<EFBFBD>ven
|
|
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*
|
|
|
|
|
* Note: This XMS emulation is hooked through the DPMI interrupt.
|
1998-10-11 14:16:56 +02:00
|
|
|
|
*/
|
|
|
|
|
|
2002-08-17 02:43:16 +02:00
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
|
# include <unistd.h>
|
|
|
|
|
#endif
|
1998-10-11 14:16:56 +02:00
|
|
|
|
#include <string.h>
|
1999-02-24 14:05:13 +01:00
|
|
|
|
#include "winbase.h"
|
2000-09-27 00:20:14 +02:00
|
|
|
|
#include "wine/winbase16.h"
|
1998-10-11 14:16:56 +02:00
|
|
|
|
#include "module.h"
|
|
|
|
|
#include "miscemu.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
|
#include "wine/debug.h"
|
1998-10-11 14:16:56 +02:00
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(int31);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
|
1998-10-11 14:16:56 +02:00
|
|
|
|
typedef struct {
|
|
|
|
|
WORD Handle;
|
|
|
|
|
DWORD Offset;
|
|
|
|
|
} WINE_PACKED MOVEOFS;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
DWORD Length;
|
|
|
|
|
MOVEOFS Source;
|
|
|
|
|
MOVEOFS Dest;
|
|
|
|
|
} WINE_PACKED MOVESTRUCT;
|
|
|
|
|
|
|
|
|
|
static BYTE * XMS_Offset( MOVEOFS *ofs )
|
|
|
|
|
{
|
|
|
|
|
if (ofs->Handle) return (BYTE*)GlobalLock16(ofs->Handle)+ofs->Offset;
|
2002-08-30 02:03:25 +02:00
|
|
|
|
else return (BYTE*)PTR_REAL_TO_LIN(SELECTOROF(ofs->Offset),OFFSETOF(ofs->Offset));
|
1998-10-11 14:16:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
|
* XMS_Handler
|
|
|
|
|
*/
|
|
|
|
|
|
1999-06-26 20:40:24 +02:00
|
|
|
|
void WINAPI XMS_Handler( CONTEXT86 *context )
|
1998-10-11 14:16:56 +02:00
|
|
|
|
{
|
|
|
|
|
switch(AH_reg(context))
|
|
|
|
|
{
|
|
|
|
|
case 0x00: /* Get XMS version number */
|
1999-06-26 21:09:08 +02:00
|
|
|
|
TRACE("get XMS version number\n");
|
2002-08-31 20:47:00 +02:00
|
|
|
|
SET_AX( context, 0x0200 ); /* 2.0 */
|
|
|
|
|
SET_BX( context, 0x0000 ); /* internal revision */
|
|
|
|
|
SET_DX( context, 0x0001 ); /* HMA exists */
|
1998-10-11 14:16:56 +02:00
|
|
|
|
break;
|
|
|
|
|
case 0x08: /* Query Free Extended Memory */
|
|
|
|
|
{
|
2002-08-30 02:03:25 +02:00
|
|
|
|
MEMORYSTATUS status;
|
1998-10-11 14:16:56 +02:00
|
|
|
|
|
1999-06-26 21:09:08 +02:00
|
|
|
|
TRACE("query free extended memory\n");
|
2002-08-30 02:03:25 +02:00
|
|
|
|
GlobalMemoryStatus( &status );
|
2002-08-31 20:47:00 +02:00
|
|
|
|
SET_DX( context, status.dwAvailVirtual >> 10 );
|
|
|
|
|
SET_AX( context, status.dwAvailVirtual >> 10 );
|
1999-06-26 21:09:08 +02:00
|
|
|
|
TRACE("returning largest %dK, total %dK\n", AX_reg(context), DX_reg(context));
|
1998-10-11 14:16:56 +02:00
|
|
|
|
}
|
1999-01-30 14:41:57 +01:00
|
|
|
|
break;
|
1998-10-11 14:16:56 +02:00
|
|
|
|
case 0x09: /* Allocate Extended Memory Block */
|
1999-06-26 21:09:08 +02:00
|
|
|
|
TRACE("allocate extended memory block (%dK)\n",
|
1998-10-11 14:16:56 +02:00
|
|
|
|
DX_reg(context));
|
2002-08-31 20:47:00 +02:00
|
|
|
|
SET_DX( context, GlobalAlloc16(GMEM_MOVEABLE, (DWORD)DX_reg(context)<<10) );
|
|
|
|
|
SET_AX( context, DX_reg(context) ? 1 : 0 );
|
|
|
|
|
if (!DX_reg(context)) SET_BL( context, 0xA0 ); /* out of memory */
|
1998-10-11 14:16:56 +02:00
|
|
|
|
break;
|
|
|
|
|
case 0x0a: /* Free Extended Memory Block */
|
1999-06-26 21:09:08 +02:00
|
|
|
|
TRACE("free extended memory block %04x\n",DX_reg(context));
|
2002-04-29 19:12:29 +02:00
|
|
|
|
if(!DX_reg(context) || GlobalFree16(DX_reg(context))) {
|
2002-08-31 20:47:00 +02:00
|
|
|
|
SET_AX( context, 0 ); /* failure */
|
|
|
|
|
SET_BL( context, 0xa2 ); /* invalid handle */
|
2002-04-29 19:12:29 +02:00
|
|
|
|
} else
|
2002-08-31 20:47:00 +02:00
|
|
|
|
SET_AX( context, 1 ); /* success */
|
1998-10-11 14:16:56 +02:00
|
|
|
|
break;
|
|
|
|
|
case 0x0b: /* Move Extended Memory Block */
|
|
|
|
|
{
|
|
|
|
|
MOVESTRUCT*move=CTX_SEG_OFF_TO_LIN(context,
|
2000-09-26 01:53:07 +02:00
|
|
|
|
context->SegDs,context->Esi);
|
1998-10-11 14:16:56 +02:00
|
|
|
|
BYTE*src,*dst;
|
1999-06-26 21:09:08 +02:00
|
|
|
|
TRACE("move extended memory block\n");
|
1998-10-11 14:16:56 +02:00
|
|
|
|
src=XMS_Offset(&move->Source);
|
|
|
|
|
dst=XMS_Offset(&move->Dest);
|
|
|
|
|
memcpy(dst,src,move->Length);
|
|
|
|
|
if (move->Source.Handle) GlobalUnlock16(move->Source.Handle);
|
|
|
|
|
if (move->Dest.Handle) GlobalUnlock16(move->Dest.Handle);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
INT_BARF( context, 0x31 );
|
2002-08-31 20:47:00 +02:00
|
|
|
|
SET_AX( context, 0x0000 ); /* failure */
|
|
|
|
|
SET_BL( context, 0x80 ); /* function not implemented */
|
1998-10-11 14:16:56 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|