[NTVDM]: Partial revert to r67234: delays were in fact better than frequencies, in...
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 18 Apr 2015 00:29:14 +0000 (00:29 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 18 Apr 2015 00:29:14 +0000 (00:29 +0000)
svn path=/trunk/; revision=67235

reactos/subsystems/mvdm/ntvdm/clock.c
reactos/subsystems/mvdm/ntvdm/clock.h
reactos/subsystems/mvdm/ntvdm/hardware/cmos.c
reactos/subsystems/mvdm/ntvdm/hardware/mouse.c
reactos/subsystems/mvdm/ntvdm/hardware/pit.c
reactos/subsystems/mvdm/ntvdm/hardware/ps2.c
reactos/subsystems/mvdm/ntvdm/hardware/video/vga.c

index e1d43cf..82d5f82 100644 (file)
@@ -141,7 +141,7 @@ VOID ClockUpdate(VOID)
     }
 }
 
-PHARDWARE_TIMER CreateHardwareTimer(ULONG Flags, ULONG Frequency, PHARDWARE_TIMER_PROC Callback)
+PHARDWARE_TIMER CreateHardwareTimer(ULONG Flags, ULONGLONG Delay, PHARDWARE_TIMER_PROC Callback)
 {
     PHARDWARE_TIMER Timer;
     
@@ -151,7 +151,7 @@ PHARDWARE_TIMER CreateHardwareTimer(ULONG Flags, ULONG Frequency, PHARDWARE_TIME
     Timer->Flags = Flags & ~HARDWARE_TIMER_ENABLED;
     Timer->EnableCount = 0;
     Timer->Callback = Callback;
-    SetHardwareTimerDelay(Timer, 1000000000ULL / (ULONGLONG)Frequency);
+    SetHardwareTimerDelay(Timer, Delay);
 
     if (Flags & HARDWARE_TIMER_ENABLED) EnableHardwareTimer(Timer);
     return Timer;
@@ -234,7 +234,7 @@ BOOLEAN ClockInitialize(VOID)
 
 #ifdef IPS_DISPLAY
 
-    IpsTimer = CreateHardwareTimer(HARDWARE_TIMER_ENABLED, 1, IpsDisplayCallback);
+    IpsTimer = CreateHardwareTimer(HARDWARE_TIMER_ENABLED, HZ_TO_NS(1), IpsDisplayCallback);
     if (IpsTimer == NULL)
     {
         wprintf(L"FATAL: Cannot create IPS display timer.\n");
index 65111c5..fb48cd4 100644 (file)
@@ -18,6 +18,9 @@
 #define HARDWARE_TIMER_ONESHOT (1 << 1)
 #define HARDWARE_TIMER_PRECISE (1 << 2)
 
+/* Converts a frequency in Hertz into a duration in nanoseconds */
+#define HZ_TO_NS(Freq) (ULONGLONG)(1000000000ULL / (ULONGLONG)(Freq))
+
 typedef VOID (FASTCALL *PHARDWARE_TIMER_PROC)(ULONGLONG ElapsedTime);
 
 typedef struct _HARDWARE_TIMER
@@ -35,7 +38,7 @@ typedef struct _HARDWARE_TIMER
 PHARDWARE_TIMER CreateHardwareTimer
 (
     ULONG Flags,
-    ULONG Frequency, // in Hz
+    ULONGLONG Delay, /* nanoseconds */
     PHARDWARE_TIMER_PROC Callback
 );
 VOID EnableHardwareTimer(PHARDWARE_TIMER Timer);
index 470d837..1006ee2 100644 (file)
@@ -44,7 +44,7 @@ static VOID RtcUpdatePeriodicTimer(VOID)
     /* 1 and 2 act like 8 and 9 */
     if (RateSelect <= 2) RateSelect += 7;
 
-    SetHardwareTimerDelay(PeriodicTimer, 1000000000ULL / (ULONGLONG)(1 << (16 - RateSelect)));
+    SetHardwareTimerDelay(PeriodicTimer, HZ_TO_NS(1 << (16 - RateSelect)));
     EnableHardwareTimer(PeriodicTimer);
 }
 
@@ -501,9 +501,11 @@ VOID CmosInitialize(VOID)
     RegisterIoPort(CMOS_ADDRESS_PORT, NULL        , CmosWritePort);
     RegisterIoPort(CMOS_DATA_PORT   , CmosReadPort, CmosWritePort);
 
-    ClockTimer = CreateHardwareTimer(HARDWARE_TIMER_ENABLED, 1, RtcTimeUpdate);
+    ClockTimer = CreateHardwareTimer(HARDWARE_TIMER_ENABLED,
+                                     HZ_TO_NS(1),
+                                     RtcTimeUpdate);
     PeriodicTimer = CreateHardwareTimer(HARDWARE_TIMER_ENABLED | HARDWARE_TIMER_PRECISE,
-                                        1000,
+                                        HZ_TO_NS(1000),
                                         RtcPeriodicTick);
 }
 
index 1d722d0..5ffda02 100644 (file)
@@ -454,7 +454,9 @@ BOOLEAN MouseInit(BYTE PS2Connector)
     MouseMutex = CreateMutex(NULL, FALSE, NULL);
     if (MouseMutex == NULL) return FALSE;
 
-    StreamTimer = CreateHardwareTimer(HARDWARE_TIMER_ENABLED, 100, MouseStreamingCallback);
+    StreamTimer = CreateHardwareTimer(HARDWARE_TIMER_ENABLED,
+                                      HZ_TO_NS(100),
+                                      MouseStreamingCallback);
 
     MouseReset();
     return TRUE;
index 0d1dfca..f64d267 100644 (file)
@@ -511,7 +511,7 @@ VOID PitInitialize(VOID)
 
     /* Register the hardware timer */
     MasterClock = CreateHardwareTimer(HARDWARE_TIMER_ENABLED | HARDWARE_TIMER_PRECISE,
-                                      PIT_BASE_FREQUENCY,
+                                      HZ_TO_NS(PIT_BASE_FREQUENCY),
                                       PitClock);
 }
 
