diff --git a/main.c b/main.c index eee6d81..015f24a 100644 --- a/main.c +++ b/main.c @@ -175,12 +175,6 @@ HRESULT __stdcall ddraw_SetDisplayMode(IDirectDrawImpl *This, DWORD width, DWORD This->render.run = TRUE; - /* currently we only support 8 bit modes */ - if(bpp != 8) - { - return DDERR_INVALIDMODE; - } - This->mode.dmSize = sizeof(DEVMODE); This->mode.dmDriverExtra = 0; @@ -422,6 +416,9 @@ HRESULT __stdcall ddraw_WaitForVerticalBlank(IDirectDrawImpl *This, DWORD a, HAN HRESULT __stdcall ddraw_QueryInterface(IDirectDrawImpl *This, REFIID riid, void **obj) { printf("DirectDraw::QueryInterface(This=%p, riid=%08X, obj=%p)\n", This, (unsigned int)riid, obj); + + *obj = This; + return S_OK; } diff --git a/render_soft.c b/render_soft.c index 95547ef..7666f2b 100644 --- a/render_soft.c +++ b/render_soft.c @@ -27,11 +27,11 @@ DWORD WINAPI render_soft_main(void) PBITMAPINFO bmi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFO) + (sizeof(RGBQUAD) * 256) + 1024); - bmi->bmiHeader.biSize = sizeof(BITMAPINFO); + bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi->bmiHeader.biWidth = ddraw->width; bmi->bmiHeader.biHeight = -ddraw->height; bmi->bmiHeader.biPlanes = 1; - bmi->bmiHeader.biBitCount = 8; + bmi->bmiHeader.biBitCount = ddraw->bpp; bmi->bmiHeader.biCompression = BI_RGB; SelectObject(memDC, surface); @@ -58,9 +58,9 @@ DWORD WINAPI render_soft_main(void) } EnterCriticalSection(&ddraw->cs); - if (ddraw->primary && ddraw->primary->palette) + if (ddraw->primary && (ddraw->primary->palette || ddraw->bpp == 16)) { - if (ddraw->primary->palette->data_rgb == NULL) + if (ddraw->primary->palette && ddraw->primary->palette->data_rgb == NULL) { ddraw->primary->palette->data_rgb = &bmi->bmiColors[1]; } diff --git a/surface.c b/surface.c index e605e38..628a306 100644 --- a/surface.c +++ b/surface.c @@ -151,15 +151,27 @@ HRESULT __stdcall ddraw_surface_DeleteAttachedSurface(IDirectDrawSurfaceImpl *Th HRESULT __stdcall ddraw_surface_GetSurfaceDesc(IDirectDrawSurfaceImpl *This, LPDDSURFACEDESC lpDDSurfaceDesc) { +#if _DEBUG printf("IDirectDrawSurface::GetSurfaceDesc(This=%p, lpDDSurfaceDesc=%p)\n", This, lpDDSurfaceDesc); +#endif - lpDDSurfaceDesc->dwFlags = DDSD_WIDTH|DDSD_HEIGHT|DDSD_PITCH|DDSD_PIXELFORMAT; + lpDDSurfaceDesc->dwSize = sizeof(DDSURFACEDESC); + lpDDSurfaceDesc->dwFlags = DDSD_WIDTH|DDSD_HEIGHT|DDSD_PITCH|DDSD_PIXELFORMAT|DDSD_LPSURFACE; lpDDSurfaceDesc->dwWidth = This->width; lpDDSurfaceDesc->dwHeight = This->height; lpDDSurfaceDesc->lPitch = This->lPitch; + lpDDSurfaceDesc->lpSurface = This->surface; lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_RGB; lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount = This->bpp; + if (This->bpp == 16) + { + /* RGB 555 */ + lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x7C00; + lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x03E0; + lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x001F; + } + return DD_OK; } @@ -168,10 +180,11 @@ HRESULT __stdcall ddraw_surface_EnumAttachedSurfaces(IDirectDrawSurfaceImpl *Thi printf("IDirectDrawSurface::EnumAttachedSurfaces(This=%p, lpContext=%p, lpEnumSurfacesCallback=%p)\n", This, lpContext, lpEnumSurfacesCallback); /* this is not actually complete, but Carmageddon seems to call EnumAttachedSurfaces instead of GetSurfaceDesc to get the main surface description */ - LPDDSURFACEDESC lpDDSurfaceDesc = malloc(sizeof(DDSURFACEDESC)); + static LPDDSURFACEDESC lpDDSurfaceDesc; + lpDDSurfaceDesc = (LPDDSURFACEDESC)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DDSURFACEDESC)); ddraw_surface_GetSurfaceDesc(This, lpDDSurfaceDesc); - free(lpDDSurfaceDesc); lpEnumSurfacesCallback((LPDIRECTDRAWSURFACE)This, lpDDSurfaceDesc, lpContext); + HeapFree(GetProcessHeap(), 0, lpDDSurfaceDesc); return DD_OK; } @@ -302,12 +315,7 @@ HRESULT __stdcall ddraw_surface_Lock(IDirectDrawSurfaceImpl *This, LPRECT lpDest } #endif - lpDDSurfaceDesc->dwSize = sizeof(DDSURFACEDESC); - lpDDSurfaceDesc->dwFlags = DDSD_LPSURFACE|DDSD_PITCH; - lpDDSurfaceDesc->lpSurface = This->surface; - lpDDSurfaceDesc->lPitch = This->lPitch; - - return DD_OK; + return ddraw_surface_GetSurfaceDesc(This, lpDDSurfaceDesc); } HRESULT __stdcall ddraw_surface_ReleaseDC(IDirectDrawSurfaceImpl *This, HDC a) @@ -466,9 +474,9 @@ HRESULT __stdcall ddraw_CreateSurface(IDirectDrawImpl *This, LPDDSURFACEDESC lpD if(Surface->width && Surface->height) { - Surface->lPitch = Surface->width; Surface->lXPitch = Surface->bpp / 8; - Surface->surface = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Surface->width * Surface->height * Surface->lXPitch); + Surface->lPitch = Surface->width * Surface->lXPitch; + Surface->surface = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Surface->lPitch * Surface->height * Surface->lXPitch); } printf(" Surface = %p (%dx%d@%d)\n", Surface, (int)Surface->width, (int)Surface->height, (int)Surface->bpp);