[NTVDM]
[reactos.git] / reactos / subsystems / ntvdm / hardware / ps2.c
index c98d32e..7c1ed6d 100644 (file)
@@ -14,6 +14,8 @@
 #include "io.h"
 #include "ps2.h"
 #include "pic.h"
+#include "mouse.h"
+#include "../bios/bios32/moubios32.h"
 
 /* PRIVATE VARIABLES **********************************************************/
 
@@ -28,69 +30,6 @@ static HANDLE QueueMutex = NULL;
 
 /* PRIVATE FUNCTIONS **********************************************************/
 
-static BOOLEAN KeyboardQueuePush(BYTE ScanCode)
-{
-    BOOLEAN Result = TRUE;
-
-    WaitForSingleObject(QueueMutex, INFINITE);
-
-    /* Check if the keyboard queue is full */
-    if (!KeyboardQueueEmpty && (KeyboardQueueStart == KeyboardQueueEnd))
-    {
-        Result = FALSE;
-        goto Done;
-    }
-
-    /* Insert the value in the queue */
-    KeyboardQueue[KeyboardQueueEnd] = ScanCode;
-    KeyboardQueueEnd++;
-    KeyboardQueueEnd %= KEYBOARD_BUFFER_SIZE;
-
-    /* Since we inserted a value, it's not empty anymore */
-    KeyboardQueueEmpty = FALSE;
-
-Done:
-    ReleaseMutex(QueueMutex);
-    return Result;
-}
-
-static BOOLEAN KeyboardQueuePop(BYTE *ScanCode)
-{
-    BOOLEAN Result = TRUE;
-
-    /* Make sure the keyboard queue is not empty (fast check) */
-    if (KeyboardQueueEmpty) return FALSE;
-
-    WaitForSingleObject(QueueMutex, INFINITE);
-
-    /*
-     * Recheck whether keyboard queue is not empty (it
-     * may have changed after having grabbed the mutex).
-     */
-    if (KeyboardQueueEmpty)
-    {
-        Result = FALSE;
-        goto Done;
-    }
-
-    /* Get the scan code */
-    *ScanCode = KeyboardQueue[KeyboardQueueStart];
-
-    /* Remove the value from the queue */
-    KeyboardQueueStart++;
-    KeyboardQueueStart %= KEYBOARD_BUFFER_SIZE;
-
-    /* Check if the queue is now empty */
-    if (KeyboardQueueStart == KeyboardQueueEnd)
-    {
-        KeyboardQueueEmpty = TRUE;
-    }
-
-Done:
-    ReleaseMutex(QueueMutex);
-    return Result;
-}
-
 static BYTE WINAPI PS2ReadPort(ULONG Port)
 {
     if (Port == PS2_CONTROL_PORT)
@@ -156,14 +95,14 @@ static VOID WINAPI PS2WritePort(ULONG Port, BYTE Data)
             /* Disable mouse */
             case 0xA7:
             {
-                // TODO: Mouse support
+                // TODO: Not implemented
                 break;
             }
 
             /* Enable mouse */
             case 0xA8:
             {
-                // TODO: Mouse support
+                // TODO: Not implemented
                 break;
             }
 
@@ -268,7 +207,7 @@ static VOID WINAPI PS2WritePort(ULONG Port, BYTE Data)
 
                 case 0xD4:
                 {
-                    // TODO: Mouse support
+                    MouseCommand(Data);
                     break;
                 }
             }
@@ -282,6 +221,69 @@ static VOID WINAPI PS2WritePort(ULONG Port, BYTE Data)
 
 /* PUBLIC FUNCTIONS ***********************************************************/
 
+BOOLEAN KeyboardQueuePush(BYTE ScanCode)
+{
+    BOOLEAN Result = TRUE;
+
+    WaitForSingleObject(QueueMutex, INFINITE);
+
+    /* Check if the keyboard queue is full */
+    if (!KeyboardQueueEmpty && (KeyboardQueueStart == KeyboardQueueEnd))
+    {
+        Result = FALSE;
+        goto Done;
+    }
+
+    /* Insert the value in the queue */
+    KeyboardQueue[KeyboardQueueEnd] = ScanCode;
+    KeyboardQueueEnd++;
+    KeyboardQueueEnd %= KEYBOARD_BUFFER_SIZE;
+
+    /* Since we inserted a value, it's not empty anymore */
+    KeyboardQueueEmpty = FALSE;
+
+Done:
+    ReleaseMutex(QueueMutex);
+    return Result;
+}
+
+BOOLEAN KeyboardQueuePop(BYTE *ScanCode)
+{
+    BOOLEAN Result = TRUE;
+
+    /* Make sure the keyboard queue is not empty (fast check) */
+    if (KeyboardQueueEmpty) return FALSE;
+
+    WaitForSingleObject(QueueMutex, INFINITE);
+
+    /*
+     * Recheck whether keyboard queue is not empty (it
+     * may have changed after having grabbed the mutex).
+     */
+    if (KeyboardQueueEmpty)
+    {
+        Result = FALSE;
+        goto Done;
+    }
+
+    /* Get the scan code */
+    *ScanCode = KeyboardQueue[KeyboardQueueStart];
+
+    /* Remove the value from the queue */
+    KeyboardQueueStart++;
+    KeyboardQueueStart %= KEYBOARD_BUFFER_SIZE;
+
+    /* Check if the queue is now empty */
+    if (KeyboardQueueStart == KeyboardQueueEnd)
+    {
+        KeyboardQueueEmpty = TRUE;
+    }
+
+Done:
+    ReleaseMutex(QueueMutex);
+    return Result;
+}
+
 VOID PS2Dispatch(PINPUT_RECORD InputRecord)
 {
     /* Check the event type */
@@ -306,8 +308,11 @@ VOID PS2Dispatch(PINPUT_RECORD InputRecord)
 
         case MOUSE_EVENT:
         {
-            // TODO: NOT IMPLEMENTED
-            UNIMPLEMENTED;
+            /* Notify the BIOS driver */
+            MouseBiosUpdatePosition(&InputRecord->Event.MouseEvent.dwMousePosition);
+
+            // TODO: PS/2, other stuff
+
             break;
         }
 
@@ -325,9 +330,7 @@ VOID GenerateKeyboardInterrupts(VOID)
 
 BOOLEAN PS2Initialize(HANDLE ConsoleInput)
 {
-#if 0
     DWORD ConInMode;
-#endif
 
     /* Create the mutex */
     QueueMutex = CreateMutex(NULL, FALSE, NULL);
@@ -336,23 +339,25 @@ BOOLEAN PS2Initialize(HANDLE ConsoleInput)
     RegisterIoPort(PS2_CONTROL_PORT, PS2ReadPort, PS2WritePort);
     RegisterIoPort(PS2_DATA_PORT   , PS2ReadPort, PS2WritePort);
 
-#if 0
     if (GetConsoleMode(ConsoleInput, &ConInMode))
     {
+#if 0
         if (MousePresent)
         {
+#endif
             /* Support mouse input events if there is a mouse on the system */
             ConInMode |= ENABLE_MOUSE_INPUT;
+#if 0
         }
         else
         {
             /* Do not support mouse input events if there is no mouse on the system */
             ConInMode &= ~ENABLE_MOUSE_INPUT;
         }
+#endif
 
         SetConsoleMode(ConsoleInput, ConInMode);
     }
-#endif
 
     return TRUE;
 }