#include "pch.hpp"
//===========================================================================//
// File:	 DirectInput.cpp												 //
// Project:  GameOS					                                         //
// Contents: Interface to DirectInput									     //
//---------------------------------------------------------------------------//
// Date      Who    Modification                                             //
// 01/21/98  AG     Created													 //
//---------------------------------------------------------------------------//
// Copyright (C) 1999 Microsoft Corp.						                 //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//
#include "ErrorHandler.hpp"
#include "DirectXDebugging.hpp"
#include "Windows.hpp"


HRESULT wDirectInputCreate( HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUT* lplpDirectInput, LPUNKNOWN punkOuter )
{
	SPEW(( GROUP_DIRECTINPUT, "DirectInputCreate(0x%x)+",dwVersion ));

	HRESULT result=_DirectInputCreate( hinst, dwVersion, lplpDirectInput, punkOuter );
	if( result!=S_OK )
		PAUSE(( "FAILED (0x%x - %s) - DirectInputCreate(0x%x)+",result,ErrorNumberToMessage(result),dwVersion));

	SPEW(( GROUP_DIRECTINPUT, " -0x%x",(int)*lplpDirectInput));

	return result;
}

HRESULT wDirectInputCreateEx( HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, void** ppvOut, LPUNKNOWN punkOuter )
{
	SPEW(( GROUP_DIRECTINPUT, "DirectInputCreateEx(0x%x,%s)+",dwVersion,GetReturnInterface(riidltf) ));

	HRESULT result=_DirectInputCreateEx( hinst, dwVersion, riidltf, ppvOut, punkOuter );
	if( result!=S_OK )
		PAUSE(( "FAILED (0x%x - %s) - DirectInputCreateEx(0x%x,%s)+",result,ErrorNumberToMessage(result),dwVersion,GetReturnInterface(riidltf) ));

	SPEW(( GROUP_DIRECTINPUT, " -0x%x",(int)*ppvOut));

	return result;
}

HRESULT wCreateDevice( IDirectInput2* lpdi, REFGUID rguid, IDirectInputDevice** lplpDirectInputDevice, LPUNKNOWN pUnkOuter )
{
	SPEW(( GROUP_DIRECTINPUT, "CreateDevice(%s)+", GetDIDevice(rguid) ));

	HRESULT result=lpdi->CreateDevice( rguid, lplpDirectInputDevice,  pUnkOuter );

	SPEW(( GROUP_DIRECTINPUT, " -0x%x",(int)*lplpDirectInputDevice));

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - CreateDevice(%s)", GetDIDevice(rguid) ));

	return result;
}

HRESULT wCreateDeviceEx( IDirectInput7* lpdi, REFGUID rguid, REFIID riid, void** lplpDirectInputDevice, LPUNKNOWN pUnkOuter )
{
	SPEW(( GROUP_DIRECTINPUT, "CreateDeviceEx(%s)+", GetDIDevice(rguid),GetReturnInterface(riid) ));

	HRESULT result=lpdi->CreateDeviceEx( rguid, riid, lplpDirectInputDevice,  pUnkOuter );

	SPEW(( GROUP_DIRECTINPUT, " -0x%x",(int)*lplpDirectInputDevice));

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - CreateDeviceEx(%s)", GetDIDevice(rguid),GetReturnInterface(riid) ));

	return result;
}

HRESULT wSetDataFormat(IDirectInputDevice7* lpdid, LPCDIDATAFORMAT lpdf )
{
	SPEW(( GROUP_DIRECTINPUT, "SetDataFormat(0x%x, %s)", (int)lpdid, GetDIInputFormat(lpdf) ));

	HRESULT result=lpdid->SetDataFormat(lpdf);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetDataFormat(0x%x, %s)",result,ErrorNumberToMessage(result), (int)lpdid, GetDIInputFormat(lpdf) ));

	return result;
}


HRESULT wSetCooperativeLevel( IDirectInputDevice7* lpdid, HWND hwnd, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTINPUT, "SetCooperativeLevel(0x%x, 0x%x, %s)", (DWORD)lpdid, hwnd, GetDICoopFlags(dwFlags) ));

	HRESULT result=lpdid->SetCooperativeLevel( hwnd, dwFlags);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetCooperativeLevel(0x%x, 0x%x, %s)",result, ErrorNumberToMessage(result), (DWORD)lpdid, hwnd, GetDICoopFlags(dwFlags) ));

	return result;
}


HRESULT wUnacquire(IDirectInputDevice7* lpdid)
{
	SPEW(( GROUP_DIRECTINPUT, "Unacquire(0x%x)", (DWORD)lpdid ));

	HRESULT result=lpdid->Unacquire();

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - Unacquire()",result,ErrorNumberToMessage(result)));

	return result;
}


HRESULT wAcquire(IDirectInputDevice7* lpdid)
{
	SPEW(( GROUP_DIRECTINPUT, "Acquire(0x%x)", (DWORD)lpdid ));

	HRESULT result=lpdid->Acquire();

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - Acquire()",result,ErrorNumberToMessage(result)));

	return result;
}

HRESULT wGetDeviceState(IDirectInputDevice7* lpdid, DWORD cbData, LPVOID lpvData )
{
	SPEW(( GROUP_DIRECTINPUT, "GetDeviceState(0x%x: %s)", lpdid, GetInputDevice(cbData) ));

	HRESULT result=lpdid->GetDeviceState(cbData, lpvData);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetDeviceState(0x%x: %s)",result,ErrorNumberToMessage(result), lpdid, GetInputDevice(cbData) ));

	return result;
}

