Improved DirectDrawPalette handling (set it on init, not every time it
changes). Added VGA_WriteChars() function.

diff --git a/graphics/vga.c b/graphics/vga.c
index dedc0c8..89aae22 100644
--- a/graphics/vga.c
+++ b/graphics/vga.c
@@ -47,6 +47,11 @@
     return GetStdHandle(STD_OUTPUT_HANDLE);
 }
 
+char*VGA_AlphaBuffer(void)
+{
+    return DOSMEM_MapDosToLinear(0xb8000);
+}
+
 /*** GRAPHICS MODE ***/
 
 int VGA_SetMode(unsigned Xres,unsigned Yres,unsigned Depth)
@@ -80,6 +85,8 @@
             lpddraw=NULL;
             return 1;
         }
+        FIXME("no default palette entries\n");
+        IDirectDrawSurface_SetPalette(lpddsurf,lpddpal);
         vga_refresh=0;
         /* poll every 20ms (50fps should provide adequate responsiveness) */
         VGA_InstallTimer(20);
@@ -101,8 +108,11 @@
 {
     if (lpddraw) {
         VGA_DeinstallTimer();
+        IDirectDrawSurface_SetPalette(lpddsurf,NULL);
         IDirectDrawSurface_Release(lpddsurf);
         lpddsurf=NULL;
+        IDirectDrawPalette_Release(lpddpal);
+        lpddpal=NULL;
         IDirectDraw_Release(lpddraw);
         lpddraw=NULL;
     }
@@ -112,7 +122,6 @@
 {
     if (!lpddraw) return;
     IDirectDrawPalette_SetEntries(lpddpal,0,start,len,pal);
-    IDirectDrawSurface_SetPalette(lpddsurf,lpddpal);
 }
 
 void VGA_SetQuadPalette(RGBQUAD*color,int start,int len)
@@ -128,7 +137,6 @@
         pal[c].peFlags=0;
     }
     IDirectDrawPalette_SetEntries(lpddpal,0,start,len,pal);
-    IDirectDrawSurface_SetPalette(lpddsurf,lpddpal);
 }
 
 LPSTR VGA_Lock(unsigned*Pitch,unsigned*Height,unsigned*Width,unsigned*Depth)
@@ -193,6 +201,21 @@
     if (Y) *Y=info.dwCursorPosition.Y;
 }
 
+void VGA_WriteChars(unsigned X,unsigned Y,unsigned ch,int attr,int count)
+{
+    unsigned XR, YR;
+    char*dat;
+
+    VGA_GetAlphaMode(&XR, &YR);
+    dat = VGA_AlphaBuffer() + ((XR*Y + X) * 2);
+    /* FIXME: also call WriteConsoleOutputA, for better responsiveness */
+    while (count--) {
+        *dat++ = ch;
+        if (attr>=0) *dat = attr;
+        dat++;
+    }
+}
+
 /*** CONTROL ***/
 
 void CALLBACK VGA_Poll( ULONG_PTR arg )
@@ -224,7 +247,7 @@
           HANDLE con = VGA_AlphaConsole();
 
           VGA_GetAlphaMode(&Width,&Height);
-          dat = DOSMEM_MapDosToLinear(0xb8000);
+          dat = VGA_AlphaBuffer();
           siz.X = 80; siz.Y = 1;
           off.X = 0; off.Y = 0;
           /* copy from virtual VGA frame buffer to console */