DOS VGA / Prevent crashes without console

Jukka Heinonen jhei at iki.fi
Tue Oct 29 14:11:04 CST 2002


DOS programs have lately had the habid of crashing if they try
to access certain console functions and DOS program was
started with "wine" instead of "wineconsole". This patch prevents
many of these crashes.


Changelog:
  Prevent crashes when DOS program tries to access console and
  no Windows console is available.


Index: dlls/winedos/vga.h
===================================================================
RCS file: /home/wine/wine/dlls/winedos/vga.h,v
retrieving revision 1.11
diff -u -r1.11 vga.h
--- dlls/winedos/vga.h  13 Aug 2002 03:17:42 -0000      1.11
+++ dlls/winedos/vga.h  29 Oct 2002 20:05:29 -0000
@@ -44,7 +44,7 @@
 BOOL VGA_GetAlphaMode(unsigned*Xres,unsigned*Yres);
 void VGA_SetCursorShape(unsigned char start_options,unsigned char end);
 void VGA_SetCursorPos(unsigned X,unsigned Y);
-void VGA_GetCursorPos(unsigned*X,unsigned*Y);
+BOOL VGA_GetCursorPos(unsigned*X,unsigned*Y);
 void VGA_WriteChars(unsigned X,unsigned Y,unsigned ch,int attr,int count);
 void VGA_PutChar(BYTE ascii);
 void VGA_SetTextAttribute(BYTE attr);
@@ -57,7 +57,7 @@
 void VGA_ScrollDownText(unsigned row1, unsigned col1,
                        unsigned row2, unsigned col2,
                        unsigned lines, BYTE attr);
-void VGA_GetCharacterAtCursor(BYTE *ascii, BYTE *attr);
+BOOL VGA_GetCharacterAtCursor(BYTE *ascii, BYTE *attr);
 
 /* control */
 void VGA_ioport_out(WORD port, BYTE val);



Index: dlls/winedos/vga.c
===================================================================
RCS file: /home/wine/wine/dlls/winedos/vga.c,v
retrieving revision 1.23
diff -u -r1.23 vga.c
--- dlls/winedos/vga.c  30 Aug 2002 00:03:25 -0000      1.23
+++ dlls/winedos/vga.c  29 Oct 2002 20:05:50 -0000
@@ -627,12 +627,17 @@
     SetConsoleCursorPosition(VGA_AlphaConsole(),pos);
 }
 
-void VGA_GetCursorPos(unsigned*X,unsigned*Y)
+BOOL VGA_GetCursorPos(unsigned*X,unsigned*Y)
 {
     CONSOLE_SCREEN_BUFFER_INFO info;
-    GetConsoleScreenBufferInfo(VGA_AlphaConsole(),&info);
-    if (X) *X=info.dwCursorPosition.X;
-    if (Y) *Y=info.dwCursorPosition.Y;
+    if(!GetConsoleScreenBufferInfo(VGA_AlphaConsole(),&info))
+    {
+        return FALSE;
+    } else {
+        if (X) *X=info.dwCursorPosition.X;
+        if (Y) *Y=info.dwCursorPosition.Y;
+        return TRUE;
+    }
 }
 
 void VGA_WriteChars(unsigned X,unsigned Y,unsigned ch,int attr,int count)
@@ -643,6 +648,9 @@
     unsigned XR, YR;
     char *dat;
 
+    if(!VGA_GetAlphaMode(&XR, &YR))
+        return;
+
     EnterCriticalSection(&vga_lock);
 
     info.Char.AsciiChar = ch;
@@ -654,7 +662,6 @@
     dest.Top=Y;
     dest.Bottom=Y;
 
-    VGA_GetAlphaMode(&XR, &YR);
     dat = VGA_AlphaBuffer() + ((XR*Y + X) * 2);
     while (count--) {
         dest.Left = X + count;
@@ -688,9 +695,13 @@
 {
     unsigned width, height, x, y, nx, ny;
 
+    if(!VGA_GetAlphaMode(&width, &height)) {
+        WriteFile(VGA_AlphaConsole(), &ascii, 1, NULL, NULL);
+        return;
+    }
+
     EnterCriticalSection(&vga_lock);
 
-    VGA_GetAlphaMode(&width, &height);
     VGA_GetCursorPos(&x, &y);
 
     switch(ascii) {
@@ -753,10 +764,7 @@
 
     /* return if we fail to get the height and width of the window */
     if(!VGA_GetAlphaMode(&width, &height))
-    {
-        ERR("failed\n");
         return FALSE;
-    }
 
     TRACE("dat = %p, width = %d, height = %d\n", dat, width, height);
 
@@ -794,17 +802,20 @@
     FIXME("not implemented\n");
 }
 
-void VGA_GetCharacterAtCursor(BYTE *ascii, BYTE *attr)
+BOOL VGA_GetCharacterAtCursor(BYTE *ascii, BYTE *attr)
 {
     unsigned width, height, x, y;
     char *dat;
 
-    VGA_GetAlphaMode(&width, &height);
-    VGA_GetCursorPos(&x, &y);
+    if(!VGA_GetAlphaMode(&width, &height) || !VGA_GetCursorPos(&x, &y))
+        return FALSE;
+
     dat = VGA_AlphaBuffer() + ((width*y + x) * 2);
 
     *ascii = dat[0];
     *attr = dat[1];
+
+    return TRUE;
 }
 
 


Index: dlls/winedos/int10.c
===================================================================
RCS file: /home/wine/wine/dlls/winedos/int10.c,v
retrieving revision 1.19
diff -u -r1.19 int10.c
--- dlls/winedos/int10.c        4 Sep 2002 18:52:22 -0000       1.19
+++ dlls/winedos/int10.c        29 Oct 2002 20:06:30 -0000
@@ -489,7 +489,10 @@
            {
                 BYTE ascii, attr;
                 TRACE("Read Character and Attribute at Cursor Position\n");
-                VGA_GetCharacterAtCursor(&ascii, &attr);
+                if(!VGA_GetCharacterAtCursor(&ascii, &attr)) {
+                    ascii = 0;
+                    attr = 0;
+                }
                 SET_AL( context, ascii );
                 SET_AH( context, attr );
             }
@@ -845,6 +848,6 @@
   TRACE("char: 0x%02x(%c)\n", ascii, ascii);
 
   VGA_PutChar(ascii);
-  VGA_GetCursorPos(&xpos, &ypos);
-  BIOS_SetCursorPos(data, 0, xpos, ypos);
+  if(VGA_GetCursorPos(&xpos, &ypos))
+      BIOS_SetCursorPos(data, 0, xpos, ypos);
 }



-- 
Jukka Heinonen <http://www.iki.fi/jhei/>



More information about the wine-patches mailing list