Cumulative changes required to enable / ease compilation in Linux with gcc. (PR #861)

Split MouseInterface to isolate DirectInput code.
Avoid overflow in platforms where RAND_MAX is a big integer constant.
Fix include files for gcc (where enums cannot be forward declared).
This commit is contained in:
Andrea 2020-11-10 20:33:55 +00:00 committed by GitHub
parent 3d8acbbc83
commit 8cc04e2b86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 317 additions and 239 deletions

View File

@ -62,6 +62,7 @@
<ClInclude Include="source\Debugger\Debugger_Types.h" /> <ClInclude Include="source\Debugger\Debugger_Types.h" />
<ClInclude Include="source\Debugger\Util_MemoryTextFile.h" /> <ClInclude Include="source\Debugger\Util_MemoryTextFile.h" />
<ClInclude Include="source\Debugger\Util_Text.h" /> <ClInclude Include="source\Debugger\Util_Text.h" />
<ClInclude Include="source\DirectInput.h" />
<ClInclude Include="source\Disk.h" /> <ClInclude Include="source\Disk.h" />
<ClInclude Include="source\Disk2CardManager.h" /> <ClInclude Include="source\Disk2CardManager.h" />
<ClInclude Include="source\DiskDefs.h" /> <ClInclude Include="source\DiskDefs.h" />
@ -96,6 +97,7 @@
<ClInclude Include="source\Speech.h" /> <ClInclude Include="source\Speech.h" />
<ClInclude Include="source\SSI263Phonemes.h" /> <ClInclude Include="source\SSI263Phonemes.h" />
<ClInclude Include="source\StdAfx.h" /> <ClInclude Include="source\StdAfx.h" />
<ClInclude Include="source\SynchronousEventManager.h" />
<ClInclude Include="source\Tape.h" /> <ClInclude Include="source\Tape.h" />
<ClInclude Include="source\Tfe\Bittypes.h" /> <ClInclude Include="source\Tfe\Bittypes.h" />
<ClInclude Include="source\Tfe\Bpf.h" /> <ClInclude Include="source\Tfe\Bpf.h" />
@ -138,6 +140,7 @@
<ClCompile Include="source\Configuration\PropertySheet.cpp" /> <ClCompile Include="source\Configuration\PropertySheet.cpp" />
<ClCompile Include="source\Configuration\PropertySheetHelper.cpp" /> <ClCompile Include="source\Configuration\PropertySheetHelper.cpp" />
<ClCompile Include="source\CPU.cpp" /> <ClCompile Include="source\CPU.cpp" />
<ClCompile Include="source\DirectInput.cpp" />
<ClCompile Include="source\Disk2CardManager.cpp" /> <ClCompile Include="source\Disk2CardManager.cpp" />
<ClCompile Include="source\RGBMonitor.cpp" /> <ClCompile Include="source\RGBMonitor.cpp" />
<ClCompile Include="source\SAM.cpp" /> <ClCompile Include="source\SAM.cpp" />
@ -184,6 +187,7 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release NoDX|Win32'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release NoDX|Win32'">Create</PrecompiledHeader>
</ClCompile> </ClCompile>
<ClCompile Include="source\SynchronousEventManager.cpp" />
<ClCompile Include="source\Tape.cpp" /> <ClCompile Include="source\Tape.cpp" />
<ClCompile Include="source\Tfe\Tfe.cpp"> <ClCompile Include="source\Tfe\Tfe.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>

View File

@ -199,6 +199,12 @@
<ClCompile Include="source\CardManager.cpp"> <ClCompile Include="source\CardManager.cpp">
<Filter>Source Files\Emulator</Filter> <Filter>Source Files\Emulator</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="source\SynchronousEventManager.cpp">
<Filter>Source Files\Emulator</Filter>
</ClCompile>
<ClCompile Include="source\DirectInput.cpp">
<Filter>Source Files\Emulator</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="source\Applewin.h"> <ClInclude Include="source\Applewin.h">
@ -483,6 +489,12 @@
<ClInclude Include="source\CardManager.h"> <ClInclude Include="source\CardManager.h">
<Filter>Source Files\Emulator</Filter> <Filter>Source Files\Emulator</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="source\SynchronousEventManager.h">
<Filter>Source Files\Emulator</Filter>
</ClInclude>
<ClInclude Include="source\DirectInput.h">
<Filter>Source Files\Emulator</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Image Include="resource\Applewin.bmp"> <Image Include="resource\Applewin.bmp">

View File

@ -62,6 +62,7 @@
<ClInclude Include="source\Debugger\Debugger_Types.h" /> <ClInclude Include="source\Debugger\Debugger_Types.h" />
<ClInclude Include="source\Debugger\Util_MemoryTextFile.h" /> <ClInclude Include="source\Debugger\Util_MemoryTextFile.h" />
<ClInclude Include="source\Debugger\Util_Text.h" /> <ClInclude Include="source\Debugger\Util_Text.h" />
<ClInclude Include="source\DirectInput.h" />
<ClInclude Include="source\Disk.h" /> <ClInclude Include="source\Disk.h" />
<ClInclude Include="source\Disk2CardManager.h" /> <ClInclude Include="source\Disk2CardManager.h" />
<ClInclude Include="source\DiskDefs.h" /> <ClInclude Include="source\DiskDefs.h" />
@ -139,6 +140,7 @@
<ClCompile Include="source\Configuration\PropertySheet.cpp" /> <ClCompile Include="source\Configuration\PropertySheet.cpp" />
<ClCompile Include="source\Configuration\PropertySheetHelper.cpp" /> <ClCompile Include="source\Configuration\PropertySheetHelper.cpp" />
<ClCompile Include="source\CPU.cpp" /> <ClCompile Include="source\CPU.cpp" />
<ClCompile Include="source\DirectInput.cpp" />
<ClCompile Include="source\Disk2CardManager.cpp" /> <ClCompile Include="source\Disk2CardManager.cpp" />
<ClCompile Include="source\RGBMonitor.cpp" /> <ClCompile Include="source\RGBMonitor.cpp" />
<ClCompile Include="source\SAM.cpp" /> <ClCompile Include="source\SAM.cpp" />

View File

@ -202,6 +202,9 @@
<ClCompile Include="source\SynchronousEventManager.cpp"> <ClCompile Include="source\SynchronousEventManager.cpp">
<Filter>Source Files\Emulator</Filter> <Filter>Source Files\Emulator</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="source\DirectInput.cpp">
<Filter>Source Files\Emulator</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="source\Applewin.h"> <ClInclude Include="source\Applewin.h">
@ -489,6 +492,9 @@
<ClInclude Include="source\SynchronousEventManager.h"> <ClInclude Include="source\SynchronousEventManager.h">
<Filter>Source Files\Emulator</Filter> <Filter>Source Files\Emulator</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="source\DirectInput.h">
<Filter>Source Files\Emulator</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Image Include="resource\Applewin.bmp"> <Image Include="resource\Applewin.bmp">

257
source/DirectInput.cpp Normal file
View File

@ -0,0 +1,257 @@
/*
AppleWin : An Apple //e emulator for Windows
Copyright (C) 1994-1996, Michael O'Brien
Copyright (C) 1999-2001, Oliver Schmidt
Copyright (C) 2002-2005, Tom Charlesworth
Copyright (C) 2006-2010, Tom Charlesworth, Michael Pohoreski
AppleWin is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
AppleWin 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with AppleWin; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Description: Disk Image
*
* Author: Various
*/
#include "StdAfx.h"
//=============================================================================
// DirectInput interface
//=============================================================================
//#define STRICT
#define DIRECTINPUT_VERSION 0x0800
#include "SoundCore.h" // SAFE_RELEASE()
#include "Log.h"
#include "DirectInput.h"
#include "Common.h"
#include <dinput.h>
extern bool g_bDisableDirectInput; // currently in AppleWin.h
namespace DIMouse
{
static LPDIRECTINPUT8 g_pDI = NULL;
static LPDIRECTINPUTDEVICE8 g_pMouse = NULL;
#define SAMPLE_BUFFER_SIZE 16 // arbitrary number of buffer elements
static UINT_PTR g_TimerIDEvent = 0;
//-----------------------------------------------------------------------------
// Name: OnCreateDevice()
// Desc: Sets up the mouse device using the flags from the dialog.
//-----------------------------------------------------------------------------
HRESULT DirectInputInit( HWND hDlg )
{
LogFileOutput("DirectInputInit: g_bDisableDirectInput=%d\n", g_bDisableDirectInput);
if (g_bDisableDirectInput)
return S_OK;
#ifdef NO_DIRECT_X
return E_FAIL;
#else // NO_DIRECT_X
HRESULT hr;
BOOL bExclusive;
BOOL bForeground;
BOOL bImmediate;
DWORD dwCoopFlags;
DirectInputUninit(hDlg);
LogFileOutput("DirectInputInit: DirectInputUninit()\n");
// Determine where the buffer would like to be allocated
bExclusive = FALSE;
bForeground = FALSE; // Otherwise get DIERR_OTHERAPPHASPRIO (== E_ACCESSDENIED) on Acquire()
bImmediate = TRUE;
if( bExclusive )
dwCoopFlags = DISCL_EXCLUSIVE;
else
dwCoopFlags = DISCL_NONEXCLUSIVE;
if( bForeground )
dwCoopFlags |= DISCL_FOREGROUND;
else
dwCoopFlags |= DISCL_BACKGROUND;
// Create a DInput object
hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&g_pDI, NULL );
LogFileOutput("DirectInputInit: DirectInput8Create(), hr=0x%08X\n", hr);
if (FAILED(hr))
return hr;
// Obtain an interface to the system mouse device.
hr = g_pDI->CreateDevice( GUID_SysMouse, &g_pMouse, NULL );
LogFileOutput("DirectInputInit: CreateDevice(), hr=0x%08X\n", hr);
if (FAILED(hr))
return hr;
// Set the data format to "mouse format" - a predefined data format
//
// A data format specifies which controls on a device we
// are interested in, and how they should be reported.
//
// This tells DirectInput that we will be passing a
// DIMOUSESTATE2 structure to IDirectInputDevice::GetDeviceState.
hr = g_pMouse->SetDataFormat( &c_dfDIMouse2 );
LogFileOutput("DirectInputInit: SetDataFormat(), hr=0x%08X\n", hr);
if (FAILED(hr))
return hr;
// Set the cooperativity level to let DirectInput know how
// this device should interact with the system and with other
// DirectInput applications.
hr = g_pMouse->SetCooperativeLevel( hDlg, dwCoopFlags );
LogFileOutput("DirectInputInit: SetCooperativeLevel(), hr=0x%08X\n", hr);
if( hr == DIERR_UNSUPPORTED && !bForeground && bExclusive )
{
DirectInputUninit(hDlg);
LogFileOutput("DirectInputInit: DirectInputUninit()n");
//MessageBox( hDlg, _T("SetCooperativeLevel() returned DIERR_UNSUPPORTED.\n")
// _T("For security reasons, background exclusive mouse\n")
// _T("access is not allowed."),
// _T("Mouse"), MB_OK );
return S_OK;
}
if( FAILED(hr) )
return hr;
if( !bImmediate )
{
// IMPORTANT STEP TO USE BUFFERED DEVICE DATA!
//
// DirectInput uses unbuffered I/O (buffer size = 0) by default.
// If you want to read buffered data, you need to set a nonzero
// buffer size.
//
// Set the buffer size to SAMPLE_BUFFER_SIZE (defined above) elements.
//
// The buffer size is a DWORD property associated with the device.
DIPROPDWORD dipdw;
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = SAMPLE_BUFFER_SIZE; // Arbitary buffer size
hr = g_pMouse->SetProperty( DIPROP_BUFFERSIZE, &dipdw.diph );
LogFileOutput("DirectInputInit: SetProperty(), hr=0x%08X\n", hr);
if (FAILED(hr))
return hr;
}
// Acquire the newly created device
hr = g_pMouse->Acquire();
LogFileOutput("DirectInputInit: Acquire(), hr=0x%08X\n", hr);
if (FAILED(hr))
return hr;
// Setup timer to read mouse position
_ASSERT(g_TimerIDEvent == 0);
g_TimerIDEvent = SetTimer(hDlg, IDEVENT_TIMER_MOUSE, 8, NULL); // 120Hz timer
LogFileOutput("DirectInputInit: SetTimer(), id=0x%08X\n", g_TimerIDEvent);
if (g_TimerIDEvent == 0)
return E_FAIL;
return S_OK;
#endif // NO_DIRECT_X
}
//-----------------------------------------------------------------------------
// Name: FreeDirectInput()
// Desc: Initialize the DirectInput variables.
//-----------------------------------------------------------------------------
void DirectInputUninit( HWND hDlg )
{
LogFileOutput("DirectInputUninit\n");
// Unacquire the device one last time just in case
// the app tried to exit while the device is still acquired.
if( g_pMouse )
{
HRESULT hr = g_pMouse->Unacquire();
LogFileOutput("DirectInputUninit: Unacquire(), hr=0x%08X\n", hr);
}
// Release any DirectInput objects.
SAFE_RELEASE( g_pMouse );
SAFE_RELEASE( g_pDI );
if (g_TimerIDEvent)
{
BOOL bRes = KillTimer(hDlg, g_TimerIDEvent);
LogFileOutput("DirectInputUninit: KillTimer(), res=%d\n", bRes ? 1 : 0);
g_TimerIDEvent = 0;
}
}
//-----------------------------------------------------------------------------
// Name: ReadImmediateData()
// Desc: Read the input device's state when in immediate mode and display it.
//-----------------------------------------------------------------------------
HRESULT ReadImmediateData( long* pX, long* pY )
{
HRESULT hr;
DIMOUSESTATE2 dims2; // DirectInput mouse state structure
if (pX) *pX = 0;
if (pY) *pY = 0;
if( NULL == g_pMouse )
return S_OK;
// Get the input's device state, and put the state in dims
ZeroMemory( &dims2, sizeof(dims2) );
hr = g_pMouse->GetDeviceState( sizeof(DIMOUSESTATE2), &dims2 );
if( FAILED(hr) )
{
// DirectInput may be telling us that the input stream has been
// interrupted. We aren't tracking any state between polls, so
// we don't have any special reset that needs to be done.
// We just re-acquire and try again.
// If input is lost then acquire and keep trying
hr = g_pMouse->Acquire();
while( hr == DIERR_INPUTLOST )
hr = g_pMouse->Acquire();
// Update the dialog text
if( hr == DIERR_OTHERAPPHASPRIO ||
hr == DIERR_NOTACQUIRED )
{
//SetDlgItemText( hDlg, IDC_DATA, TEXT("Unacquired") );
}
// hr may be DIERR_OTHERAPPHASPRIO or other errors. This
// may occur when the app is minimized or in the process of
// switching, so just try again later
return S_OK;
}
if (pX) *pX = dims2.lX;
if (pY) *pY = dims2.lY;
return S_OK;
}
}; // namespace DIMouse

