From 2dc91ac6c05bea408dd8fe2e179676c3319924eb Mon Sep 17 00:00:00 2001 From: Aleksandar Andrejevic Date: Fri, 17 Apr 2015 18:36:45 +0000 Subject: [PATCH] [NTVDM] - The auxiliary PS/2 port IRQ is disabled by default. - In the DOS mouse driver's IRQ handler, just reading the entire packet is faster than waiting for one IRQ per byte. (real drivers can do that too, using polling, which is slower on real hardware but faster in NTVDM). - Increase the speed of the PS/2 IRQ scheduler so that mouse packets don't fill up the queue completely. And consequently, increase the number of CPU steps per cycle to avoid "stuck key" bugs. svn path=/trunk/; revision=67231 --- .../mvdm/ntvdm/bios/bios32/moubios32.c | 18 ++++++ reactos/subsystems/mvdm/ntvdm/clock.c | 2 +- reactos/subsystems/mvdm/ntvdm/dos/mouse32.c | 62 +++++-------------- .../subsystems/mvdm/ntvdm/hardware/mouse.c | 1 + reactos/subsystems/mvdm/ntvdm/hardware/ps2.c | 4 +- 5 files changed, 36 insertions(+), 51 deletions(-) diff --git a/reactos/subsystems/mvdm/ntvdm/bios/bios32/moubios32.c b/reactos/subsystems/mvdm/ntvdm/bios/bios32/moubios32.c index f116762252a..a77fa4d8334 100644 --- a/reactos/subsystems/mvdm/ntvdm/bios/bios32/moubios32.c +++ b/reactos/subsystems/mvdm/ntvdm/bios/bios32/moubios32.c @@ -110,6 +110,24 @@ VOID BiosMousePs2Interface(LPWORD Stack) BOOLEAN MouseBios32Initialize(VOID) { + BYTE ControllerConfig; + + /* Clear the mouse queue */ + while (PS2PortQueueRead(1)) continue; + + /* Enable packet reporting */ + IOWriteB(PS2_CONTROL_PORT, 0xD4); + IOWriteB(PS2_DATA_PORT, 0xF4); + + /* Read the mouse ACK reply */ + PS2PortQueueRead(1); + + /* Enable IRQ12 */ + IOWriteB(PS2_CONTROL_PORT, 0x20); + ControllerConfig = IOReadB(PS2_DATA_PORT); + IOWriteB(PS2_CONTROL_PORT, 0x60); + IOWriteB(PS2_DATA_PORT, ControllerConfig | 0x02); + /* Set up the HW vector interrupts */ EnableHwIRQ(12, BiosMouseIrq); diff --git a/reactos/subsystems/mvdm/ntvdm/clock.c b/reactos/subsystems/mvdm/ntvdm/clock.c index 7909321181f..bebb7cd3185 100644 --- a/reactos/subsystems/mvdm/ntvdm/clock.c +++ b/reactos/subsystems/mvdm/ntvdm/clock.c @@ -39,7 +39,7 @@ // #define WORKING_TIMER /* Processor speed */ -#define STEPS_PER_CYCLE 256 +#define STEPS_PER_CYCLE 1024 /* VARIABLES ******************************************************************/ diff --git a/reactos/subsystems/mvdm/ntvdm/dos/mouse32.c b/reactos/subsystems/mvdm/ntvdm/dos/mouse32.c index a6a6ae22a06..4a3c10afc73 100644 --- a/reactos/subsystems/mvdm/ntvdm/dos/mouse32.c +++ b/reactos/subsystems/mvdm/ntvdm/dos/mouse32.c @@ -30,8 +30,6 @@ #define MICKEYS_PER_CELL_HORIZ 8 #define MICKEYS_PER_CELL_VERT 16 -static MOUSE_PACKET Packet; -static INT ByteCounter = 0; static BOOLEAN DriverEnabled = FALSE; static MOUSE_DRIVER_STATE DriverState; static DWORD OldIrqHandler; @@ -289,50 +287,25 @@ static inline VOID DosUpdateButtons(BYTE ButtonState) static VOID WINAPI DosMouseIrq(LPWORD Stack) { + BYTE Flags; + SHORT DeltaX, DeltaY; COORD Position; BYTE ButtonState; - switch (ByteCounter) - { - case 0: - { - Packet.Flags = IOReadB(PS2_DATA_PORT); - break; - } + /* Read the whole packet at once */ + Flags = IOReadB(PS2_DATA_PORT); + PS2PortQueueRead(1); + DeltaX = IOReadB(PS2_DATA_PORT); + PS2PortQueueRead(1); + DeltaY = IOReadB(PS2_DATA_PORT); - case 1: - { - Packet.HorzCounter = IOReadB(PS2_DATA_PORT); - break; - } + /* Adjust the sign */ + if (Flags & MOUSE_X_SIGN) DeltaX = -DeltaX; + if (Flags & MOUSE_Y_SIGN) DeltaY = -DeltaY; - case 2: - { - Packet.VertCounter = IOReadB(PS2_DATA_PORT); - break; - } - - default: - { - /* Shouldn't happen */ - ASSERT(FALSE); - } - } - - if (++ByteCounter == 3) - { - SHORT DeltaX = Packet.HorzCounter; - SHORT DeltaY = Packet.VertCounter; - - /* Adjust the sign */ - if (Packet.Flags & MOUSE_X_SIGN) DeltaX = -DeltaX; - if (Packet.Flags & MOUSE_Y_SIGN) DeltaY = -DeltaY; - - DriverState.HorizCount += DeltaX; - DriverState.VertCount += DeltaY; - - ByteCounter = 0; - } + /* Update the counters */ + DriverState.HorizCount += DeltaX; + DriverState.VertCount += DeltaY; /* * Get the absolute position directly from the mouse, this is the only @@ -834,13 +807,6 @@ VOID DosMouseEnable(VOID) /* Set the IRQ handler */ RegisterDosInt32(MOUSE_IRQ_INT, DosMouseIrq); - - /* Enable packet reporting */ - IOWriteB(PS2_CONTROL_PORT, 0xD4); - IOWriteB(PS2_DATA_PORT, 0xF4); - - /* Read the mouse ACK reply */ - PS2PortQueueRead(1); } } diff --git a/reactos/subsystems/mvdm/ntvdm/hardware/mouse.c b/reactos/subsystems/mvdm/ntvdm/hardware/mouse.c index 1cdae0ab763..96ee4a27870 100644 --- a/reactos/subsystems/mvdm/ntvdm/hardware/mouse.c +++ b/reactos/subsystems/mvdm/ntvdm/hardware/mouse.c @@ -208,6 +208,7 @@ static VOID WINAPI MouseCommand(LPVOID Param, BYTE Command) } DataByteWait = 0; + return; } /* Check if we're in wrap mode */ diff --git a/reactos/subsystems/mvdm/ntvdm/hardware/ps2.c b/reactos/subsystems/mvdm/ntvdm/hardware/ps2.c index 055e21c27bd..c7f69f2fc61 100644 --- a/reactos/subsystems/mvdm/ntvdm/hardware/ps2.c +++ b/reactos/subsystems/mvdm/ntvdm/hardware/ps2.c @@ -42,7 +42,7 @@ typedef struct _PS2_PORT #define PS2_PORTS 2 static PS2_PORT Ports[PS2_PORTS]; -#define PS2_DEFAULT_CONFIG 0x47 +#define PS2_DEFAULT_CONFIG 0x45 static BYTE ControllerConfig = PS2_DEFAULT_CONFIG; static BYTE ControllerCommand = 0x00; @@ -405,7 +405,7 @@ BOOLEAN PS2Initialize(VOID) RegisterIoPort(PS2_CONTROL_PORT, PS2ReadPort, PS2WritePort); RegisterIoPort(PS2_DATA_PORT , PS2ReadPort, PS2WritePort); - IrqTimer = CreateHardwareTimer(HARDWARE_TIMER_ONESHOT, 20, GeneratePS2Irq); + IrqTimer = CreateHardwareTimer(HARDWARE_TIMER_ONESHOT, 10, GeneratePS2Irq); return TRUE; }