1
0
mirror of https://github.com/TASVideos/desmume synced 2024-07-08 11:55:50 +00:00

Slot2: Slide Controller fixes

This commit is contained in:
windwakr 2023-10-11 18:31:28 -04:00
parent c3cdf8b412
commit b6cc718d81
2 changed files with 27 additions and 24 deletions

View File

@ -225,9 +225,11 @@ public:
ISlot2Interface* construct_Slot2_SlideController() { return new Slot2_SlideController(); } ISlot2Interface* construct_Slot2_SlideController() { return new Slot2_SlideController(); }
void slideController_updateMotion(s8 x, s8 y) void slideController_updateMotion(s8 x, s8 y)
{
if (x || y)
{ {
scRegs[0x03] = (u8)x; scRegs[0x03] = (u8)x;
scRegs[0x04] = (u8)y; scRegs[0x04] = (u8)y;
if (scRegs[0x03] || scRegs[0x04]) scRegs[0x02] |= 0x80; //Set motion flag in the motion status register
scRegs[0x02] |= 0x80; }
} }

View File

@ -2133,12 +2133,13 @@ int _main()
exit(-1); exit(-1);
} }
RAWINPUTDEVICE rid = {}; //Raw input for the Slide Controller add-on
rid.usUsagePage = 0x01; RAWINPUTDEVICE Rid[1];
rid.usUsage = 0x02; Rid[0].usUsagePage = 0x01;
rid.dwFlags = 0; Rid[0].usUsage = 0x02;
rid.hwndTarget = MainWindow->getHWnd(); Rid[0].dwFlags = 0x00;
RegisterRawInputDevices(&rid, 1, sizeof(rid)); Rid[0].hwndTarget = MainWindow->getHWnd();
RegisterRawInputDevices(Rid, 1, sizeof(Rid[0]));
//disable wacky stylus stuff //disable wacky stylus stuff
//TODO - we are obliged to call GlobalDeleteAtom //TODO - we are obliged to call GlobalDeleteAtom
@ -4529,24 +4530,24 @@ DOKEYDOWN:
{ {
if (SlideController.Enabled) if (SlideController.Enabled)
{ {
UINT dataSize; UINT dwSize = sizeof(RAWINPUT);
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &dataSize, sizeof(RAWINPUTHEADER)); static BYTE lpb[sizeof(RAWINPUT)];
LPBYTE rawdata = new BYTE[dataSize];
if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, rawdata, &dataSize, sizeof(RAWINPUTHEADER)) == dataSize) GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER));
{
RAWINPUT* raw = (RAWINPUT*)rawdata; RAWINPUT* raw = (RAWINPUT*)lpb;
if (raw->header.dwType == RIM_TYPEMOUSE) if (raw->header.dwType == RIM_TYPEMOUSE)
{ {
LONG xMotion = raw->data.mouse.lLastX; int xMotion = raw->data.mouse.lLastX;
LONG yMotion = raw->data.mouse.lLastY; int yMotion = raw->data.mouse.lLastY;
xMotion = max((LONG)-127, min(xMotion, (LONG)127)); xMotion = max(-127, min(xMotion, 127));
yMotion = max((LONG)-127, min(yMotion, (LONG)127)); yMotion = max(-127, min(yMotion, 127));
slideController_updateMotion(xMotion, -yMotion); slideController_updateMotion(xMotion, -yMotion);
} }
}
}
}
return 0; return 0;
}
}
case WM_COMMAND: case WM_COMMAND:
if(HIWORD(wParam) == 0 || HIWORD(wParam) == 1) if(HIWORD(wParam) == 0 || HIWORD(wParam) == 1)