📄 ps2mouse.cpp
字号:
/*
Copyright(c) 1998,1999 SIC/Hitachi,Ltd.
Copyright(c) 1998,1999 3RD Rail Engineering.
Module Name:
ps2mouse.cpp
Revision History:
26th April 1999 Released
16th June 1999 Revised
*/
#include <windows.h>
#include <ceddk.h>
#include <nkintr.h>
#include <pkfuncs.h>
//#include <oalintr.h>
#include "ps2p465.hpp"
#include "ps2mouse.hpp"
#include "ps2keybd.hpp"
#include "dbgzones.hpp"
Ps2M465 *v_pp2m;
extern DWORD dwSysIntrMouse;
BOOL
Ps2M465::
Initialize(
Ps2P465 *pp2p
)
{
m_pp2p = pp2p;
m_hevInterrupt = NULL;
m_ui8ButtonState = 0;
return TRUE;
}
BOOL
Ps2M465::
IsrThreadProc(
void
)
{
BOOL bInPacket = FALSE;
const int cmsInPacketTimeout = 50; // was 50 milliseconds
int cmsWaitTimeout;
int cBytes = 0;
UINT8 ui8Data;
UINT8 buf[3];
long x,y;
UINT8 ui8Buttons;
UINT8 ui8XorButtons;
unsigned int evfMouse;
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
m_hevInterrupt = CreateEvent(NULL, FALSE, FALSE, NULL);
if ( m_hevInterrupt == NULL)
{
goto leave;
}
if ( !InterruptInitialize(dwSysIntrMouse, m_hevInterrupt, NULL, 0) )
{
goto leave;
}
v_pp2m -> m_pp2p -> MouseInterruptEnable();
for ( ; ; )
{
wait_for_interrupt:
if ( bInPacket )
{
cmsWaitTimeout = cmsInPacketTimeout;
}
else
{
cmsWaitTimeout = INFINITE;
}
if ( WaitForSingleObject(m_hevInterrupt, cmsWaitTimeout) == WAIT_TIMEOUT )
{
DEBUGMSG(ZONE_MOUSEDATA, (TEXT("ps2mouse.cpp: Packet timeout cBytes= %d\r\n"), cBytes));
cBytes = 0;
bInPacket = FALSE;
goto wait_for_interrupt;
}
if ( v_pp2m -> m_pp2p -> MouseDataRead(&ui8Data) )
{
if ( cBytes < 3 )
{
#ifdef DEBUG
if (cBytes) {
if (cBytes != 2) {
DEBUGMSG(ZONE_MOUSEDATA, (TEXT("%02X "), ui8Data));
}
else
{
DEBUGMSG(ZONE_MOUSEDATA, (TEXT("%02X\r\n"), ui8Data));
}
}
else {
DEBUGMSG(ZONE_MOUSEDATA, (TEXT("ps2mouse.cpp:%02X "), ui8Data));
}
#endif
// Filter bad points: in case bytes are lost.
if ( cBytes == 0 )
{
// First byte never has bits 6,7 set,
// but always has bit 3 set.
if ((ui8Data & 0xC8) != 0x08)
goto ByteRefused;
}
buf[cBytes++] = ui8Data;
bInPacket = TRUE;
}
if ( cBytes == 3 )
{
evfMouse = 0;
ui8XorButtons = (buf[0] ^ m_ui8ButtonState) & 0x03;
if ( ui8XorButtons )
{
ui8Buttons = buf[0];
if ( ui8XorButtons & 0x01 )
{
if ( ui8Buttons & 0x01 )
{
evfMouse |= MOUSEEVENTF_LEFTDOWN;
}
else
{
evfMouse |= MOUSEEVENTF_LEFTUP;
}
}
if ( ui8XorButtons & 0x02 )
{
if ( ui8Buttons & 0x02 )
{
evfMouse |= MOUSEEVENTF_RIGHTDOWN;
}
else
{
evfMouse |= MOUSEEVENTF_RIGHTUP;
}
}
if ( ui8XorButtons & 0x04 )
{
if ( ui8Buttons & 0x04 )
{
evfMouse |= MOUSEEVENTF_MIDDLEDOWN;
}
else
{
evfMouse |= MOUSEEVENTF_MIDDLEUP;
}
}
m_ui8ButtonState = buf[0];
}
x = buf[1];
y = buf[2];
if (buf[0] & 0x10)
{
x |= 0xFFFFFF00;
}
else
{
x &= 0x000000FF;
}
if (buf[0] & 0x20)
{
y |= 0xFFFFFF00;
}
else
{
y &= 0x000000FF;
}
y = -y;
if ( y || x )
{
evfMouse |= MOUSEEVENTF_MOVE;
}
/* if ( evfMouse & MOUSEEVENTF_LEFTDOWN )
DEBUGMSG(1, (TEXT("MOUSE:left button down.\r\n")));
else if ( evfMouse & MOUSEEVENTF_LEFTUP )
DEBUGMSG(1, (TEXT("MOUSE:left button up.\r\n")));
else if ( evfMouse & MOUSEEVENTF_RIGHTDOWN )
DEBUGMSG(1, (TEXT("MOUSE:right button down.\r\n")));
else if ( evfMouse & MOUSEEVENTF_RIGHTUP )
DEBUGMSG(1, (TEXT("MOUSE:right button up.\r\n")));
else if ( evfMouse & MOUSEEVENTF_MIDDLEDOWN )
DEBUGMSG(1, (TEXT("MOUSE:middle button down.\r\n")));
else if ( evfMouse & MOUSEEVENTF_MIDDLEUP )
DEBUGMSG(1, (TEXT("MOUSE:middle button up.\r\n")));
else if ( evfMouse & MOUSEEVENTF_MOVE )
DEBUGMSG(1, (TEXT("MOUSE:moving.\r\n")));
DEBUGMSG(1, (TEXT( "x = %d, y = %d\r\n" ), x, y ) );
*/
mouse_event(evfMouse, x, y, 0, NULL);
cBytes = 0;
bInPacket = FALSE;
}
}
else
{
ERRORMSG(1,(TEXT("Error reading mouse data\r\n")));
}
ByteRefused :
v_pp2m -> m_pp2p -> MouseInterruptEnable();
InterruptDone(dwSysIntrMouse);
}
leave:
return TRUE;
}
DWORD
Ps2M465IsrThread(
Ps2M465 *pp2m
)
{
pp2m -> IsrThreadProc();
return 0;
}
BOOL
Ps2M465::
IsrThreadStart(
void
)
{
HANDLE hthrd;
hthrd = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Ps2M465IsrThread, this, 0, NULL);
// Since we don't need the handle, close it now.
CloseHandle(hthrd);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -