[FAST486][NTVDM]
[reactos.git] / subsystems / ntvdm / ntvdm.c
index 7212309..c1efd21 100644 (file)
 
 BOOLEAN VdmRunning = TRUE;
 LPVOID BaseAddress = NULL;
-LPCWSTR ExceptionName[] =
-{
-    L"Division By Zero",
-    L"Debug",
-    L"Unexpected Error",
-    L"Breakpoint",
-    L"Integer Overflow",
-    L"Bound Range Exceeded",
-    L"Invalid Opcode",
-    L"FPU Not Available"
-};
 
 /* PUBLIC FUNCTIONS ***********************************************************/
 
@@ -79,12 +68,12 @@ INT wmain(INT argc, WCHAR *argv[])
     INT i;
     CHAR CommandLine[DOS_CMDLINE_LENGTH];
     DWORD CurrentTickCount;
-    DWORD LastTickCount = GetTickCount();
     DWORD Cycles = 0;
     DWORD LastCyclePrintout = GetTickCount();
     DWORD LastVerticalRefresh = GetTickCount();
     LARGE_INTEGER Frequency, LastTimerTick, Counter;
     LONGLONG TimerTicks;
+    HANDLE InputThread = NULL;
 
     /* Set the handler routine */
     SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE);
@@ -141,6 +130,9 @@ INT wmain(INT argc, WCHAR *argv[])
         DisplayMessage(L"Could not start program: %S", CommandLine);
         return -1;
     }
+
+    /* Start the input thread */
+    InputThread = CreateThread(NULL, 0, &InputThreadProc, NULL, 0, NULL);
  
     /* Set the last timer tick to the current time */
     QueryPerformanceCounter(&LastTimerTick);
@@ -148,25 +140,36 @@ INT wmain(INT argc, WCHAR *argv[])
     /* Main loop */
     while (VdmRunning)
     {
+        /* Get the resolution of the system timer */
+        DWORD TimerResolution = PitGetResolution();
+
         /* Get the current number of ticks */
         CurrentTickCount = GetTickCount();
  
-        /* Get the current performance counter value */
-        QueryPerformanceCounter(&Counter);
+        if (TimerResolution > 1000)
+        {
+            /* Get the current performance counter value */
+            QueryPerformanceCounter(&Counter);
  
-        /* Get the number of PIT ticks that have passed */
-        TimerTicks = ((Counter.QuadPart - LastTimerTick.QuadPart)
-                     * PIT_BASE_FREQUENCY) / Frequency.QuadPart;
+            /* Get the number of PIT ticks that have passed */
+            TimerTicks = ((Counter.QuadPart - LastTimerTick.QuadPart)
+                         * PIT_BASE_FREQUENCY) / Frequency.QuadPart;
+        }
+        else
+        {
+            /* Use the standard tick count */
+            Counter.QuadPart = CurrentTickCount;
+
+            /* Get the number of PIT ticks that have passed */
+            TimerTicks = ((Counter.QuadPart - LastTimerTick.QuadPart)
+                         * PIT_BASE_FREQUENCY) / 1000;
+        }
  
         /* Update the PIT */
-        for (i = 0; i < TimerTicks; i++) PitDecrementCount();
-        LastTimerTick = Counter;
-
-        /* Check for console input events every millisecond */
-        if (CurrentTickCount != LastTickCount)
+        if (TimerTicks > 0)
         {
-            CheckForInputEvents();
-            LastTickCount = CurrentTickCount;
+            for (i = 0; i < TimerTicks; i++) PitDecrementCount();
+            LastTimerTick = Counter;
         }
 
         /* Check for vertical retrace */
@@ -198,6 +201,7 @@ INT wmain(INT argc, WCHAR *argv[])
     VgaRefreshDisplay();
 
 Cleanup:
+    if (InputThread != NULL) CloseHandle(InputThread);
     BiosCleanup();
     EmulatorCleanup();