ReactOS 0.4.16-dev-197-g92996da
mouse.c File Reference
#include "ntvdm.h"
#include <debug.h>
#include "mouse.h"
#include "ps2.h"
#include "clock.h"
#include "video/svga.h"
#include "../console/video.h"
Include dependency graph for mouse.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static VOID MouseResetConfig (VOID)
 
static VOID MouseResetCounters (VOID)
 
static VOID MouseReset (VOID)
 
static VOID MouseGetPacket (PMOUSE_PACKET Packet)
 
static VOID MouseDispatchPacket (PMOUSE_PACKET Packet)
 
static VOID WINAPI MouseCommand (LPVOID Param, BYTE Command)
 
static VOID FASTCALL MouseStreamingCallback (ULONGLONG ElapsedTime)
 
VOID MouseGetDataFast (PCOORD CurrentPosition, PBYTE CurrentButtonState)
 
VOID MouseEventHandler (PMOUSE_EVENT_RECORD MouseEvent)
 
BOOLEAN MouseInit (BYTE PS2Connector)
 

Variables

static const BYTE ScrollMagic [3] = { 200, 100, 80 }
 
static const BYTE ExtraButtonMagic [3] = { 200, 200, 80 }
 
static HANDLE MouseMutex
 
static PHARDWARE_TIMER StreamTimer
 
static MOUSE_PACKET LastPacket
 
static MOUSE_MODE Mode
 
static MOUSE_MODE PreviousMode
 
static COORD Position
 
static BYTE Resolution
 
static BOOLEAN Scaling
 
static BOOLEAN MouseReporting = FALSE
 
static BYTE MouseId
 
static ULONG ButtonState
 
static SHORT HorzCounter
 
static SHORT VertCounter
 
static CHAR ScrollCounter
 
static BOOLEAN EventsOccurred = FALSE
 
static BYTE MouseDataByteWait = 0
 
static BYTE ScrollMagicCounter = 0
 
static BYTE ExtraButtonMagicCounter = 0
 
static UINT MouseCycles = 10
 
static BYTE MousePS2Port = 1
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file mouse.c.

Function Documentation

◆ MouseCommand()

static VOID WINAPI MouseCommand ( LPVOID  Param,
BYTE  Command 
)
static

Definition at line 155 of file mouse.c.

