Overlay update

This commit is contained in:
pagefault
2001-06-15 04:42:56 +00:00
parent 307aec6fcd
commit 5d36f63367
4 changed files with 166 additions and 80 deletions

View File

@@ -176,6 +176,7 @@ EXTSYM numlockptr
%ifdef __WIN32__ %ifdef __WIN32__
EXTSYM CheckPriority EXTSYM CheckPriority
EXTSYM CheckAlwaysOnTop EXTSYM CheckAlwaysOnTop
EXTSYM initDirectDraw
%endif %endif
NEWSYM GuiAsmStart NEWSYM GuiAsmStart

View File

@@ -818,6 +818,13 @@ GUIOptionKeys:
xor byte[vsyncon],1 xor byte[vsyncon],1
mov al,[vsyncon] mov al,[vsyncon]
mov [cfgvsync],al mov [cfgvsync],al
%ifdef __WIN32__
cmp byte[OverlayEnabled],1
jne .novsync
pushad
call initDirectDraw
popad
%endif
.novsync .novsync
%endif %endif
cmp dh,'M' cmp dh,'M'
@@ -892,6 +899,9 @@ GUIOptionKeys:
cmp dh,'Y' cmp dh,'Y'
jne .nooverlay jne .nooverlay
xor byte[OverlayEnabled],1 xor byte[OverlayEnabled],1
pushad
call initDirectDraw
popad
.nooverlay .nooverlay
cmp dh,'S' cmp dh,'S'
jne .noalttimer jne .noalttimer

View File

@@ -994,6 +994,24 @@ GUIWinClicked:
%%noclick %%noclick
%endmacro %endmacro
%ifdef __WIN32__
%macro GUIClickCButtonov 3
cmp eax,%1+1
jl %%noclick
cmp edx,%2+3
jl %%noclick
cmp eax,%1+6
jg %%noclick
cmp edx,%2+8
jg %%noclick
xor %3,1
pushad
call initDirectDraw
popad
%%noclick
%endmacro
%endif
%macro GUIClickCButtonat 3 %macro GUIClickCButtonat 3
cmp eax,%1+1 cmp eax,%1+1
jl %%noclick jl %%noclick
@@ -1133,6 +1151,32 @@ GUIWinClicked:
%%noclick %%noclick
%endmacro %endmacro
%ifndef __LINUX__
%macro GUIClickCButton2ov 5
cmp eax,%1+1
jl %%noclick
cmp edx,%2+3
jl %%noclick
cmp eax,%1+6
jg %%noclick
cmp edx,%2+8
jg %%noclick
xor %3,%5
mov al,%3
mov %4,al
%ifdef __WIN32__
cmp byte[OverlayEnabled],1
jne %%noinit
pushad
call initDirectDraw
popad
%%noinit
%endif
ret
%%noclick
%endmacro
%endif
%macro GUIClickCButton3 5 %macro GUIClickCButton3 5
cmp eax,%1+1 cmp eax,%1+1
jl %%noclick jl %%noclick
@@ -2100,7 +2144,7 @@ DisplayGUIOptionClick:
GUIClickCButton2 11,36,byte[newengen],byte[cfgnewgfx],1 GUIClickCButton2 11,36,byte[newengen],byte[cfgnewgfx],1
.invalidng .invalidng
%ifndef __LINUX__ %ifndef __LINUX__
GUIClickCButton2 11,46,byte[vsyncon],byte[cfgvsync],1 GUIClickCButton2ov 11,46,byte[vsyncon],byte[cfgvsync],1
%endif %endif
GUIClickCButton2 11,56,byte[FPUCopy],byte[cfgcopymethod],2 GUIClickCButton2 11,56,byte[FPUCopy],byte[cfgcopymethod],2
GUIClickCButtonM 11,66,byte[pl12s34] GUIClickCButtonM 11,66,byte[pl12s34]
@@ -2120,7 +2164,7 @@ DisplayGUIOptionClick:
GUIClickCButton 11,156,byte[AutoState] GUIClickCButton 11,156,byte[AutoState]
GUIClickCButton 11,166,byte[DontSavePath] GUIClickCButton 11,166,byte[DontSavePath]
%ifdef __WIN32__ %ifdef __WIN32__
GUIClickCButton 11,176,byte[OverlayEnabled] GUIClickCButtonov 11,176,byte[OverlayEnabled]
GUIClickCButtonat 11,186,byte[AlternateTimer] GUIClickCButtonat 11,186,byte[AlternateTimer]
%endif %endif
; Frameskip = 0 ; Frameskip = 0

