[BOOTVID] Don't increment an uninitialized and unused variable, bug #5103
[reactos.git] / reactos / drivers / base / bootvid / i386 / bootvid.c
index aaf11a3..08d0dc1 100644 (file)
@@ -155,7 +155,7 @@ VgaInterpretCmdStream(IN PUSHORT CmdStream)
                     if (!ShortValue) continue;
 
                     /* Loop the cmd array */
-                    for (; Count; Count--, CmdStream++, Value++)
+                    for (; Count; Count--, CmdStream++)
                     {
                         /* Get the byte we're writing */
                         ShortValue += (*CmdStream) << 8;
@@ -355,9 +355,9 @@ BOOLEAN
 NTAPI
 VidInitialize(IN BOOLEAN SetMode)
 {
-    ULONG Context = 0;
+    ULONG_PTR Context = 0;
     PHYSICAL_ADDRESS TranslatedAddress;
-    PHYSICAL_ADDRESS NullAddress = {{0}};
+    PHYSICAL_ADDRESS NullAddress = {{0, 0}}, VgaAddress;
     ULONG AddressSpace = 1;
     BOOLEAN Result;
     ULONG_PTR Base;
@@ -373,12 +373,58 @@ VidInitialize(IN BOOLEAN SetMode)
                                           TRUE);
     if (!Result) return FALSE;
 
-    /* See if this is I/O Space, which we need to map */
-TryAgain:
+    /* Loop trying to find posssible VGA base addresses */
+    while (TRUE)
+    {
+        /* See if this is I/O Space, which we need to map */
+        if (!AddressSpace)
+        {
+            /* Map it */
+            Base = (ULONG_PTR)MmMapIoSpace(TranslatedAddress, 0x400, MmNonCached);
+        }
+        else
+        {
+            /* The base is the translated address, no need to map I/O space */
+            Base = TranslatedAddress.LowPart;
+        }
+
+        /* Try to see if this is VGA */
+        VgaRegisterBase = Base;
+        if (VgaIsPresent())
+        {
+            /* Translate the VGA Memory Address */
+            VgaAddress.LowPart = 0xA0000;
+            VgaAddress.HighPart = 0;
+            AddressSpace = 0;
+            Result = HalFindBusAddressTranslation(VgaAddress,
+                                                  &AddressSpace,
+                                                  &TranslatedAddress,
+                                                  &Context,
+                                                  FALSE);
+            if (Result) break;
+            
+            /* Try to see if there's any other address */
+            Result = HalFindBusAddressTranslation(NullAddress,
+                                                  &AddressSpace,
+                                                  &TranslatedAddress,
+                                                  &Context,
+                                                  TRUE);
+            if (!Result) return FALSE;
+        }
+        else
+        {
+            /* It's not, so unmap the I/O space if we mapped it */
+            if (!AddressSpace) MmUnmapIoSpace((PVOID)VgaRegisterBase, 0x400);
+        }
+    }
+
+    /* Success! See if this is I/O Space, which we need to map */
     if (!AddressSpace)
     {
         /* Map it */
-        Base = (ULONG_PTR)MmMapIoSpace(TranslatedAddress, 0x400, MmNonCached);
+        Base = (ULONG_PTR)MmMapIoSpace(TranslatedAddress,
+                                       0x20000,
+                                       MmNonCached);
     }
     else
     {
@@ -386,67 +432,23 @@ TryAgain:
         Base = TranslatedAddress.LowPart;
     }
 
-    /* Set the VGA Register base and now check if we have a VGA device */
-    VgaRegisterBase = Base;
-    if (VgaIsPresent())
-    {
-        /* Translate the VGA Memory Address */
-        NullAddress.LowPart = 0xA0000;
-        AddressSpace = 0;
-        Result = HalFindBusAddressTranslation(NullAddress,
-                                              &AddressSpace,
-                                              &TranslatedAddress,
-                                              &Context,
-                                              FALSE);
-        if (Result)
-        {
-            /* Success! See if this is I/O Space, which we need to map */
-            if (!AddressSpace)
-            {
-                /* Map it */
-                Base = (ULONG_PTR)MmMapIoSpace(TranslatedAddress,
-                                               0x20000,
-                                               MmNonCached);
-            }
-            else
-            {
-                /* The base is the translated address, no need to map I/O space */
-                Base = TranslatedAddress.LowPart;
-            }
-
-            /* Set the VGA Memory Base */
-            VgaBase = Base;
+    /* Set the VGA Memory Base */
+    VgaBase = Base;
 
-            /* Now check if we have to set the mode */
-            if (SetMode)
-            {
-                /* Reset the display */
-                HalResetDisplay();
-                curr_x = 0;
-                curr_y = 0;
-
-                /* Initialize it */
-                VgaInterpretCmdStream(AT_Initialization);
-                return TRUE;
-            }
-        }
-    }
-    else
+    /* Now check if we have to set the mode */
+    if (SetMode)
     {
-        /* It's not, so unmap the I/O space if we mapped it */
-        if (!AddressSpace) MmUnmapIoSpace((PVOID)VgaRegisterBase, 0x400);
-    }
+        /* Reset the display */
+        HalResetDisplay();
+        curr_x = 0;
+        curr_y = 0;
 
-    /* If we got here, then we failed...let's try again */
-    Result = HalFindBusAddressTranslation(NullAddress,
-                                          &AddressSpace,
-                                          &TranslatedAddress,
-                                          &Context,
-                                          TRUE);
-    if (Result) goto TryAgain;
-
-    /* If we got here, then we failed even past our re-try... */
-    return FALSE;
+        /* Initialize it */
+        VgaInterpretCmdStream(AT_Initialization);
+    }
+    
+    /* VGA is ready */
+    return TRUE;
 }
 
 /*