156{
157 /* Check if we were waiting for a data byte */
159 {
161
162 switch (MouseDataByteWait)
163 {
164 /* Set Resolution */
165 case 0xE8:
166 {
168 break;
169 }
170
171 /* Set Sample Rate */
172 case 0xF3:
173 {
174 /* Check for the scroll wheel enabling sequence */
175 if (MouseId == 0)
176 {
178 {
180 if (ScrollMagicCounter == 3) MouseId = 3;
181 }
182 else
183 {
185 }
186 }
187
188 /* Check for the 5-button enabling sequence */
189 if (MouseId == 3)
190 {
192 {
194 if (ExtraButtonMagicCounter == 3) MouseId = 4;
195 }
196 else
197 {
199 }
200 }
201
202 MouseCycles = 1000 / (UINT)Command;
203 break;
204 }
205
206 default:
207 {
208 /* Shouldn't happen */
209 ASSERT(FALSE);
210 }
211 }
212
214 return;
215 }
216
217 /* Check if we're in wrap mode */
218 if (Mode == MOUSE_WRAP_MODE)
219 {
220 /*
221 * In this mode, we just echo whatever byte we get,
222 * except for the 0xEC and 0xFF commands.
223 */
224 if (Command != 0xEC && Command != 0xFF)
225 {
227 return;
228 }
229 }
230
231 switch (Command)
232 {
233 /* Set 1:1 Scaling */
234 case 0xE6:
235 {
236 Scaling = FALSE;
238 break;
239 }
240
241 /* Set 2:1 Scaling */
242 case 0xE7:
243 {
244 Scaling = TRUE;
246 break;
247 }
248
249 /* Set Resolution */
250 case 0xE8:
251 /* Set Sample Rate */
252 case 0xF3:
253 {
256 break;
257 }
258
259 /* Read Status */
260 case 0xE9:
261 {
262 BYTE Status = ButtonState & 7;
263
264 if (Scaling) Status |= 1 << 4;
265 if (MouseReporting) Status |= 1 << 5;
266 if (Mode == MOUSE_REMOTE_MODE) Status |= 1 << 6;
267
272 break;
273 }
274
275 /* Enter Streaming Mode */
276 case 0xEA:
277 {
280
282 break;
283 }
284
285 /* Read Packet */
286 case 0xEB:
287 {
291 break;
292 }
293
294 /* Return from Wrap Mode */
295 case 0xEC:
296 {
297 if (Mode == MOUSE_WRAP_MODE)
298 {
299 /* Restore the previous mode */
303 }
304 else
305 {
307 }
308
309 break;
310 }
311
312 /* Enter Wrap Mode */
313 case 0xEE:
314 {
315 if (Mode != MOUSE_WRAP_MODE)
316 {
317 /* Save the previous mode */
319 }
320
323
325 break;
326 }
327
328 /* Enter Remote Mode */
329 case 0xF0:
330 {
333
335 break;
336 }
337
338 /* Get Mouse ID */
339 case 0xF2:
340 {
343 break;
344 }
345
346 /* Enable Reporting */
347 case 0xF4:
348 {
352 break;
353 }
354
355 /* Disable Reporting */
356 case 0xF5:
357 {
361 break;
362 }
363
364 /* Set Defaults */
365 case 0xF6:
366 {
367 /* Reset the configuration and counters */
371 break;
372 }
373
374 /* Resend */
375 case 0xFE:
376 {
379 break;
380 }
381
382 /* Reset */
383 case 0xFF:
384 {
385 /* Send ACKnowledge */
387
388 MouseReset();
389
390 /* Send the Basic Assurance Test success code and the device ID */
393 break;
394 }
395
396 /* Unknown command */
397 default:
398 {
400 }
401 }
402}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
ButtonState
Definition: button.c:147
Status
Definition: gdiplustypes.h:25
#define MOUSE_ACK
Definition: i8042prt.h:285
#define MOUSE_ERROR
Definition: i8042prt.h:286
#define ASSERT(a)
Definition: mode.c:44
unsigned int UINT
Definition: ndis.h:50
BOOLEAN PS2QueuePush(BYTE PS2Port, BYTE Data)
Definition: ps2.c:486
Definition: shell.h:41
static VOID MouseDispatchPacket(PMOUSE_PACKET Packet)
Definition: mouse.c:147
static const BYTE ExtraButtonMagic[3]
Definition: mouse.c:28
static BYTE ScrollMagicCounter
Definition: mouse.c:45
static BYTE Resolution
Definition: mouse.c:35
static UINT MouseCycles
Definition: mouse.c:47
static VOID MouseResetCounters(VOID)
Definition: mouse.c:64
static MOUSE_PACKET LastPacket
Definition: mouse.c:32
static VOID MouseResetConfig(VOID)
Definition: mouse.c:55
static BYTE MouseDataByteWait
Definition: mouse.c:44
static BOOLEAN Scaling
Definition: mouse.c:36
static BYTE MousePS2Port
Definition: mouse.c:49
static VOID MouseGetPacket(PMOUSE_PACKET Packet)
Definition: mouse.c:82
static BYTE MouseId
Definition: mouse.c:38
static BOOLEAN MouseReporting
Definition: mouse.c:37
static MOUSE_MODE Mode
Definition: mouse.c:33
static MOUSE_MODE PreviousMode
Definition: mouse.c:33
static const BYTE ScrollMagic[3]
Definition: mouse.c:27
static BYTE ExtraButtonMagicCounter
Definition: mouse.c:45
static VOID MouseReset(VOID)
Definition: mouse.c:70
#define MOUSE_BAT_SUCCESS
Definition: mouse.h:32
@ MOUSE_REMOTE_MODE
Definition: mouse.h:51
@ MOUSE_WRAP_MODE
Definition: mouse.h:52
@ MOUSE_STREAMING_MODE
Definition: mouse.h:50
unsigned char BYTE
Definition: xxhash.c:193

