#include "io.h"
#include "ps2.h"
#include "pic.h"
+#include "mouse.h"
+#include "../bios/bios32/moubios32.h"
/* PRIVATE VARIABLES **********************************************************/
/* 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)
/* Disable mouse */
case 0xA7:
{
- // TODO: Mouse support
+ // TODO: Not implemented
break;
}
/* Enable mouse */
case 0xA8:
{
- // TODO: Mouse support
+ // TODO: Not implemented
break;
}
case 0xD4:
{
- // TODO: Mouse support
+ MouseCommand(Data);
break;
}
}
/* 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 */
case MOUSE_EVENT:
{
- // TODO: NOT IMPLEMENTED
- UNIMPLEMENTED;
+ /* Notify the BIOS driver */
+ MouseBiosUpdatePosition(&InputRecord->Event.MouseEvent.dwMousePosition);
+
+ // TODO: PS/2, other stuff
+
break;
}
BOOLEAN PS2Initialize(HANDLE ConsoleInput)
{
-#if 0
DWORD ConInMode;
-#endif
/* Create the mutex */
QueueMutex = CreateMutex(NULL, FALSE, NULL);
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;
}