static BOOLEAN KeyboardQueueEmpty = TRUE;
static UINT KeyboardQueueStart = 0;
static UINT KeyboardQueueEnd = 0;
-static BYTE KeyboardResponse = 0;
+static BYTE KeyboardData = 0, KeyboardResponse = 0;
static BOOLEAN KeyboardReadResponse = FALSE, KeyboardWriteResponse = FALSE;
static BYTE KeyboardConfig = PS2_DEFAULT_CONFIG;
BYTE KeyboardReadData()
{
- BYTE Value = 0;
-
/* If there was a response byte from the controller, return it */
if (KeyboardReadResponse)
{
KeyboardReadResponse = FALSE;
- return KeyboardResponse;
+ KeyboardData = KeyboardResponse;
+ }
+ else
+ {
+ /* Otherwise, read the data from the queue */
+ KeyboardQueuePop(&KeyboardData);
}
-
- /* Otherwise, read the data from the queue */
- KeyboardQueuePop(&Value);
- return Value;
+ return KeyboardData;
}
VOID KeyboardWriteData(BYTE Data)
// TODO: Implement PS/2 device commands
}
-VOID CheckForInputEvents()
+DWORD WINAPI InputThreadProc(LPVOID Parameter)
{
- PINPUT_RECORD Buffer;
+ INT i;
HANDLE ConsoleInput = GetStdHandle(STD_INPUT_HANDLE);
- DWORD i, j, Count, TotalEvents;
- BYTE ScanCode;
+ INPUT_RECORD InputRecord;
+ DWORD Count;
- /* Get the number of input events */
- if (!GetNumberOfConsoleInputEvents(ConsoleInput, &Count)) return;
- if (Count == 0) return;
+ while (VdmRunning)
+ {
+ /* Wait for an input record */
+ if (!ReadConsoleInput(ConsoleInput, &InputRecord, 1, &Count))
+ {
+ DPRINT1("Error reading console input\n");
+ return GetLastError();
+
+ }
- /* Allocate the buffer */
- Buffer = (PINPUT_RECORD)HeapAlloc(GetProcessHeap(), 0, Count * sizeof(INPUT_RECORD));
- if (Buffer == NULL) return;
+ ASSERT(Count != 0);
- /* Peek the input events */
- if (!ReadConsoleInput(ConsoleInput, Buffer, Count, &TotalEvents)) goto Cleanup;
+ /* Check the event type */
+ switch (InputRecord.EventType)
+ {
+ case KEY_EVENT:
+ {
+ BYTE ScanCode = (BYTE)InputRecord.Event.KeyEvent.wVirtualScanCode;
- for (i = 0; i < TotalEvents; i++)
- {
- /* Check if this is a key event */
- if (Buffer[i].EventType != KEY_EVENT) continue;
+ /* If this is a key release, set the highest bit in the scan code */
+ if (!InputRecord.Event.KeyEvent.bKeyDown) ScanCode |= 0x80;
- /* Get the scan code */
- ScanCode = (BYTE)Buffer[i].Event.KeyEvent.wVirtualScanCode;
+ /* Push the scan code onto the keyboard queue */
+ for (i = 0; i < InputRecord.Event.KeyEvent.wRepeatCount; i++)
+ {
+ KeyboardQueuePush(ScanCode);
+ }
- /* If this is a key release, set the highest bit in the scan code */
- if (!Buffer[i].Event.KeyEvent.bKeyDown) ScanCode |= 0x80;
+ /* TODO: Update the keyboard shift status flags */
- /* Push the scan code onto the keyboard queue */
- for (j = 0; j < Buffer[i].Event.KeyEvent.wRepeatCount; j++)
- {
- KeyboardQueuePush(ScanCode);
- }
+ /* Keyboard IRQ */
+ PicInterruptRequest(1);
+
+ break;
+ }
+
+ case MOUSE_EVENT:
+ {
+ // TODO: NOT IMPLEMENTED
+ UNIMPLEMENTED;
- /* Yes, IRQ 1 */
- PicInterruptRequest(1);
+ break;
+ }
- /* Stop the loop */
- break;
+ default:
+ {
+ /* Ignored */
+ break;
+ }
+ }
}
-Cleanup:
- HeapFree(GetProcessHeap(), 0, Buffer);
+ return 0;
}
/* EOF */