Referenced by MouseInit().

◆ MouseDispatchPacket()

static VOID MouseDispatchPacket ( PMOUSE_PACKET  Packet)
static

Definition at line 147 of file mouse.c.

148{
150 PS2QueuePush(MousePS2Port, Packet->HorzCounter);
151 PS2QueuePush(MousePS2Port, Packet->VertCounter);
152 if (MouseId >= 3) PS2QueuePush(MousePS2Port, Packet->Extra);
153}
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549

Referenced by MouseCommand(), and MouseStreamingCallback().

◆ MouseEventHandler()

VOID MouseEventHandler ( PMOUSE_EVENT_RECORD  MouseEvent)

Definition at line 427 of file mouse.c.

428{
429 COORD NewPosition = MouseEvent->dwMousePosition;
431
433 {
434 /* Text mode */
435 NewPosition.X *= 8;
436 NewPosition.Y *= 8;
437 }
438
439 /* Adjust for double vision */
440 if (DoubleWidth) NewPosition.X /= 2;
441 if (DoubleHeight) NewPosition.Y /= 2;
442
444
445 /* Update the counters */
446 HorzCounter += (NewPosition.X - Position.X) << DoubleWidth;
447 VertCounter += (NewPosition.Y - Position.Y) << DoubleHeight;
448
449 /* Update the position */
450 Position = NewPosition;
451
452 /* Update the button state */
453 ButtonState = MouseEvent->dwButtonState;
454
455 if (MouseEvent->dwEventFlags & MOUSE_WHEELED)
456 {
457 ScrollCounter += (SHORT)HIWORD(MouseEvent->dwButtonState);
458 }
459
462}
unsigned char BOOLEAN
#define INFINITE
Definition: serial.h:102
short SHORT
Definition: pedump.c:59
Definition: bl.h:1338
ULONG Y
Definition: bl.h:1340
ULONG X
Definition: bl.h:1339
DWORD dwEventFlags
Definition: wincon.h:257
DWORD dwButtonState
Definition: wincon.h:255
COORD dwMousePosition
Definition: wincon.h:254
BOOLEAN VgaGetDoubleVisionState(PBOOLEAN Horizontal, PBOOLEAN Vertical)
Definition: video.c:488
static BOOLEAN DoubleHeight
Definition: video.c:59
static BOOLEAN DoubleWidth
Definition: video.c:58
static BOOLEAN EventsOccurred
Definition: mouse.c:43
static CHAR ScrollCounter
Definition: mouse.c:42
static SHORT VertCounter
Definition: mouse.c:41
static HANDLE MouseMutex
Definition: mouse.c:30
static COORD Position
Definition: mouse.c:34
static SHORT HorzCounter
Definition: mouse.c:40
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseMutex(IN HANDLE hMutex)
Definition: synch.c:618
#define HIWORD(l)
Definition: typedefs.h:247
#define MOUSE_WHEELED
Definition: wincon.h:170

Referenced by ConsoleEventThread().

◆ MouseGetDataFast()

VOID MouseGetDataFast ( PCOORD  CurrentPosition,
PBYTE  CurrentButtonState 
)

Definition at line 419 of file mouse.c.

420{
423 *CurrentButtonState = LOBYTE(ButtonState);
425}
#define LOBYTE(W)
Definition: jmemdos.c:487
ULONG CurrentPosition
Definition: patchapi.h:57

Referenced by DosMouseIrq().

◆ MouseGetPacket()

static VOID MouseGetPacket ( PMOUSE_PACKET  Packet)
static

Definition at line 82 of file mouse.c.

