Author: aandrejevic
Date: Tue Jun  9 14:48:30 2015
New Revision: 68091

URL: http://svn.reactos.org/svn/reactos?rev=68091&view=rev
Log:
[NTVDM]
Properly clear the video memory when switching to a different mode.


Modified:
    trunk/reactos/subsystems/mvdm/ntvdm/bios/vidbios.c

Modified: trunk/reactos/subsystems/mvdm/ntvdm/bios/vidbios.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/bios/vidbios.c?rev=68091&r1=68090&r2=68091&view=diff
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/bios/vidbios.c  [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/bios/vidbios.c  [iso-8859-1] Tue Jun  9 
14:48:30 2015
@@ -2387,6 +2387,44 @@
     return Bda->VideoMode | (Bda->VGAOptions & 0x80);
 }
 
+static inline VOID VidBiosClearScreen(VOID)
+{
+    static const DWORD MemoryMaps[4] = { 0xA0000, 0xA0000, 0xB0000, 0xB8000 };
+    static const DWORD MemorySizes[4] = { 0x20000, 0x10000, 0x10000, 0x8000 };
+
+    DWORD VideoAddress;
+    BYTE Buffer[0x20000];
+    DWORD BufferSize;
+    BYTE Misc;
+
+    /* Read the misc register */
+    IOWriteB(VGA_GC_INDEX, VGA_GC_MISC_REG);
+    Misc = IOReadB(VGA_GC_DATA);
+
+    /* Get the video address */
+    VideoAddress = MemoryMaps[(Misc >> 2) & 3];
+    BufferSize = MemorySizes[(Misc >> 2) & 3];
+
+    if (Misc & 1)
+    {
+        /* Graphics mode */
+        RtlZeroMemory(Buffer, BufferSize);
+    }
+    else
+    {
+        INT i;
+
+        /* Text mode */
+        for (i = 0; i < (BufferSize >> 1); i++)
+        {
+            ((PWORD)Buffer)[i] = MAKEWORD(' ', DEFAULT_ATTRIBUTE);
+        }
+    }
+
+    /* Write to video memory */
+    EmulatorWriteMemory(&EmulatorContext, VideoAddress, Buffer, BufferSize);
+}
+
 static BOOLEAN VidBiosSetVideoMode(BYTE ModeNumber)
 {
     BYTE Page;
@@ -2503,30 +2541,7 @@
     for (Page = 0; Page < BIOS_MAX_PAGES; ++Page)
         VidBiosSetCursorPosition(0, 0, Page);
 
-    // HACK: We clear here all the text memory. TODO: Do it better!
-    if (!DoNotClear && ((ModeNumber >= 0x00 && ModeNumber <= 0x03) || 
(ModeNumber == 0x07)))
-    {
-        INT i, j;
-        DWORD VideoAddress;
-        WORD FillCharacter = MAKEWORD(' ', DEFAULT_ATTRIBUTE);
-
-        for (Page = 0; Page < BIOS_MAX_PAGES; ++Page)
-        {
-            VideoAddress = TO_LINEAR(TEXT_VIDEO_SEG, Page * 
Bda->VideoPageSize);
-
-            for (i = 0; i <= Bda->ScreenRows; i++)
-            {
-                for (j = 0; j <= Bda->ScreenColumns - 1; j++)
-                {
-                    /* Write to video memory */
-                    EmulatorWriteMemory(&EmulatorContext,
-                                        VideoAddress + (i * Bda->ScreenColumns 
+ j) * sizeof(WORD),
-                                        (LPVOID)&FillCharacter,
-                                        sizeof(FillCharacter));
-                }
-            }
-        }
-    }
+    if (!DoNotClear) VidBiosClearScreen();
 
     /* Refresh display */
     VgaRefreshDisplay();


Reply via email to