D modes now work in 32bpp windowed mode (gfx filters etc)

This commit is contained in:
pagefault
2003-07-23 17:09:05 +00:00
parent 1c13ff3988
commit 9342dd9ca6
2 changed files with 160 additions and 61 deletions

View File

@@ -462,9 +462,9 @@ NEWSYM DrawWin320x240x16
sub edi,640 sub edi,640
add esi,64 add esi,64
%ifdef __WIN32__ %ifdef __WIN32__
cmp eax,239 cmp ebx,239
%else %else
cmp eax,223 cmp ebx,223
%endif %endif
jne .Copying2MMX jne .Copying2MMX
mov ecx,128 mov ecx,128

View File

@@ -71,6 +71,7 @@ LPDIRECTDRAW BasiclpDD = NULL;
LPDIRECTDRAW7 lpDD = NULL; LPDIRECTDRAW7 lpDD = NULL;
LPDIRECTDRAWSURFACE7 DD_Primary = NULL; LPDIRECTDRAWSURFACE7 DD_Primary = NULL;
LPDIRECTDRAWSURFACE7 DD_CFB = NULL; LPDIRECTDRAWSURFACE7 DD_CFB = NULL;
LPDIRECTDRAWSURFACE7 DD_CFB16 = NULL;
LPDIRECTDRAWSURFACE7 DD_BackBuffer = NULL; LPDIRECTDRAWSURFACE7 DD_BackBuffer = NULL;
LPDIRECTDRAWCLIPPER lpDDClipper = NULL; LPDIRECTDRAWCLIPPER lpDDClipper = NULL;
RECT rcWindow; RECT rcWindow;
@@ -124,6 +125,7 @@ BYTE IsActivated=1;
WORD PrevRes=0; WORD PrevRes=0;
RECT BlitArea; RECT BlitArea;
BYTE AltSurface=0;
extern "C" { extern "C" {
DWORD MouseButton; DWORD MouseButton;
@@ -302,7 +304,7 @@ void DrawScreen()
DDrawError(); DDrawError();
} }
} }
DD_Primary->Blt(&rcWindow, DD_CFB, &BlitArea, DDBLT_WAIT, NULL); DD_Primary->Blt(&rcWindow, AltSurface == 0 ? DD_CFB : DD_CFB16, &BlitArea, DDBLT_WAIT, NULL);
} }
} }
@@ -1077,6 +1079,12 @@ void ReleaseDirectDraw()
DD_CFB = NULL; DD_CFB = NULL;
} }
if (DD_CFB16)
{
DD_CFB16->Release();
DD_CFB16 = NULL;
}
if (lpDDClipper) if (lpDDClipper)
{ {
lpDDClipper->Release(); lpDDClipper->Release();
@@ -1462,6 +1470,24 @@ int InitDirectDraw()
return FALSE; return FALSE;
} }
// create alt. drawing surface
if ( BitDepth == 32 )
{
ddsd2.dwFlags |= DDSD_PIXELFORMAT;
ddsd2.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
ddsd2.ddpfPixelFormat.dwFlags = DDPF_RGB;
ddsd2.ddpfPixelFormat.dwRGBBitCount = 16;
ddsd2.ddpfPixelFormat.dwRBitMask = 0xF800;
ddsd2.ddpfPixelFormat.dwGBitMask = 0x07E0;
ddsd2.ddpfPixelFormat.dwBBitMask = 0x001F;
if (lpDD->CreateSurface(&ddsd2, &DD_CFB16, NULL) != DD_OK)
{
MessageBox(NULL, "IDirectDraw7::CreateSurface failed.", "DirectDraw Error", MB_ICONERROR);
return FALSE;
}
}
if (!blur_buffer) blur_buffer = malloc(SurfaceX * SurfaceY * (BitDepth == 16 ? 2 : 4)); if (!blur_buffer) blur_buffer = malloc(SurfaceX * SurfaceY * (BitDepth == 16 ? 2 : 4));
else blur_buffer = realloc(blur_buffer, SurfaceX * SurfaceY * (BitDepth == 16 ? 2 : 4)); else blur_buffer = realloc(blur_buffer, SurfaceX * SurfaceY * (BitDepth == 16 ? 2 : 4));
if (!blur_temp) blur_temp = malloc(SurfaceX * SurfaceY * (BitDepth == 16 ? 2 : 4)); if (!blur_temp) blur_temp = malloc(SurfaceX * SurfaceY * (BitDepth == 16 ? 2 : 4));
@@ -1475,25 +1501,66 @@ DDSURFACEDESC2 ddsd;
DWORD LockSurface() DWORD LockSurface()
{ {
HRESULT hRes;
if (DD_CFB == NULL) return(0); if (AltSurface == 0)
{
if (DD_CFB != NULL)
{
memset(&ddsd,0,sizeof(ddsd)); memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof( ddsd ); ddsd.dwSize = sizeof( ddsd );
ddsd.dwFlags = DDSD_LPSURFACE | DDSD_PITCH; ddsd.dwFlags = DDSD_LPSURFACE | DDSD_PITCH;
if (DD_CFB->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL) != DD_OK)
{
return(0);
}
hRes = DD_CFB->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL);
if (hRes == DD_OK)
{
SurfBuf = (BYTE*)ddsd.lpSurface; SurfBuf = (BYTE*)ddsd.lpSurface;
return(ddsd.lPitch); return(ddsd.lPitch);
}
else
{
if (hRes == DDERR_SURFACELOST)
DD_CFB->Restore();
return(0);
}
}
else
return(0);
}
else
{
if (DD_CFB16 != NULL)
{
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof( ddsd );
ddsd.dwFlags = DDSD_LPSURFACE | DDSD_PITCH;
hRes = DD_CFB16->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL);
if (hRes == DD_OK)
{
SurfBuf = (BYTE*)ddsd.lpSurface;
return(ddsd.lPitch);
}
else
{
if (hRes == DDERR_SURFACELOST)
DD_CFB16->Restore();
return(0);
}
}
else
return(0);
}
} }
void UnlockSurface() void UnlockSurface()
{ {
if (AltSurface == 0)
DD_CFB->Unlock((struct tagRECT *)ddsd.lpSurface); DD_CFB->Unlock((struct tagRECT *)ddsd.lpSurface);
DrawScreen(); else
DD_CFB16->Unlock((struct tagRECT *)ddsd.lpSurface);
} }
extern "C" { extern "C" {
@@ -2154,14 +2221,19 @@ extern void ClearWin32();
void clearwin() void clearwin()
{ {
DWORD i,j,color32; HRESULT hRes;
DWORD *SURFDW;
pitch=LockSurface(); if (DD_CFB != NULL)
if (pitch==0) { return; } {
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
SurfBufD=(DWORD) &SurfBuf[0]; hRes = DD_CFB->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL);
SURFDW=(DWORD *) &SurfBuf[0];
if (hRes == DD_OK)
{
SurfBufD=(DWORD)ddsd.lpSurface;
pitch = ddsd.lPitch;
switch (BitDepth) switch (BitDepth)
{ {
@@ -2172,7 +2244,31 @@ void clearwin()
ClearWin32(); ClearWin32();
break; break;
} }
UnlockSurface(); DD_CFB->Unlock((struct tagRECT *)ddsd.lpSurface);
}
else
if (hRes == DDERR_SURFACELOST)
DD_CFB->Restore();
}
if (DD_CFB16 != NULL)
{
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
hRes = DD_CFB16->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL);
if (hRes == DD_OK)
{
SurfBufD=(DWORD)ddsd.lpSurface;
pitch = ddsd.lPitch;
ClearWin16();
DD_CFB16->Unlock((struct tagRECT *)ddsd.lpSurface);
}
else
if (hRes == DDERR_SURFACELOST)
DD_CFB16->Restore();
}
} }
void clear_display() void clear_display()
@@ -2234,12 +2330,13 @@ void drawscreenwin(void)
UpdateVFrame(); UpdateVFrame();
if (curblank!=0) return; if (curblank!=0) return;
AltSurface = 0;
if ( ((SurfaceX==512) || (SurfaceX==640)) && (BitDepth == 32) )
AltSurface = 1;
if (!(pitch = LockSurface())) if (!(pitch = LockSurface()))
{
DD_Primary->Restore();
DD_CFB->Restore();
return; return;
}
ScreenPtr=vidbuffer; ScreenPtr=vidbuffer;
ScreenPtr+=16*2+32*2+256*2; ScreenPtr+=16*2+32*2+256*2;
@@ -2301,7 +2398,6 @@ void drawscreenwin(void)
Refresh = 100; Refresh = 100;
InitDirectDraw(); InitDirectDraw();
} }
if (SurfaceX == 256 && SurfaceY == 240) if (SurfaceX == 256 && SurfaceY == 240)
{ {
switch (BitDepth) switch (BitDepth)
@@ -2428,6 +2524,7 @@ void drawscreenwin(void)
switch (BitDepth) switch (BitDepth)
{ {
case 16: case 16:
case 32: // using 16bpp AltSurface
AddEndBytes=pitch-1024; AddEndBytes=pitch-1024;
NumBytesPerLine=pitch; NumBytesPerLine=pitch;
WinVidMemStart=&SurfBuf[0]; WinVidMemStart=&SurfBuf[0];
@@ -2440,7 +2537,7 @@ void drawscreenwin(void)
break; break;
default: default:
UnlockSurface(); UnlockSurface();
MessageBox (NULL, "Mode only available in 16 bit color", "DDRAW Error" , MB_ICONERROR ); MessageBox (NULL, "Mode only available in 16 and 32 bit color", "DDRAW Error" , MB_ICONERROR );
cvidmode=2; cvidmode=2;
initwinvideo(); initwinvideo();
Sleep(1000); Sleep(1000);
@@ -2453,6 +2550,7 @@ void drawscreenwin(void)
switch (BitDepth) switch (BitDepth)
{ {
case 16: case 16:
case 32: // using 16bpp AltSurface
AddEndBytes=pitch-1024; AddEndBytes=pitch-1024;
NumBytesPerLine=pitch; NumBytesPerLine=pitch;
WinVidMemStart=&SurfBuf[16*640*2+64*2]; WinVidMemStart=&SurfBuf[16*640*2+64*2];
@@ -2465,7 +2563,7 @@ void drawscreenwin(void)
break; break;
default: default:
UnlockSurface(); UnlockSurface();
MessageBox (NULL, "Mode only available in 16 bit color", "DDRAW Error" , MB_ICONERROR ); MessageBox (NULL, "Mode only available in 16 and 32 bit color", "DDRAW Error" , MB_ICONERROR );
cvidmode=2; cvidmode=2;
initwinvideo(); initwinvideo();
Sleep(1000); Sleep(1000);
@@ -2509,6 +2607,7 @@ void drawscreenwin(void)
} }
UnlockSurface(); UnlockSurface();
DrawScreen();
} }
extern void SwitchFullScreen(void); extern void SwitchFullScreen(void);