9
source/DirectInput.h Normal file
View File

@ -0,0 +1,9 @@
#pragma once
namespace DIMouse
{
HRESULT DirectInputInit( HWND hDlg );
void DirectInputUninit( HWND hDlg );
HRESULT ReadImmediateData( long* pX=NULL, long* pY=NULL );
};

View File

@ -1190,7 +1190,7 @@ void Disk2InterfaceCard::DataLatchReadWOZ(WORD pc, WORD addr, UINT bitCellRemain
drive.m_headWindow <<= 1; drive.m_headWindow <<= 1;
drive.m_headWindow |= (n & floppy.m_bitMask) ? 1 : 0; drive.m_headWindow |= (n & floppy.m_bitMask) ? 1 : 0;
BYTE outputBit = (drive.m_headWindow & 0xf) ? (drive.m_headWindow >> 1) & 1 BYTE outputBit = (drive.m_headWindow & 0xf) ? (drive.m_headWindow >> 1) & 1
: (rand() < ((RAND_MAX * 3) / 10)) ? 1 : 0; // ~30% chance of a 1 bit (Ref: WOZ-2.0) : (rand() < RAND_THRESHOLD(3, 10)) ? 1 : 0; // ~30% chance of a 1 bit (Ref: WOZ-2.0)
IncBitStream(floppy); IncBitStream(floppy);

View File

@ -25,6 +25,18 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "DiskDefs.h" #include "DiskDefs.h"
#ifdef _MSC_VER
#define RAND_THRESHOLD(num, den) ((RAND_MAX * num) / den)
#else
// RAND_MAX is a massive number which overflows when (* num) is applied above
#define RAND_THRESHOLD(num, den) ((RAND_MAX / den) * num)
#endif
#define TRACK_DENIBBLIZED_SIZE (16 * 256) // #Sectors x Sector-size #define TRACK_DENIBBLIZED_SIZE (16 * 256) // #Sectors x Sector-size
#define TRACKS_STANDARD 35 #define TRACKS_STANDARD 35

View File

@ -37,6 +37,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "DiskImage.h" #include "DiskImage.h"
#include "DiskImageHelper.h" #include "DiskImageHelper.h"
#include "Log.h" #include "Log.h"
#include "Card.h"
#include "Memory.h" #include "Memory.h"
ImageInfo::ImageInfo() ImageInfo::ImageInfo()
@ -1089,7 +1090,7 @@ public:
BYTE n = 0; BYTE n = 0;
for (UINT j = 0; j < 8; j++) for (UINT j = 0; j < 8; j++)
{ {
if (rand() < ((RAND_MAX * 3) / 10)) // ~30% of buffer are 1 bits if (rand() < RAND_THRESHOLD(3, 10)) // ~30% of buffer are 1 bits
n |= 1 << j; n |= 1 << j;
} }
m_pWOZEmptyTrack[i] = n; m_pWOZEmptyTrack[i] = n;

View File

@ -41,6 +41,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "Memory.h" #include "Memory.h"
#include "Mockingboard.h" #include "Mockingboard.h"
#include "MouseInterface.h" #include "MouseInterface.h"
#include "DirectInput.h"
#include "NTSC.h" #include "NTSC.h"
#include "ParallelPrinter.h" #include "ParallelPrinter.h"
#include "Pravets.h" #include "Pravets.h"

View File

@ -43,6 +43,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "Memory.h" #include "Memory.h"
#include "Mockingboard.h" #include "Mockingboard.h"
#include "MouseInterface.h" #include "MouseInterface.h"
#include "Video.h"
#include "NTSC.h" #include "NTSC.h"
#include "NoSlotClock.h" #include "NoSlotClock.h"
#include "ParallelPrinter.h" #include "ParallelPrinter.h"
@ -51,7 +52,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "SerialComms.h" #include "SerialComms.h"
#include "Speaker.h" #include "Speaker.h"
#include "Tape.h" #include "Tape.h"
#include "Video.h"
#include "RGBMonitor.h" #include "RGBMonitor.h"
#include "z80emu.h" #include "z80emu.h"

View File

@ -2403,7 +2403,7 @@ bool MB_LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version)
for(UINT i=0; i<NUM_MB_UNITS; i++) for(UINT i=0; i<NUM_MB_UNITS; i++)
{ {
char szNum[2] = {'0'+char(i),0}; char szNum[2] = {char('0' + i), 0};
std::string unit = std::string(SS_YAML_KEY_MB_UNIT) + std::string(szNum); std::string unit = std::string(SS_YAML_KEY_MB_UNIT) + std::string(szNum);
if (!yamlLoadHelper.GetSubMap(unit)) if (!yamlLoadHelper.GetSubMap(unit))
throw std::string("Card: Expected key: ") + std::string(unit); throw std::string("Card: Expected key: ") + std::string(unit);
@ -2552,7 +2552,7 @@ bool Phasor_LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version
for(UINT i=0; i<NUM_PHASOR_UNITS; i++) for(UINT i=0; i<NUM_PHASOR_UNITS; i++)
{ {
char szNum[2] = {'0'+char(i),0}; char szNum[2] = {char('0' + i), 0};
std::string unit = std::string(SS_YAML_KEY_MB_UNIT) + std::string(szNum); std::string unit = std::string(SS_YAML_KEY_MB_UNIT) + std::string(szNum);
if (!yamlLoadHelper.GetSubMap(unit)) if (!yamlLoadHelper.GetSubMap(unit))
throw std::string("Card: Expected key: ") + std::string(unit); throw std::string("Card: Expected key: ") + std::string(unit);

View File

@ -51,6 +51,7 @@ Etc.
#include "Log.h" #include "Log.h"
#include "Memory.h" #include "Memory.h"
#include "MouseInterface.h" #include "MouseInterface.h"
#include "Video.h"
#include "NTSC.h" // NTSC_GetCyclesUntilVBlank() #include "NTSC.h" // NTSC_GetCyclesUntilVBlank()
#include "YamlHelper.h" #include "YamlHelper.h"
@ -766,228 +767,3 @@ bool CMouseInterface::LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT sl
return true; return true;
} }
//=============================================================================
// DirectInput interface
//=============================================================================
//#define STRICT
#define DIRECTINPUT_VERSION 0x0800
#include "SoundCore.h" // SAFE_RELEASE()
#include <dinput.h>
extern bool g_bDisableDirectInput; // currently in AppleWin.h
namespace DIMouse
{
static LPDIRECTINPUT8 g_pDI = NULL;
static LPDIRECTINPUTDEVICE8 g_pMouse = NULL;
#define SAMPLE_BUFFER_SIZE 16 // arbitrary number of buffer elements
static UINT_PTR g_TimerIDEvent = 0;
//-----------------------------------------------------------------------------
// Name: OnCreateDevice()
// Desc: Sets up the mouse device using the flags from the dialog.
//-----------------------------------------------------------------------------
HRESULT DirectInputInit( HWND hDlg )
{
LogFileOutput("DirectInputInit: g_bDisableDirectInput=%d\n", g_bDisableDirectInput);
if (g_bDisableDirectInput)
return S_OK;
#ifdef NO_DIRECT_X
return E_FAIL;
#else // NO_DIRECT_X
HRESULT hr;
BOOL bExclusive;
BOOL bForeground;
BOOL bImmediate;
DWORD dwCoopFlags;
DirectInputUninit(hDlg);
LogFileOutput("DirectInputInit: DirectInputUninit()\n");
// Determine where the buffer would like to be allocated
bExclusive = FALSE;
bForeground = FALSE; // Otherwise get DIERR_OTHERAPPHASPRIO (== E_ACCESSDENIED) on Acquire()
bImmediate = TRUE;
if( bExclusive )
dwCoopFlags = DISCL_EXCLUSIVE;
else
dwCoopFlags = DISCL_NONEXCLUSIVE;
if( bForeground )
dwCoopFlags |= DISCL_FOREGROUND;
else
dwCoopFlags |= DISCL_BACKGROUND;
// Create a DInput object
hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&g_pDI, NULL );
LogFileOutput("DirectInputInit: DirectInput8Create(), hr=0x%08X\n", hr);
if (FAILED(hr))
return hr;
// Obtain an interface to the system mouse device.
hr = g_pDI->CreateDevice( GUID_SysMouse, &g_pMouse, NULL );
LogFileOutput("DirectInputInit: CreateDevice(), hr=0x%08X\n", hr);
if (FAILED(hr))
return hr;
// Set the data format to "mouse format" - a predefined data format
//
// A data format specifies which controls on a device we
// are interested in, and how they should be reported.
//
// This tells DirectInput that we will be passing a
// DIMOUSESTATE2 structure to IDirectInputDevice::GetDeviceState.
hr = g_pMouse->SetDataFormat( &c_dfDIMouse2 );
LogFileOutput("DirectInputInit: SetDataFormat(), hr=0x%08X\n", hr);
if (FAILED(hr))
return hr;
// Set the cooperativity level to let DirectInput know how
// this device should interact with the system and with other
// DirectInput applications.
hr = g_pMouse->SetCooperativeLevel( hDlg, dwCoopFlags );
LogFileOutput("DirectInputInit: SetCooperativeLevel(), hr=0x%08X\n", hr);
if( hr == DIERR_UNSUPPORTED && !bForeground && bExclusive )
{
DirectInputUninit(hDlg);
LogFileOutput("DirectInputInit: DirectInputUninit()n");
//MessageBox( hDlg, _T("SetCooperativeLevel() returned DIERR_UNSUPPORTED.\n")
// _T("For security reasons, background exclusive mouse\n")
// _T("access is not allowed."),
// _T("Mouse"), MB_OK );
return S_OK;
}
if( FAILED(hr) )
return hr;
if( !bImmediate )
{
// IMPORTANT STEP TO USE BUFFERED DEVICE DATA!
//
// DirectInput uses unbuffered I/O (buffer size = 0) by default.
// If you want to read buffered data, you need to set a nonzero
// buffer size.
//
// Set the buffer size to SAMPLE_BUFFER_SIZE (defined above) elements.
//
// The buffer size is a DWORD property associated with the device.
DIPROPDWORD dipdw;
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = SAMPLE_BUFFER_SIZE; // Arbitary buffer size
hr = g_pMouse->SetProperty( DIPROP_BUFFERSIZE, &dipdw.diph );
LogFileOutput("DirectInputInit: SetProperty(), hr=0x%08X\n", hr);
if (FAILED(hr))
return hr;
}
// Acquire the newly created device
hr = g_pMouse->Acquire();
LogFileOutput("DirectInputInit: Acquire(), hr=0x%08X\n", hr);
if (FAILED(hr))
return hr;
// Setup timer to read mouse position
_ASSERT(g_TimerIDEvent == 0);
g_TimerIDEvent = SetTimer(hDlg, IDEVENT_TIMER_MOUSE, 8, NULL); // 120Hz timer
LogFileOutput("DirectInputInit: SetTimer(), id=0x%08X\n", g_TimerIDEvent);
if (g_TimerIDEvent == 0)
return E_FAIL;
return S_OK;
#endif // NO_DIRECT_X
}
//-----------------------------------------------------------------------------
// Name: FreeDirectInput()
// Desc: Initialize the DirectInput variables.
//-----------------------------------------------------------------------------
void DirectInputUninit( HWND hDlg )
{
LogFileOutput("DirectInputUninit\n");
// Unacquire the device one last time just in case
// the app tried to exit while the device is still acquired.
if( g_pMouse )
{
HRESULT hr = g_pMouse->Unacquire();
LogFileOutput("DirectInputUninit: Unacquire(), hr=0x%08X\n", hr);
}
// Release any DirectInput objects.
SAFE_RELEASE( g_pMouse );
SAFE_RELEASE( g_pDI );
if (g_TimerIDEvent)
{
BOOL bRes = KillTimer(hDlg, g_TimerIDEvent);
LogFileOutput("DirectInputUninit: KillTimer(), res=%d\n", bRes ? 1 : 0);
g_TimerIDEvent = 0;
}
}
//-----------------------------------------------------------------------------
// Name: ReadImmediateData()
// Desc: Read the input device's state when in immediate mode and display it.
//-----------------------------------------------------------------------------
HRESULT ReadImmediateData( long* pX, long* pY )
{
HRESULT hr;
DIMOUSESTATE2 dims2; // DirectInput mouse state structure
if (pX) *pX = 0;
if (pY) *pY = 0;
if( NULL == g_pMouse )
return S_OK;
// Get the input's device state, and put the state in dims
ZeroMemory( &dims2, sizeof(dims2) );
hr = g_pMouse->GetDeviceState( sizeof(DIMOUSESTATE2), &dims2 );
if( FAILED(hr) )
{
// DirectInput may be telling us that the input stream has been
// interrupted. We aren't tracking any state between polls, so
// we don't have any special reset that needs to be done.
// We just re-acquire and try again.
// If input is lost then acquire and keep trying
hr = g_pMouse->Acquire();
while( hr == DIERR_INPUTLOST )
hr = g_pMouse->Acquire();
// Update the dialog text
if( hr == DIERR_OTHERAPPHASPRIO ||
hr == DIERR_NOTACQUIRED )
{
//SetDlgItemText( hDlg, IDC_DATA, TEXT("Unacquired") );
}
// hr may be DIERR_OTHERAPPHASPRIO or other errors. This
// may occur when the app is minimized or in the process of
// switching, so just try again later
return S_OK;
}
if (pX) *pX = dims2.lX;
if (pY) *pY = dims2.lY;
return S_OK;
}
}; // namespace DIMouse

View File

@ -107,10 +107,3 @@ protected:
SyncEvent m_syncEvent; SyncEvent m_syncEvent;
}; };
namespace DIMouse
{
HRESULT DirectInputInit( HWND hDlg );
void DirectInputUninit( HWND hDlg );
HRESULT ReadImmediateData( long* pX=NULL, long* pY=NULL );
};