HRESULT wEnumDevices( IDirectInput7* lpdi, DWORD dwDevType, LPDIENUMDEVICESCALLBACK lpCallback, LPVOID pvRef, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTINPUT, "EnumDevices(%s, %s)", GetDIDevType(dwDevType), GetDIEnumFlags(dwFlags) ));

	HRESULT result=lpdi->EnumDevices( dwDevType, lpCallback, pvRef, dwFlags );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - EnumDevices(%s, %s)",result,ErrorNumberToMessage(result), GetDIDevType(dwDevType), GetDIEnumFlags(dwFlags) ));

	return result;
}

HRESULT wSetProperty( IDirectInputDevice7* lpdid, REFGUID rguidProp, LPCDIPROPHEADER pdiph )
{
	SPEW(( GROUP_DIRECTINPUT, "SetProperty(0x%x: %s, 0x%x)", lpdid, GetDIDevice(rguidProp), pdiph ));

	HRESULT result=lpdid->SetProperty( rguidProp, pdiph );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetProperty(0x%x: %s, 0x%x)",result,ErrorNumberToMessage(result), lpdid, GetDIDevice(rguidProp), pdiph ));

	return result;
}

HRESULT wGetDeviceInfo( IDirectInputDevice7* lpdid, LPDIDEVICEINSTANCE pdidi)
{
	SPEW(( GROUP_DIRECTINPUT, "GetDeviceInfo(0x%x)+", lpdid ));

	HRESULT result=lpdid->GetDeviceInfo( pdidi );

	SPEW(( GROUP_DIRECTINPUT, " -%s", pdidi->tszInstanceName ));

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetDeviceInfo(0x%x)",result,ErrorNumberToMessage(result), lpdid ));

	return result;
}


HRESULT wGetCapabilities( IDirectInputDevice7* lpdid, LPDIDEVCAPS lpDIDevCaps )
{
	SPEW(( GROUP_DIRECTINPUT, "GetCapabilities(0x%x)", (int)lpdid ));

	HRESULT result=lpdid->GetCapabilities( lpDIDevCaps );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetCapabilities(0x%x)",result,ErrorNumberToMessage(result), (int)lpdid ));

	return result;
}

HRESULT wGetDeviceData( IDirectInputDevice7* lpdid, DWORD cbObjectData, LPDIDEVICEOBJECTDATA rgdod, LPDWORD pdwInOut, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTINPUT, "GetDeviceData(0x%x, 0x%x, 0x%x, %s)", cbObjectData, rgdod, pdwInOut, GetDIGetDeviceDataFlags(dwFlags) ));

	HRESULT result=lpdid->GetDeviceData( cbObjectData, rgdod, pdwInOut, dwFlags );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetDeviceData(0x%x, 0x%x, 0x%x, %s)",result,ErrorNumberToMessage(result), cbObjectData, rgdod, pdwInOut, GetDIGetDeviceDataFlags(dwFlags) ));

	return result;
}

HRESULT wPoll( IDirectInputDevice7* lpdid2 )
{
	SPEW(( GROUP_DIRECTINPUT, "Poll(0x%x)", lpdid2));

	HRESULT result=lpdid2->Poll();

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - Poll(0x%x)",result,ErrorNumberToMessage(result),lpdid2 ));

	return result;
}

HRESULT wCreateEffect( IDirectInputDevice7* lpdid2, REFGUID rguid, LPCDIEFFECT lpeff, LPDIRECTINPUTEFFECT* ppdeff, LPUNKNOWN punkOuter )
{
	SPEW(( GROUP_DIRECTINPUT, "CreateEffect(%s) +", GetDIDevice(rguid) ));

	HRESULT result=lpdid2->CreateEffect(rguid, lpeff, ppdeff, punkOuter);

	SPEW(( GROUP_DIRECTINPUT, "- 0x%x", (DWORD)*ppdeff ));

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - CreateEffect(%s)", result,ErrorNumberToMessage(result), GetDIDevice(rguid) ));

	return result;
}

HRESULT wStart( IDirectInputEffect* lpdid7, DWORD iterations, DWORD flags )
{
	SPEW(( GROUP_DIRECTINPUT, "Start(%d, 0x%x)", iterations, flags ));

	HRESULT result=lpdid7->Start(iterations, flags);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - Start(%d, 0x%x)", result,ErrorNumberToMessage(result), iterations, flags ));

	return result;
}

HRESULT wStop( IDirectInputEffect* lpdid7 )
{
	SPEW(( GROUP_DIRECTINPUT, "Stop()" ));

	HRESULT result=lpdid7->Stop();

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - Stop()", result,ErrorNumberToMessage(result) ));

	return result;
}

HRESULT wGetEffectStatus( IDirectInputEffect* lpdid7, DWORD * status )
{
	SPEW(( GROUP_DIRECTINPUT, "GetEffectStstus( 0x%x )", status ));

	HRESULT result=lpdid7->GetEffectStatus(status);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetEffectStatus( 0x%x)", result,ErrorNumberToMessage(result), status ));

	return result;
}

HRESULT wDownload( IDirectInputEffect* lpdid7 )
{
	SPEW(( GROUP_DIRECTINPUT, "Download()" ));

	HRESULT result=lpdid7->Download();

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - Download()", result,ErrorNumberToMessage(result) ));

	return result;
}

HRESULT wSetParameters( IDirectInputEffect* lpeff, LPCDIEFFECT lpdi, DWORD flags )
{
	SPEW(( GROUP_DIRECTINPUT, "SetParameters(0x%x, %s)", lpeff, GetEffectFlags(flags) ));

	HRESULT result=lpeff->SetParameters(lpdi, flags);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetParameters(0x%x, %s)", result,ErrorNumberToMessage(result),lpeff, GetEffectFlags(flags) ));

	return result;
}





