/* * VGA hardware emulation * * Copyright 1998 Ove Kåven (with some help from Marcus Meissner) * */ #include #include "winbase.h" #include "winuser.h" #include "wine/winuser16.h" #include "miscemu.h" #include "vga.h" #include "ddraw.h" #include "debugtools.h" DEFAULT_DEBUG_CHANNEL(ddraw) static IDirectDraw *lpddraw = NULL; static IDirectDrawSurface *lpddsurf; static IDirectDrawPalette *lpddpal; static DDSURFACEDESC sdesc; static WORD poll_timer; static CRITICAL_SECTION vga_crit; static int vga_polling,vga_refresh; int VGA_SetMode(unsigned Xres,unsigned Yres,unsigned Depth) { if (lpddraw) VGA_Exit(); if (!lpddraw) { DirectDrawCreate(NULL,&lpddraw,NULL); if (!lpddraw) { ERR("DirectDraw is not available\n"); return 1; } if (IDirectDraw_SetDisplayMode(lpddraw,Xres,Yres,Depth)) { ERR("DirectDraw does not support requested display mode\n"); IDirectDraw_Release(lpddraw); lpddraw=NULL; return 1; } IDirectDraw_CreatePalette(lpddraw,DDPCAPS_8BIT,NULL,&lpddpal,NULL); memset(&sdesc,0,sizeof(sdesc)); sdesc.dwSize=sizeof(sdesc); sdesc.dwFlags = DDSD_CAPS; sdesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; if (IDirectDraw_CreateSurface(lpddraw,&sdesc,&lpddsurf,NULL)||(!lpddsurf)) { ERR("DirectDraw surface is not available\n"); IDirectDraw_Release(lpddraw); lpddraw=NULL; return 1; } vga_refresh=0; InitializeCriticalSection(&vga_crit); MakeCriticalSectionGlobal(&vga_crit); /* poll every 20ms (50fps should provide adequate responsiveness) */ poll_timer = CreateSystemTimer( 20, VGA_Poll ); } return 0; } int VGA_GetMode(unsigned*Height,unsigned*Width,unsigned*Depth) { if (!lpddraw) return 1; if (!lpddsurf) return 1; if (Height) *Height=sdesc.dwHeight; if (Width) *Width=sdesc.dwWidth; if (Depth) *Depth=sdesc.ddpfPixelFormat.x.dwRGBBitCount; return 0; } void VGA_Exit(void) { if (lpddraw) { SYSTEM_KillSystemTimer(poll_timer); DeleteCriticalSection(&vga_crit); IDirectDrawSurface_Release(lpddsurf); lpddsurf=NULL; IDirectDraw_Release(lpddraw); lpddraw=NULL; } } void VGA_SetPalette(PALETTEENTRY*pal,int start,int len) { if (!lpddraw) return; IDirectDrawPalette_SetEntries(lpddpal,0,start,len,pal); IDirectDrawSurface_SetPalette(lpddsurf,lpddpal); } void VGA_SetQuadPalette(RGBQUAD*color,int start,int len) { PALETTEENTRY pal[256]; int c; if (!lpddraw) return; for (c=0; c