83{
84 /* Clear the packet */
85 RtlZeroMemory(Packet, sizeof(*Packet));
86
87 /* Acquire the mutex */
89
90 Packet->Flags |= MOUSE_ALWAYS_SET;
91
92 /* Set the sign flags */
93 if (HorzCounter < 0)
94 {
95 Packet->Flags |= MOUSE_X_SIGN;
97 }
98
99 if (VertCounter < 0)
100 {
101 Packet->Flags |= MOUSE_Y_SIGN;
103 }
104
105 /* Check for horizontal overflows */
107 {
109 Packet->Flags |= MOUSE_X_OVERFLOW;
110 }
111
112 /* Check for vertical overflows */
114 {
116 Packet->Flags |= MOUSE_Y_OVERFLOW;
117 }
118
119 /* Set the button flags */
123
124 if (MouseId == 4)
125 {
128 }
129
130 if (MouseId >= 3)
131 {
132 /* Set the scroll counter */
133 Packet->Extra |= ((UCHAR)ScrollCounter & 0x0F);
134 }
135
136 /* Store the counters in the packet */
137 Packet->HorzCounter = LOBYTE(HorzCounter);
138 Packet->VertCounter = LOBYTE(VertCounter);
139
140 /* Reset the counters */
142
143 /* Release the mutex */
145}
#define MOUSE_Y_OVERFLOW
Definition: mouse.h:25
#define MOUSE_5TH_BUTTON
Definition: mouse.h:29
#define MOUSE_X_OVERFLOW
Definition: mouse.h:24
#define MOUSE_ALWAYS_SET
Definition: mouse.h:21
#define MOUSE_RIGHT_BUTTON
Definition: mouse.h:19
#define MOUSE_X_SIGN
Definition: mouse.h:22
#define MOUSE_MAX
Definition: mouse.h:15
#define MOUSE_Y_SIGN
Definition: mouse.h:23
#define MOUSE_4TH_BUTTON
Definition: mouse.h:28
#define MOUSE_MIDDLE_BUTTON
Definition: mouse.h:20
#define MOUSE_LEFT_BUTTON
Definition: mouse.h:18
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define FROM_LEFT_4TH_BUTTON_PRESSED
Definition: wincon.h:163
#define FROM_LEFT_2ND_BUTTON_PRESSED
Definition: wincon.h:161
#define FROM_LEFT_3RD_BUTTON_PRESSED
Definition: wincon.h:162
#define FROM_LEFT_1ST_BUTTON_PRESSED
Definition: wincon.h:159
#define RIGHTMOST_BUTTON_PRESSED
Definition: wincon.h:160
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by MouseCommand(), and MouseStreamingCallback().

◆ MouseInit()

BOOLEAN MouseInit ( BYTE  PS2Connector)

Definition at line 464 of file mouse.c.

465{
466 /* Finish to plug the mouse to the specified PS/2 port */
467 MousePS2Port = PS2Connector;
469
471 if (MouseMutex == NULL) return FALSE;
472
474 HZ_TO_NS(100),
476
477 MouseReset();
478 return TRUE;
479}
#define HARDWARE_TIMER_ENABLED
Definition: clock.h:15
#define HZ_TO_NS(Freq)
Definition: clock.h:20
#define NULL
Definition: types.h:112
VOID PS2SetDeviceCmdProc(BYTE PS2Port, LPVOID Param, PS2_DEVICE_CMDPROC DeviceCommand)
Definition: ps2.c:478
PHARDWARE_TIMER CreateHardwareTimer(ULONG Flags, ULONGLONG Delay, PHARDWARE_TIMER_PROC Callback)
Definition: clock.c:144
static VOID FASTCALL MouseStreamingCallback(ULONGLONG ElapsedTime)
Definition: mouse.c:404
static VOID WINAPI MouseCommand(LPVOID Param, BYTE Command)
Definition: mouse.c:155
static PHARDWARE_TIMER StreamTimer
Definition: mouse.c:31
#define CreateMutex
Definition: winbase.h:3780

Referenced by EmulatorInitialize().

◆ MouseReset()

static VOID MouseReset ( VOID  )
static

Definition at line 70 of file mouse.c.

71{
72 /* Reset everything */
75
76 /* Enter streaming mode and the reset the mouse ID */
78 MouseId = 0;
80}