View File

@ -2179,8 +2179,8 @@ _mono:
} }
//=========================================================================== //===========================================================================
void GenerateVideoTables( void ); static void GenerateVideoTables( void );
void GenerateBaseColors(baseColors_t pBaseNtscColors); static void GenerateBaseColors(baseColors_t pBaseNtscColors);
void NTSC_Destroy(void) void NTSC_Destroy(void)
{ {

View File

@ -5,6 +5,7 @@
#include "Frame.h" #include "Frame.h"
#include "Memory.h" // MemGetMainPtr() MemGetAuxPtr() #include "Memory.h" // MemGetMainPtr() MemGetAuxPtr()
#include "Video.h" #include "Video.h"
#include "Card.h"
#include "RGBMonitor.h" #include "RGBMonitor.h"
#include "YamlHelper.h" #include "YamlHelper.h"

View File

@ -11,6 +11,7 @@
</ProjectConfiguration> </ProjectConfiguration>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\source\SynchronousEventManager.cpp" />
<ClCompile Include="stdafx.cpp" /> <ClCompile Include="stdafx.cpp" />
<ClCompile Include="TestCPU6502.cpp" /> <ClCompile Include="TestCPU6502.cpp" />
</ItemGroup> </ItemGroup>

View File

@ -13,6 +13,9 @@
<ClCompile Include="TestCPU6502.cpp"> <ClCompile Include="TestCPU6502.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\source\SynchronousEventManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="stdafx.h"> <ClInclude Include="stdafx.h">