View File

@@ -15,8 +15,6 @@
//along with this program; if not, write to the Free Software //along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#define OVERLAY_SUPPORT
#define DIRECTINPUT_VERSION 0x0800 #define DIRECTINPUT_VERSION 0x0800
#define DIRECTSOUND_VERSION 0x0800 #define DIRECTSOUND_VERSION 0x0800
@@ -46,9 +44,9 @@ DWORD FirstSound=1;
int AllowDefault=0; int AllowDefault=0;
int SoundEnabled=1; int SoundEnabled=1;
#ifdef OVERLAY_SUPPORT DWORD Overlay = 0;
DWORD Overlay_failed = 0;
DWORD Overlay_Colorkey = 0; DWORD Overlay_Colorkey = 0;
#endif
DWORD FirstActivate = 1; DWORD FirstActivate = 1;
@@ -80,9 +78,7 @@ LPDIRECTDRAWSURFACE7 DD_Primary = NULL;
LPDIRECTDRAWSURFACE7 DD_CFB = NULL; LPDIRECTDRAWSURFACE7 DD_CFB = NULL;
LPDIRECTDRAWSURFACE7 DD_BackBuffer = NULL; LPDIRECTDRAWSURFACE7 DD_BackBuffer = NULL;
LPDIRECTDRAWCLIPPER lpDDClipper = NULL; LPDIRECTDRAWCLIPPER lpDDClipper = NULL;
#ifdef OVERLAY_SUPPORT
DDOVERLAYFX ddofx; DDOVERLAYFX ddofx;
#endif
RECT rcWindow; RECT rcWindow;
LPDIRECTINPUT8 DInput = NULL; LPDIRECTINPUT8 DInput = NULL;
@@ -154,6 +150,11 @@ extern "C"
void drawscreenwin(void); void drawscreenwin(void);
DWORD LastUsedPos=0; DWORD LastUsedPos=0;
DWORD CurMode=-1; DWORD CurMode=-1;
void initDirectDraw()
{
InitDirectDraw();
}
} }
void DDrawError(){ void DDrawError(){
@@ -165,18 +166,20 @@ void DDrawError(){
extern "C" BYTE vsyncon; extern "C" BYTE vsyncon;
extern "C" BYTE TripleBufferWin; extern "C" BYTE TripleBufferWin;
extern "C" BYTE OverlayEnabled;
void DrawScreen() typedef DWORD (__fastcall* lpLockSurface)();
DWORD __fastcall LockSurface_normal();
DWORD __fastcall LockSurface_overlay();
lpLockSurface LockSurface;
typedef void (__fastcall* lpUnlockSurface)();
void __fastcall UnlockSurface_normal();
void __fastcall UnlockSurface_overlay();
lpUnlockSurface UnlockSurface;
void DrawScreen_normal()
{ {
#ifdef OVERLAY_SUPPORT
if (vsyncon == 1)
{
if (DD_BackBuffer == NULL) InitDirectDraw();
DD_CFB->Flip(NULL,DDFLIP_WAIT);
}
else
if (DD_BackBuffer) InitDirectDraw();
#else
if (vsyncon == 1) if (vsyncon == 1)
{ {
if(FullScreen == 1) if(FullScreen == 1)
@@ -212,7 +215,12 @@ void DrawScreen()
DD_Primary->Blt(&rcWindow, DD_CFB, NULL, DDBLT_WAIT, NULL); DD_Primary->Blt(&rcWindow, DD_CFB, NULL, DDBLT_WAIT, NULL);
} }
} }
#endif }
void DrawScreen_overlay()
{
if (vsyncon == 1)
DD_CFB->Flip(NULL,DDFLIP_WAIT);
} }
DWORD InputEn=0; DWORD InputEn=0;
@@ -275,6 +283,7 @@ extern "C" void CheckAlwaysOnTop()
extern "C" void MinimizeWindow() extern "C" void MinimizeWindow()
{ {
if (Overlay && (DD_CFB)) DD_CFB->UpdateOverlay(NULL, DD_Primary, NULL, DDOVER_HIDE, NULL);
ShowWindow(hMainWindow, SW_MINIMIZE); ShowWindow(hMainWindow, SW_MINIMIZE);
IsActivated = 0; IsActivated = 0;
} }
@@ -454,7 +463,8 @@ LRESULT CALLBACK Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case WM_MOVE: case WM_MOVE:
break; break;
case WM_PAINT: case WM_PAINT:
#ifdef OVERLAY_SUPPORT if (Overlay && Overlay_Colorkey && (DD_Primary))
{
HDC hdc; HDC hdc;
POINT pt; POINT pt;
RECT rc1; RECT rc1;
@@ -474,9 +484,9 @@ LRESULT CALLBACK Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
DDBLT_WAIT, &ddbfx); DDBLT_WAIT, &ddbfx);
EndPaint(hWnd, &ps); EndPaint(hWnd, &ps);
#else }
else
ValidateRect(hWnd,NULL); ValidateRect(hWnd,NULL);
#endif
break; break;
case WM_ACTIVATE: case WM_ACTIVATE:
if (LOWORD(wParam) != WA_INACTIVE) if (LOWORD(wParam) != WA_INACTIVE)
@@ -484,11 +494,10 @@ LRESULT CALLBACK Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
IsActivated = 1; IsActivated = 1;
if(FirstActivate == 0) if(FirstActivate == 0)
{ {
#ifdef OVERLAY_SUPPORT if (Overlay == 1)
ShowWindow(hMainWindow, SW_SHOWNORMAL); ShowWindow(hMainWindow, SW_SHOWNORMAL);
#endif
initwinvideo(); initwinvideo();
#ifdef OVERLAY_SUPPORT if (Overlay == 1)
{ {
HRESULT hr; HRESULT hr;
RECT rc1; RECT rc1;
@@ -519,8 +528,8 @@ LRESULT CALLBACK Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
sprintf(err,"IDirectDrawSurface7::UpdateOverlay failed: 0x%x", hr); sprintf(err,"IDirectDrawSurface7::UpdateOverlay failed: 0x%x", hr);
MessageBox(NULL, err, "DirectDraw Error", MB_ICONERROR); MessageBox(NULL, err, "DirectDraw Error", MB_ICONERROR);
} }
} }
#endif
} }
InputAcquire(); InputAcquire();
if (FirstActivate == 1) FirstActivate = 0; if (FirstActivate == 1) FirstActivate = 0;
@@ -1221,21 +1230,20 @@ int InitDirectDraw()
} }
#ifdef OVERLAY_SUPPORT if (OverlayEnabled == 1 && !Overlay_failed)
{
ddcaps.dwSize = sizeof(DDCAPS); ddcaps.dwSize = sizeof(DDCAPS);
if(lpDD->GetCaps(&ddcaps, NULL) != DD_OK) if(lpDD->GetCaps(&ddcaps, NULL) != DD_OK)
{ {
MessageBox(NULL, "IDirectDraw7::GetCaps failed.", "DirectDraw Error", MB_ICONERROR); MessageBox(NULL, "IDirectDraw7::GetCaps failed.", "DirectDraw Error", MB_ICONERROR);
} }
if ((ddcaps.dwCaps & DDCAPS_OVERLAY) == 0 || if ((ddcaps.dwCaps & DDCAPS_OVERLAY) &&
(ddcaps.dwCaps & DDCAPS_OVERLAYSTRETCH) == 0) (ddcaps.dwCaps & DDCAPS_OVERLAYSTRETCH))
{ Overlay = 1;
MessageBox(NULL, "Sorry, no support for overlays.", "DirectDraw Error", MB_ICONERROR);
exit(0);
}
if (ddcaps.dwCaps & DDCAPS_COLORKEY) if (ddcaps.dwCaps & DDCAPS_COLORKEY)
Overlay_Colorkey = 1; Overlay_Colorkey = 1;
#endif }
else Overlay = 0;
if(FullScreen == 1) if(FullScreen == 1)
{ {
@@ -1257,27 +1265,26 @@ int InitDirectDraw()
CheckAlwaysOnTop(); CheckAlwaysOnTop();
} }
overlay_failed:
ZeroMemory(&ddsd2, sizeof(DDSURFACEDESC2)); ZeroMemory(&ddsd2, sizeof(DDSURFACEDESC2));
ddsd2.dwSize = sizeof(DDSURFACEDESC2); ddsd2.dwSize = sizeof(DDSURFACEDESC2);
ddsd2.dwFlags = DDSD_CAPS; ddsd2.dwFlags = DDSD_CAPS;
ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
#ifndef OVERLAY_SUPPORT if(!Overlay && FullScreen == 1)
if(FullScreen == 1)
{ {
ddsd2.dwFlags |= DDSD_BACKBUFFERCOUNT; ddsd2.dwFlags |= DDSD_BACKBUFFERCOUNT;
ddsd2.dwBackBufferCount = 2; ddsd2.dwBackBufferCount = 2;
ddsd2.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd2.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_COMPLEX;
} }
#endif
if (lpDD->CreateSurface( &ddsd2, &DD_Primary, NULL) != DD_OK) if (lpDD->CreateSurface( &ddsd2, &DD_Primary, NULL) != DD_OK)
{ {
MessageBox(NULL, "IDirectDraw7::CreateSurface failed.", "DirectDraw Error", MB_ICONERROR); MessageBox(NULL, "IDirectDraw7::CreateSurface failed.", "DirectDraw Error", MB_ICONERROR);
} }
#ifndef OVERLAY_SUPPORT if(!Overlay && FullScreen == 1)
if(FullScreen == 1)
{ {
ddsd2.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER; ddsd2.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
if (DD_Primary->GetAttachedSurface(&ddsd2.ddsCaps, &DD_BackBuffer) != DD_OK) if (DD_Primary->GetAttachedSurface(&ddsd2.ddsCaps, &DD_BackBuffer) != DD_OK)
@@ -1285,7 +1292,6 @@ int InitDirectDraw()
MessageBox(NULL, "IDirectDrawSurface7::GetAttachedSurface failed.", "DirectDraw Error", MB_ICONERROR); MessageBox(NULL, "IDirectDrawSurface7::GetAttachedSurface failed.", "DirectDraw Error", MB_ICONERROR);
} }
} }
#endif
if(FullScreen == 0) if(FullScreen == 0)
{ {
if (lpDD->CreateClipper(0,&lpDDClipper,NULL) != DD_OK) if (lpDD->CreateClipper(0,&lpDDClipper,NULL) != DD_OK)
@@ -1318,13 +1324,11 @@ int InitDirectDraw()
BitDepth=format.dwRGBBitCount; BitDepth=format.dwRGBBitCount;
GBitMask=format.dwGBitMask; // 0x07E0 or not GBitMask=format.dwGBitMask; // 0x07E0 or not
#ifndef OVERLAY_SUPPORT if (BitDepth==24 && Overlay==0)
if (BitDepth==24)
{ {
MessageBox(NULL,"ZSNESw does not support 24bit color.\nPlease change your resolution to either 16bit or 32bit color","Error",MB_OK); MessageBox(NULL,"ZSNESw does not support 24bit color.\nPlease change your resolution to either 16bit or 32bit color","Error",MB_OK);
exit(0); exit(0);
} }
#endif
converta = (BitDepth==16 && GBitMask!=0x07E0); converta = (BitDepth==16 && GBitMask!=0x07E0);
@@ -1332,9 +1336,8 @@ int InitDirectDraw()
ddsd2.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; ddsd2.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
ddsd2.dwWidth = SurfaceX; ddsd2.dwWidth = SurfaceX;
ddsd2.dwHeight = SurfaceY; ddsd2.dwHeight = SurfaceY;
if (Overlay)
#ifdef OVERLAY_SUPPORT {
DWORD flags = DDOVER_SHOW, ddofx_ptr = NULL; DWORD flags = DDOVER_SHOW, ddofx_ptr = NULL;
ddsd2.ddsCaps.dwCaps = DDSCAPS_OVERLAY; ddsd2.ddsCaps.dwCaps = DDSCAPS_OVERLAY;
@@ -1397,8 +1400,10 @@ int InitDirectDraw()
{ {
DD_Primary->Release(); DD_Primary->Release();
MessageBox(NULL,"Sorry, no overlay hardware available.", "DirectDraw Error", MB_ICONERROR); Overlay = 0;
exit(0); Overlay_failed = 1;
OverlayEnabled = 0;
goto overlay_failed;
} }
if ( hr != DD_OK ) if ( hr != DD_OK )
@@ -1472,7 +1477,12 @@ overlay_nocolorkey:
DD_Primary->Blt(&rc1, NULL, &rc1, DDBLT_COLORFILL | DDBLT_WAIT, &ddbfx); DD_Primary->Blt(&rc1, NULL, &rc1, DDBLT_COLORFILL | DDBLT_WAIT, &ddbfx);
} }
#else
LockSurface = (lpLockSurface) &LockSurface_overlay;
UnlockSurface = (lpUnlockSurface) &UnlockSurface_overlay;
}
else
{
ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
@@ -1481,15 +1491,32 @@ overlay_nocolorkey:
{ {
MessageBox(NULL, "IDirectDraw7::CreateSurface failed.", "DirectDraw Error", MB_ICONERROR); MessageBox(NULL, "IDirectDraw7::CreateSurface failed.", "DirectDraw Error", MB_ICONERROR);
} }
#endif LockSurface = (lpLockSurface) &LockSurface_normal;
UnlockSurface = (lpUnlockSurface) &UnlockSurface_normal;
}
return TRUE; return TRUE;
} }
BYTE* SurfBuf; BYTE* SurfBuf;
DDSURFACEDESC2 ddsd; DDSURFACEDESC2 ddsd;
DWORD LockSurface() DWORD __fastcall LockSurface_normal()
{
if (DD_CFB == NULL) return(0);
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof( ddsd );
ddsd.dwFlags = DDSD_LPSURFACE | DDSD_PITCH;
if (DD_CFB->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL) != DD_OK)
{
return(0);
}
SurfBuf = (BYTE*)ddsd.lpSurface;
return(ddsd.lPitch);
}
DWORD __fastcall LockSurface_overlay()
{ {
HRESULT hr; HRESULT hr;
@@ -1499,11 +1526,9 @@ DWORD LockSurface()
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;
#ifdef OVERLAY_SUPPORT if (DD_BackBuffer)
if (vsyncon == 1 && (DD_BackBuffer))
hr=DD_BackBuffer->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL); hr=DD_BackBuffer->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL);
else else
#endif
hr=DD_CFB->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL); hr=DD_CFB->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL);
if (hr != DD_OK) if (hr != DD_OK)
@@ -1515,15 +1540,19 @@ DWORD LockSurface()
return(ddsd.lPitch); return(ddsd.lPitch);
} }
void UnlockSurface() void __fastcall UnlockSurface_normal()
{ {
#ifdef OVERLAY_SUPPORT DD_CFB->Unlock((struct tagRECT *)ddsd.lpSurface);
if (vsyncon == 1 && (DD_BackBuffer)) DrawScreen_normal();
}
void __fastcall UnlockSurface_overlay()
{
if (DD_BackBuffer)
DD_BackBuffer->Unlock((struct tagRECT *)ddsd.lpSurface); DD_BackBuffer->Unlock((struct tagRECT *)ddsd.lpSurface);
else else
#endif
DD_CFB->Unlock((struct tagRECT *)ddsd.lpSurface); DD_CFB->Unlock((struct tagRECT *)ddsd.lpSurface);
DrawScreen(); DrawScreen_overlay();
} }
extern "C" { extern "C" {
@@ -2768,12 +2797,14 @@ int GetMouseButton(void)
if (Y>(GetSystemMetrics( SM_CYSCREEN )-WindowHeight)) Y=(GetSystemMetrics( SM_CYSCREEN )-WindowHeight); if (Y>(GetSystemMetrics( SM_CYSCREEN )-WindowHeight)) Y=(GetSystemMetrics( SM_CYSCREEN )-WindowHeight);
InputRead(); InputRead();
initwinvideo(); initwinvideo();
if (Overlay && (DD_CFB)) DD_CFB->SetOverlayPosition(X, Y);
} }
} }
if (Moving==1) if (Moving==1)
{ {
Moving=0; Moving=0;
initwinvideo(); initwinvideo();
if (Overlay && (DD_CFB)) DD_CFB->SetOverlayPosition(X, Y);
} }
return((int)MouseButton); return((int)MouseButton);
} }