diff --git a/zsnes/src/win/winlink.cpp b/zsnes/src/win/winlink.cpp index ffc5e6c5..2d45e1fd 100644 --- a/zsnes/src/win/winlink.cpp +++ b/zsnes/src/win/winlink.cpp @@ -15,8 +15,6 @@ //along with this program; if not, write to the Free Software //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -//#define OVERLAY_SUPPORT - #define DIRECTINPUT_VERSION 0x0800 #define DIRECTSOUND_VERSION 0x0800 @@ -46,10 +44,6 @@ DWORD FirstSound=1; int AllowDefault=0; int SoundEnabled=1; -#ifdef OVERLAY_SUPPORT -DWORD Overlay_Colorkey = 0; -#endif - DWORD FirstActivate = 1; #define BYTE unsigned char @@ -80,9 +74,6 @@ LPDIRECTDRAWSURFACE7 DD_Primary = NULL; LPDIRECTDRAWSURFACE7 DD_CFB = NULL; LPDIRECTDRAWSURFACE7 DD_BackBuffer = NULL; LPDIRECTDRAWCLIPPER lpDDClipper = NULL; -#ifdef OVERLAY_SUPPORT -DDOVERLAYFX ddofx; -#endif RECT rcWindow; LPDIRECTINPUT8 DInput = NULL; @@ -144,7 +135,6 @@ DWORD MouseButton; _int64 start, end, freq, update_ticks_pc, start2, end2, update_ticks_pc2; -int InitDirectDraw(); void ReleaseDirectDraw(); void ReleaseDirectSound(); void ReleaseDirectInput(); @@ -168,51 +158,36 @@ extern "C" BYTE TripleBufferWin; void DrawScreen() { -#ifdef OVERLAY_SUPPORT - if (vsyncon == 1) + if (FullScreen == 1) { - if (DD_BackBuffer == NULL) InitDirectDraw(); - DD_CFB->Flip(NULL,DDFLIP_WAIT); - } - else - if (DD_BackBuffer) InitDirectDraw(); -#else - if (vsyncon == 1) - { - if(FullScreen == 1) + if (TripleBufferWin == 1) { - if(TripleBufferWin == 1) - { - DD_BackBuffer->Blt(NULL, DD_CFB, NULL, DDBLT_WAIT, NULL); - DD_Primary->Flip(NULL, DDFLIP_WAIT); - } - else - { - DD_Primary->Blt(&rcWindow, DD_CFB, NULL, DDBLT_WAIT, NULL); - } + DD_BackBuffer->Blt(NULL, DD_CFB, NULL, DDBLT_WAIT, NULL); + DD_Primary->Flip(NULL, DDFLIP_WAIT); } else + { + if (vsyncon == 1) + { + if (lpDD->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL) != DD_OK) + { + DDrawError(); + } + } + DD_Primary->Blt(&rcWindow, DD_CFB, NULL, DDBLT_WAIT, NULL); + } + } + else + { + if (vsyncon == 1) { if (lpDD->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL) != DD_OK) { DDrawError(); } + } DD_Primary->Blt(&rcWindow, DD_CFB, NULL, DDBLT_WAIT, NULL); - } } - else - { - if (FullScreen == 1 && TripleBufferWin == 1) - { - DD_BackBuffer->Blt(NULL, DD_CFB, NULL, DDBLT_WAIT, NULL); - DD_Primary->Flip(NULL, DDFLIP_NOVSYNC); - } - else - { - DD_Primary->Blt(&rcWindow, DD_CFB, NULL, DDBLT_WAIT, NULL); - } - } -#endif } DWORD InputEn=0; @@ -223,6 +198,7 @@ InputAcquire(void) if (JoystickInput[1]) JoystickInput[1]->Acquire(); if (JoystickInput[2]) JoystickInput[2]->Acquire(); if (JoystickInput[3]) JoystickInput[3]->Acquire(); + if (JoystickInput[4]) JoystickInput[4]->Acquire(); if (MouseInput) MouseInput->Acquire(); if (KeyboardInput) KeyboardInput->Acquire(); InputEn=1; @@ -237,6 +213,7 @@ BOOL InputDeAcquire(void) if (JoystickInput[1]) JoystickInput[1]->Unacquire(); if (JoystickInput[2]) JoystickInput[2]->Unacquire(); if (JoystickInput[3]) JoystickInput[3]->Unacquire(); + if (JoystickInput[4]) JoystickInput[4]->Unacquire(); InputEn=0; return TRUE; } @@ -454,78 +431,17 @@ LRESULT CALLBACK Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_MOVE: break; case WM_PAINT: -#ifdef OVERLAY_SUPPORT - HDC hdc; - POINT pt; - RECT rc1; - struct tagPAINTSTRUCT ps; - DDBLTFX ddbfx; - - hdc = BeginPaint(hWnd, &ps); - - rc1 = ps.rcPaint; - ClientToScreen(hMainWindow, ( LPPOINT )&rc1 ); - ClientToScreen(hMainWindow, ( LPPOINT )&rc1 + 1 ); - - ddbfx.dwSize = sizeof(DDBLTFX); - ddbfx.dwFillColor = Overlay_Colorkey; - - DD_Primary->Blt(&rc1, NULL, &rc1, DDBLT_COLORFILL | - DDBLT_WAIT, &ddbfx); - - EndPaint(hWnd, &ps); -#else ValidateRect(hWnd,NULL); -#endif break; - case WM_ACTIVATE: + case WM_ACTIVATE: if (LOWORD(wParam) != WA_INACTIVE) { IsActivated = 1; - if(FirstActivate == 0) - { -#ifdef OVERLAY_SUPPORT - ShowWindow(hMainWindow, SW_SHOWNORMAL); -#endif - initwinvideo(); -#ifdef OVERLAY_SUPPORT - { - HRESULT hr; - RECT rc1; - DWORD flags = DDOVER_SHOW, ddofx_ptr = NULL; - if (FullScreen == 1) - SetRect(&rc1, 0, 0, WindowWidth, WindowHeight); - else - { - GetClientRect( hMainWindow, &rc1 ); - ClientToScreen( hMainWindow, ( LPPOINT )&rc1 ); - ClientToScreen( hMainWindow, ( LPPOINT )&rc1 + 1 ); - } - - if (Overlay_Colorkey) - { - ddofx.dwSize = sizeof(DDOVERLAYFX); - ddofx.dckDestColorkey.dwColorSpaceLowValue = Overlay_Colorkey; - ddofx.dckDestColorkey.dwColorSpaceHighValue = Overlay_Colorkey; - - flags |= DDOVER_KEYDESTOVERRIDE; - ddofx_ptr = (DWORD) &ddofx; - } - - if ( (hr=DD_CFB->UpdateOverlay(NULL, DD_Primary, - &rc1, flags, (DDOVERLAYFX *)ddofx_ptr)) != DD_OK) - { - char err[256]; - sprintf(err,"IDirectDrawSurface7::UpdateOverlay failed: 0x%x", hr); - MessageBox(NULL, err, "DirectDraw Error", MB_ICONERROR); - } - } -#endif - } + if (FirstActivate == 0) initwinvideo(); InputAcquire(); if (FirstActivate == 1) FirstActivate = 0; } - else IsActivated = 0; + if (LOWORD(wParam) == WA_INACTIVE) IsActivated = 0; break; case WM_SETFOCUS: if (FullScreen == 0) ShowWindow(hMainWindow, SW_SHOWNORMAL); @@ -1175,33 +1091,24 @@ void TestJoy() extern "C" DWORD converta; extern "C" unsigned int BitConv32Ptr; -DWORD madeBitConv = 0; int InitDirectDraw() { DDSURFACEDESC2 ddsd2; DDPIXELFORMAT format; - DDBLTFX ddbfx; - DDCAPS ddcaps; - DDSCAPS2 ddscaps; - RECT rc1; HRESULT hr; char message1[256]; unsigned int color32,ScreenPtr2; int i; - if (!madeBitConv) + ScreenPtr2=BitConv32Ptr; + for(i=0;i<65536;i++) { - ScreenPtr2=BitConv32Ptr; - for(i=0;i<65536;i++) - { - color32=((i&0xF800)<<8)+ - ((i&0x07E0)<<5)+ - ((i&0x001F)<<3)+0xFF000000; - (*(unsigned int *)(ScreenPtr2))=color32; - ScreenPtr2+=4; - } - madeBitConv = 1; + color32=((i&0xF800)<<8)+ + ((i&0x07E0)<<5)+ + ((i&0x001F)<<3)+0xFF000000; + (*(unsigned int *)(ScreenPtr2))=color32; + ScreenPtr2+=4; } if (!hMainWindow) @@ -1220,26 +1127,9 @@ int InitDirectDraw() MessageBox(NULL, "DirectDrawCreateEx failed.", "DirectDraw Error", MB_ICONERROR); } - -#ifdef OVERLAY_SUPPORT - ddcaps.dwSize = sizeof(DDCAPS); - if(lpDD->GetCaps(&ddcaps, NULL) != DD_OK) + if (FullScreen == 1) { - MessageBox(NULL, "IDirectDraw7::GetCaps failed.", "DirectDraw Error", MB_ICONERROR); - } - if ((ddcaps.dwCaps & DDCAPS_OVERLAY) == 0 || - (ddcaps.dwCaps & DDCAPS_OVERLAYSTRETCH) == 0) - { - MessageBox(NULL, "Sorry, no support for overlays.", "DirectDraw Error", MB_ICONERROR); - exit(0); - } - if (ddcaps.dwCaps & DDCAPS_COLORKEY) - Overlay_Colorkey = 1; -#endif - - if(FullScreen == 1) - { - if(lpDD->SetCooperativeLevel(hMainWindow, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT) != DD_OK) + if (lpDD->SetCooperativeLevel(hMainWindow, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT) != DD_OK) { MessageBox(NULL, "IDirectDraw7::SetCooperativeLevel failed.", "DirectDraw Error", MB_ICONERROR); } @@ -1261,23 +1151,20 @@ int InitDirectDraw() ddsd2.dwSize = sizeof(DDSURFACEDESC2); ddsd2.dwFlags = DDSD_CAPS; ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - -#ifndef OVERLAY_SUPPORT - if(FullScreen == 1) + + if (FullScreen == 1) { ddsd2.dwFlags |= DDSD_BACKBUFFERCOUNT; ddsd2.dwBackBufferCount = 2; ddsd2.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_COMPLEX; } -#endif if (lpDD->CreateSurface( &ddsd2, &DD_Primary, NULL) != DD_OK) { MessageBox(NULL, "IDirectDraw7::CreateSurface failed.", "DirectDraw Error", MB_ICONERROR); } -#ifndef OVERLAY_SUPPORT - if(FullScreen == 1) + if (FullScreen == 1) { ddsd2.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER; if (DD_Primary->GetAttachedSurface(&ddsd2.ddsCaps, &DD_BackBuffer) != DD_OK) @@ -1285,8 +1172,7 @@ int InitDirectDraw() MessageBox(NULL, "IDirectDrawSurface7::GetAttachedSurface failed.", "DirectDraw Error", MB_ICONERROR); } } -#endif - if(FullScreen == 0) + else { if (lpDD->CreateClipper(0,&lpDDClipper,NULL) != DD_OK) { @@ -1318,170 +1204,25 @@ int InitDirectDraw() BitDepth=format.dwRGBBitCount; GBitMask=format.dwGBitMask; // 0x07E0 or not -#ifndef OVERLAY_SUPPORT if (BitDepth==24) { MessageBox(NULL,"ZSNESw does not support 24bit color.\nPlease change your resolution to either 16bit or 32bit color","Error",MB_OK); exit(0); } -#endif converta = (BitDepth==16 && GBitMask!=0x07E0); - ddsd2.dwSize = sizeof(DDSURFACEDESC2); + ddsd2.dwSize = sizeof(ddsd2); ddsd2.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; + ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd2.dwWidth = SurfaceX; ddsd2.dwHeight = SurfaceY; -#ifdef OVERLAY_SUPPORT - - DWORD flags = DDOVER_SHOW, ddofx_ptr = NULL; - - ddsd2.ddsCaps.dwCaps = DDSCAPS_OVERLAY; - ddsd2.dwFlags |= DDSD_PIXELFORMAT; - if (vsyncon == 1) - { - ddsd2.dwFlags |= DDSD_BACKBUFFERCOUNT; - ddsd2.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_COMPLEX; - ddsd2.dwBackBufferCount = 1; - } - else DD_BackBuffer = NULL; - - if (Overlay_Colorkey) - switch (GBitMask) - { - case 0xff00: - Overlay_Colorkey = 0x22ee22; - break; - case 0x7e0: - Overlay_Colorkey = 0x27e4; - break; - case 0x3e0: - Overlay_Colorkey = 0x13e4; - break; - } - -// force overlay to 16bpp, 5-6-5... only works on supported hardware... -// if no 5-6-5 support, it's safe to assume the hardware doesn't support RGB -// overlays at all - -// At this time of writing (7:50pm PDT 2 June 2001) the following -// chipsets are known to support this feature: - -// Cirrus Logic CL-GD5465 "Laguna" - works in 16 and 32bpp modes -// ATI Rage II* - works, unknown desktop depth -// ATI Radeon* - works, tested in 32bpp mode, 16bpp mode assumed to work - -// While the following are known to NOT work with this mode: - -// NVidia GeForce 2 MX - fails in all desktop bit depths -// NVidia GeForce 2 GTS* - same as above - -// *Tested by 3rd parties only - - BitDepth = 16; - converta = 0; - - ZeroMemory(&ddsd2.ddpfPixelFormat, sizeof(DDPIXELFORMAT)); - - 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; - - hr=lpDD->CreateSurface( &ddsd2, &DD_CFB, NULL ); - - if ( hr == DDERR_NOOVERLAYHW ) - - { - DD_Primary->Release(); - MessageBox(NULL,"Sorry, no overlay hardware available.", "DirectDraw Error", MB_ICONERROR); - exit(0); - } - - if ( hr != DD_OK ) - { - char err[256]; - sprintf(err, "IDirectDrawSurface7::CreateSurface failed: 0x%x", hr); - MessageBox(NULL, err, "DirectDraw Error", MB_ICONERROR); - DD_CFB->Release(); - DD_CFB = NULL; - return FALSE; - } - - if (vsyncon == 1) - { - ZeroMemory(&ddscaps, sizeof(DDSCAPS2)); - ddscaps.dwCaps = DDSCAPS_BACKBUFFER; - if ( DD_CFB->GetAttachedSurface(&ddscaps, &DD_BackBuffer) != DD_OK ) - { - MessageBox(NULL, "IDirectDrawSurface7::GetAttachedSurface failed.", "DirectDraw Error", MB_ICONERROR); - DD_CFB->Release(); - DD_CFB = NULL; - DD_BackBuffer = NULL; - return FALSE; - } - } - if (FullScreen == 1) - SetRect(&rc1, 0, 0, WindowWidth, WindowHeight); - else - { - GetClientRect( hMainWindow, &rc1 ); - ClientToScreen( hMainWindow, ( LPPOINT )&rc1 ); - ClientToScreen( hMainWindow, ( LPPOINT )&rc1 + 1 ); - } - - if (Overlay_Colorkey) - { - ddofx.dwSize = sizeof(DDOVERLAYFX); - ddofx.dckDestColorkey.dwColorSpaceLowValue = Overlay_Colorkey; - ddofx.dckDestColorkey.dwColorSpaceHighValue = Overlay_Colorkey; - - flags |= DDOVER_KEYDESTOVERRIDE; - ddofx_ptr = (DWORD) &ddofx; - } - -overlay_nocolorkey: - - if ( (hr=DD_CFB->UpdateOverlay(NULL, DD_Primary, - &rc1, flags, (DDOVERLAYFX *)ddofx_ptr)) != DD_OK) - { - if (hr == DDERR_NOCOLORKEYHW) - { - Overlay_Colorkey = 0; - flags &= ~DDOVER_KEYDESTOVERRIDE; - ddofx_ptr = NULL; - goto overlay_nocolorkey; - } - char err[256]; - sprintf(err,"IDirectDrawSurface7::UpdateOverlay failed: 0x%x", hr); - MessageBox(NULL, err, "DirectDraw Error", MB_ICONERROR); - DD_CFB->Release(); - DD_CFB = NULL; - return FALSE; - } - - - if (Overlay_Colorkey) - { - ZeroMemory(&ddbfx, sizeof(DDBLTFX)); - ddbfx.dwSize = sizeof(DDBLTFX); - ddbfx.dwFillColor = Overlay_Colorkey; - - DD_Primary->Blt(&rc1, NULL, &rc1, DDBLT_COLORFILL | DDBLT_WAIT, &ddbfx); - } -#else - ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; - - // create drawing surface - if(lpDD->CreateSurface(&ddsd2, &DD_CFB, NULL) != DD_OK) - { - MessageBox(NULL, "IDirectDraw7::CreateSurface failed.", "DirectDraw Error", MB_ICONERROR); - } -#endif + if (lpDD->CreateSurface(&ddsd2, &DD_CFB, NULL) != DD_OK) + { + MessageBox(NULL, "IDirectDraw7::CreateSurface failed.", "DirectDraw Error", MB_ICONERROR); + } return TRUE; } @@ -1492,21 +1233,12 @@ DDSURFACEDESC2 ddsd; DWORD LockSurface() { - HRESULT hr; - if (DD_CFB == NULL) return(0); memset(&ddsd,0,sizeof(ddsd)); ddsd.dwSize = sizeof( ddsd ); ddsd.dwFlags = DDSD_LPSURFACE | DDSD_PITCH; -#ifdef OVERLAY_SUPPORT - if (vsyncon == 1 && (DD_BackBuffer)) - hr=DD_BackBuffer->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL); - else -#endif - hr=DD_CFB->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL); - - if (hr != DD_OK) + if (DD_CFB->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL) != DD_OK) { return(0); } @@ -1517,13 +1249,8 @@ DWORD LockSurface() void UnlockSurface() { -#ifdef OVERLAY_SUPPORT - if (vsyncon == 1 && (DD_BackBuffer)) - DD_BackBuffer->Unlock((struct tagRECT *)ddsd.lpSurface); - else -#endif - DD_CFB->Unlock((struct tagRECT *)ddsd.lpSurface); - DrawScreen(); + DD_CFB->Unlock((struct tagRECT *)ddsd.lpSurface); + DrawScreen(); } extern "C" { @@ -1938,8 +1665,6 @@ void CheckTimers(void) extern BYTE GUIOn2; -extern unsigned char FPUCopy; - void UpdateVFrame(void) { @@ -1986,61 +1711,13 @@ void UpdateVFrame(void) DSPBuffer1=(int *)&DSPBuffer; - int buffer_ptr = (int)&Buffer[0]; - - if (T36HZEnabled) - if (FPUCopy) - _asm - { - mov edi, buffer_ptr - mov ecx, SPCSize - shr ecx, 2 - pxor mm0,mm0 -_blank_top_fpu: - movq [edi],mm0 - add edi,8 - dec ecx - jne _blank_top_fpu - emms - } - else - _asm - { - mov edi, buffer_ptr - mov ecx, SPCSize - shr ecx, 1 - xor eax,eax -_blank_top: - mov [edi],eax - add edi,4 - dec ecx - jne _blank_top - } - else - if (FPUCopy) - _asm - { - mov esi, DSPBuffer1 - mov edi, buffer_ptr - mov ecx, SPCSize - shr ecx, 2 -_top_mmx: - movq mm0, [esi] - packssdw mm0, [esi+8] - movq [edi], mm0 - add esi, 16 - add edi, 8 - dec ecx - jne _top_mmx - emms - } - else - for(i=0;i32767)Buffer[i]=32767; - if (DSPBuffer1[i]<-32767)Buffer[i]=-32767; - } + for(i=0;i32767)Buffer[i]=32767; + if (DSPBuffer1[i]<-32767)Buffer[i]=-32767; + if (T36HZEnabled)Buffer[i]=0; + } if (DS_OK!=lpSoundBuffer->Lock(LastUsedPos, SPCSize*2, &lpvPtr1, @@ -2076,6 +1753,7 @@ extern DWORD AddEndBytes; extern DWORD NumBytesPerLine; extern unsigned char * WinVidMemStart; extern void copy640x480x16bwin(void); +extern unsigned char FPUCopy; extern unsigned char NGNoTransp; extern unsigned char newengen; @@ -2457,7 +2135,6 @@ void drawscreenwin(void) initwinvideo(); Sleep(1000); drawscreenwin(); -// exit(0); break; } } @@ -2484,7 +2161,6 @@ void drawscreenwin(void) initwinvideo(); Sleep(1000); drawscreenwin(); -// exit(0); } } @@ -2575,7 +2251,7 @@ void WinUpdateDevices() keys[0]=0; - for(i=0;i<4;i++) + for(i=0;i<5;i++) { if (JoystickInput[i]) { @@ -2586,10 +2262,10 @@ void WinUpdateDevices() JoystickInput[i]->Poll(); - if (IDirectInputDevice7_GetDeviceState(JoystickInput[i],sizeof(DIJOYSTATE), &js[i])==DIERR_INPUTLOST) + if (IDirectInputDevice8_GetDeviceState(JoystickInput[i],sizeof(DIJOYSTATE), &js[i])==DIERR_INPUTLOST) { if (JoystickInput[i]) JoystickInput[i]->Acquire(); - if (FAILED(IDirectInputDevice7_GetDeviceState(JoystickInput[i],sizeof(DIJOYSTATE), &js[i]))) return; + if (FAILED(IDirectInputDevice8_GetDeviceState(JoystickInput[i],sizeof(DIJOYSTATE), &js[i]))) return; } if (!X1Disable[i])