index afade9a..5309fd7 100644 (file)
@@ -405,7 +405,9 @@ BOOLEAN PS2Initialize(VOID)
     RegisterIoPort(PS2_CONTROL_PORT, PS2ReadPort, PS2WritePort);
     RegisterIoPort(PS2_DATA_PORT   , PS2ReadPort, PS2WritePort);
 
-    IrqTimer = CreateHardwareTimer(HARDWARE_TIMER_ONESHOT, 100, GeneratePS2Irq);
+    IrqTimer = CreateHardwareTimer(HARDWARE_TIMER_ONESHOT,
+                                   HZ_TO_NS(100),
+                                   GeneratePS2Irq);
 
     return TRUE;
 }
index a0dd0c5..d4b39e9 100644 (file)
@@ -2127,8 +2127,8 @@ BOOLEAN VgaInitialize(HANDLE TextHandle)
     RegisterIoPort(0x3D8, VgaReadPort, VgaWritePort);   // CGA_MODE_CTRL_REG
     RegisterIoPort(0x3D9, VgaReadPort, VgaWritePort);   // CGA_PAL_CTRL_REG
 
-    HSyncTimer = CreateHardwareTimer(HARDWARE_TIMER_ENABLED, 31469, VgaHorizontalRetrace);
-    VSyncTimer = CreateHardwareTimer(HARDWARE_TIMER_ENABLED, 60, VgaVerticalRetrace);
+    HSyncTimer = CreateHardwareTimer(HARDWARE_TIMER_ENABLED, HZ_TO_NS(31469), VgaHorizontalRetrace);
+    VSyncTimer = CreateHardwareTimer(HARDWARE_TIMER_ENABLED, HZ_TO_NS(60), VgaVerticalRetrace);
 
     /* Return success */
     return TRUE;