Referenced by MouseCommand(), and MouseInit().

◆ MouseResetConfig()

static VOID MouseResetConfig ( VOID  )
static

Definition at line 55 of file mouse.c.

56{
57 /* Reset the configuration to defaults */
58 MouseCycles = 10;
59 Resolution = 4;
60 Scaling = FALSE;
62}

Referenced by MouseCommand(), and MouseReset().

◆ MouseResetCounters()

static VOID MouseResetCounters ( VOID  )
static

Definition at line 64 of file mouse.c.

65{
66 /* Reset all flags and counters */
68}

Referenced by MouseCommand(), MouseGetPacket(), and MouseReset().

◆ MouseStreamingCallback()

static VOID FASTCALL MouseStreamingCallback ( ULONGLONG  ElapsedTime)
static

Definition at line 404 of file mouse.c.

405{
406 UNREFERENCED_PARAMETER(ElapsedTime);
407
408 /* Check if we're not in streaming mode, not reporting, or there's nothing to report */
410
413
415}
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317

Referenced by MouseInit().

Variable Documentation

◆ ButtonState

Definition at line 39 of file mouse.c.

◆ EventsOccurred

BOOLEAN EventsOccurred = FALSE
static

Definition at line 43 of file mouse.c.

Referenced by MouseEventHandler(), and MouseStreamingCallback().

◆ ExtraButtonMagic

const BYTE ExtraButtonMagic[3] = { 200, 200, 80 }
static

Definition at line 28 of file mouse.c.

Referenced by MouseCommand().

◆ ExtraButtonMagicCounter

BYTE ExtraButtonMagicCounter = 0
static

Definition at line 45 of file mouse.c.

Referenced by MouseCommand(), and MouseReset().

◆ HorzCounter

SHORT HorzCounter
static

Definition at line 40 of file mouse.c.

Referenced by MouseEventHandler(), MouseGetPacket(), and MouseResetCounters().

◆ LastPacket

MOUSE_PACKET LastPacket
static

Definition at line 32 of file mouse.c.

Referenced by MouseCommand(), and MouseStreamingCallback().

◆ Mode

MOUSE_MODE Mode
static

Definition at line 33 of file mouse.c.

Referenced by MouseCommand(), MouseReset(), and MouseStreamingCallback().

◆ MouseCycles

UINT MouseCycles = 10
static

Definition at line 47 of file mouse.c.

Referenced by MouseCommand(), and MouseResetConfig().

◆ MouseDataByteWait

BYTE MouseDataByteWait = 0
static

Definition at line 44 of file mouse.c.

Referenced by MouseCommand().

◆ MouseId

BYTE MouseId
static

Definition at line 38 of file mouse.c.

Referenced by MouseCommand(), MouseDispatchPacket(), MouseGetPacket(), and MouseReset().

◆ MouseMutex

HANDLE MouseMutex
static

Definition at line 30 of file mouse.c.

Referenced by MouseEventHandler(), MouseGetDataFast(), MouseGetPacket(), and MouseInit().

◆ MousePS2Port

BYTE MousePS2Port = 1
static

Definition at line 49 of file mouse.c.

Referenced by MouseCommand(), MouseDispatchPacket(), and MouseInit().

◆ MouseReporting

BOOLEAN MouseReporting = FALSE
static

Definition at line 37 of file mouse.c.

Referenced by MouseCommand(), MouseResetConfig(), and MouseStreamingCallback().

◆ Position

COORD Position
static

Definition at line 34 of file mouse.c.

