Author: aandrejevic
Date: Wed Dec  4 00:38:52 2013
New Revision: 61214

URL: http://svn.reactos.org/svn/reactos?rev=61214&view=rev
Log:
[NTVDM]
Fix the VGA refresh rate.
Serialize access to the PS/2 keyboard queue.


Modified:
    branches/ntvdm/subsystems/ntvdm/ntvdm.c
    branches/ntvdm/subsystems/ntvdm/ps2.c

Modified: branches/ntvdm/subsystems/ntvdm/ntvdm.c
URL: 
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/ntvdm.c?rev=61214&r1=61213&r2=61214&view=diff
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/ntvdm.c     [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/ntvdm.c     [iso-8859-1] Wed Dec  4 
00:38:52 2013
@@ -221,7 +221,7 @@
         }
 
         /* Check for vertical retrace */
-        if ((CurrentTickCount - LastVerticalRefresh) >= 16)
+        if ((CurrentTickCount - LastVerticalRefresh) >= 15)
         {
             VgaRefreshDisplay();
             LastVerticalRefresh = CurrentTickCount;

Modified: branches/ntvdm/subsystems/ntvdm/ps2.c
URL: 
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/ps2.c?rev=61214&r1=61213&r2=61214&view=diff
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/ps2.c       [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/ps2.c       [iso-8859-1] Wed Dec  4 
00:38:52 2013
@@ -24,6 +24,7 @@
 static BYTE KeyboardData = 0, KeyboardResponse = 0;
 static BOOLEAN KeyboardReadResponse = FALSE, KeyboardWriteResponse = FALSE;
 static BYTE KeyboardConfig = PS2_DEFAULT_CONFIG;
+static HANDLE QueueMutex = NULL;
 
 static HANDLE InputThread = NULL;
 
@@ -31,10 +32,15 @@
 
 static BOOLEAN KeyboardQueuePush(BYTE ScanCode)
 {
+    BOOLEAN Result = TRUE;
+
+    WaitForSingleObject(QueueMutex, INFINITE);
+
     /* Check if the keyboard queue is full */
     if (!KeyboardQueueEmpty && (KeyboardQueueStart == KeyboardQueueEnd))
     {
-        return FALSE;
+        Result = FALSE;
+        goto Done;
     }
 
     /* Insert the value in the queue */
@@ -45,13 +51,23 @@
     /* Since we inserted a value, it's not empty anymore */
     KeyboardQueueEmpty = FALSE;
 
-    return TRUE;
+Done:
+    ReleaseMutex(QueueMutex);
+    return Result;
 }
 
 static BOOLEAN KeyboardQueuePop(BYTE *ScanCode)
 {
+    BOOLEAN Result = TRUE;
+
+    WaitForSingleObject(QueueMutex, INFINITE);
+
     /* Make sure the keyboard queue is not empty */
-    if (KeyboardQueueEmpty) return FALSE;
+    if (KeyboardQueueEmpty)
+    {
+        Result = FALSE;
+        goto Done;
+    }
 
     /* Get the scan code */
     *ScanCode = KeyboardQueue[KeyboardQueueStart];
@@ -66,7 +82,9 @@
         KeyboardQueueEmpty = TRUE;
     }
 
-    return TRUE;
+Done:
+    ReleaseMutex(QueueMutex);
+    return Result;
 }
 
 /* PUBLIC FUNCTIONS 
***********************************************************/
@@ -338,6 +356,9 @@
 
 BOOLEAN PS2Initialize(HANDLE ConsoleInput)
 {
+    /* Create the mutex */
+    QueueMutex = CreateMutex(NULL, FALSE, NULL);
+
     /* Start the input thread */
     InputThread = CreateThread(NULL, 0, &InputThreadProc, ConsoleInput, 0, 
NULL);
 
@@ -355,6 +376,8 @@
     /* Close the input thread handle */
     if (InputThread != NULL) CloseHandle(InputThread);
     InputThread = NULL;
+
+    CloseHandle(QueueMutex);
 }
 
 /* EOF */


Reply via email to