Referenced by AcpiDsGetFieldNames(), AcpiUtHexToAsciiChar(), AcpiUtValidNameChar(), AddEntryToList(), ArcSeek(), BtrFsSeek(), CTrayWindow::CalculateValidSize(), CallMouseUserHandlers(), ConDrvSetConsoleCursorPosition(), d3dx9_set_light_parameter(), DECLARE_INTERFACE_(), disk_read(), DiskSeek(), DoNotifyPositionEvents(), DosMouseIrq(), DosMouseService(), Ext2Mount(), Ext2ReadSuperBlock(), Ext2ReadVolumeSectors(), Ext2Seek(), FatMount(), FatReadVolumeSectors(), FatSeek(), FinishDlgProc(), FlatBuf_Arg_CopyMemory(), FlatBuf_Arg_Reserve(), FlatBuf_Arg_ReserveAlignPointer(), FlatBuf_Arg_WriteString(), FromMouseCoordinates(), FsRtlIsDbcsInExpression(), FsRtlIsNameInExpressionPrivate(), CPortPinWaveCyclic::GeneratePositionEvents(), CIconWatcher::GetListEntry(), CTrayWindow::GetTrayRectFromScreenRect(), HistoryRecallHistory(), IDirectSoundCaptureBufferImpl_GetCurrentPosition(), IncrementProgressBar(), InsertTabCtrlItem(), IopReadBootRecord(), IsoBufferDirectory(), IsoLookupFile(), IsoMount(), IsoRead(), IsoSeek(), iterator_visibleitems(), KsGetMediaType(), LineInputRecallHistory(), LISTVIEW_FindItemW(), LISTVIEW_GetItemBox(), LISTVIEW_GetItemRect(), LISTVIEW_HitTest(), LISTVIEW_InvalidateSubItem(), LISTVIEW_IsItemVisible(), LISTVIEW_RefreshList(), LISTVIEW_RefreshOwnerDraw(), LISTVIEW_RefreshReport(), CTrayWindow::MakeTrayRectWithSize(), MiniportSend(), MixerThreadRoutine(), MMixerGetWavePosition(), MouseEventHandler(), MouseGetDataFast(), NtfsDiskRead(), NtfsMount(), NtfsSeek(), PeLdrLoadImage(), PrimaryDirectSoundBuffer_GetPosition(), PxeSeek(), RamDiskLoadVirtualFile(), RamDiskSeek(), read_bitmap_patterns(), read_metadata_patterns(), RegLoadHiveLog(), RestartDlgProc(), RosSymIoSeekFile(), RosSymZwSeekFile(), RtlComputePrivatizedDllName_U(), RtlFindCharInUnicodeString(), RtlFindClearBitsAndSet(), RtlFindLeastSignificantBit(), RtlFindMostSignificantBit(), RtlFindSetBitsAndClear(), RtlGetLengthWithoutLastFullDosOrNtPathElement(), TestFindCharInUnicodeString(), ToMouseCoordinates(), UefiDiskSeek(), CPortPinWaveCyclic::UpdateCommonBuffer(), CPortPinWaveCyclic::UpdateCommonBufferOverlap(), UpdateDialogLineSliderControl(), VgaConsoleUpdateTextCursor(), VTUTF8ChannelOFlush(), WdmAudGetPosition(), WdmAudGetWavePositionByMMixer(), and CConsole::WriteString().

◆ PreviousMode

MOUSE_MODE PreviousMode
static

Definition at line 33 of file mouse.c.

Referenced by MouseCommand().

◆ Resolution

◆ Scaling

BOOLEAN Scaling
static

Definition at line 36 of file mouse.c.

Referenced by MouseCommand(), and MouseResetConfig().

◆ ScrollCounter

CHAR ScrollCounter
static

Definition at line 42 of file mouse.c.

Referenced by MouseEventHandler(), MouseGetPacket(), and MouseResetCounters().

◆ ScrollMagic

const BYTE ScrollMagic[3] = { 200, 100, 80 }
static

Definition at line 27 of file mouse.c.

Referenced by MouseCommand().

◆ ScrollMagicCounter

BYTE ScrollMagicCounter = 0
static

Definition at line 45 of file mouse.c.

Referenced by MouseCommand(), and MouseReset().

◆ StreamTimer

PHARDWARE_TIMER StreamTimer
static

Definition at line 31 of file mouse.c.

Referenced by MouseInit().

◆ VertCounter

SHORT VertCounter
static

Definition at line 41 of file mouse.c.

Referenced by MouseEventHandler(), MouseGetPacket(), and MouseResetCounters().