diff --git a/Source/dx.cpp b/Source/dx.cpp index 75c6220ed..a92b39612 100644 --- a/Source/dx.cpp +++ b/Source/dx.cpp @@ -18,91 +18,7 @@ char gbBackBuf; char gbEmulate; HMODULE ghDiabMod; -void dx_init(HWND hWnd) -{ - HRESULT hDDVal; - int winw, winh; - BOOL bSuccess; - GUID *lpGUID; - - /// ASSERT: assert(! gpBuffer); - /// ASSERT: assert(! sgdwLockCount); - /// ASSERT: assert(! sgpBackBuf); - - SetFocus(hWnd); - ShowWindow(hWnd, SW_SHOWNORMAL); - - lpGUID = NULL; - if (gbEmulate) { - lpGUID = (GUID *)DDCREATE_EMULATIONONLY; - } - hDDVal = dx_DirectDrawCreate(lpGUID, &lpDDInterface, NULL); - if (hDDVal != DD_OK) { - ErrDlg(IDD_DIALOG1, hDDVal, "C:\\Src\\Diablo\\Source\\dx.cpp", 149); - } - -#ifdef COLORFIX -#ifdef __DDRAWI_INCLUDED__ - ((LPDDRAWI_DIRECTDRAW_INT)lpDDInterface)->lpLcl->dwAppHackFlags |= 0x800; -#else - ((DWORD **)lpDDInterface)[1][18] |= 0x800; -#endif -#endif - -#ifndef _DEBUG - fullscreen = TRUE; -#endif - if (!fullscreen) { -#ifdef __cplusplus - hDDVal = lpDDInterface->SetCooperativeLevel(hWnd, DDSCL_NORMAL | DDSCL_ALLOWREBOOT); -#else - hDDVal = lpDDInterface->lpVtbl->SetCooperativeLevel(lpDDInterface, hWnd, DDSCL_NORMAL | DDSCL_ALLOWREBOOT); -#endif - if (hDDVal == DDERR_EXCLUSIVEMODEALREADYSET) { - TriggerBreak(); - } else if (hDDVal != DD_OK) { - ErrDlg(IDD_DIALOG1, hDDVal, "C:\\Diablo\\Direct\\dx.cpp", 155); - } - SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); - } else { -#ifdef __cplusplus - hDDVal = lpDDInterface->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT | DDSCL_FULLSCREEN); -#else - hDDVal = lpDDInterface->lpVtbl->SetCooperativeLevel(lpDDInterface, hWnd, DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT | DDSCL_FULLSCREEN); -#endif - if (hDDVal == DDERR_EXCLUSIVEMODEALREADYSET) { - TriggerBreak(); - } else if (hDDVal != DD_OK) { - ErrDlg(IDD_DIALOG1, hDDVal, "C:\\Src\\Diablo\\Source\\dx.cpp", 170); - } -#ifdef __cplusplus - hDDVal = lpDDInterface->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP); -#else - hDDVal = lpDDInterface->lpVtbl->SetDisplayMode(lpDDInterface, SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP); -#endif - if (hDDVal != DD_OK) { - winw = GetSystemMetrics(SM_CXSCREEN); - winh = GetSystemMetrics(SM_CYSCREEN); -#ifdef __cplusplus - hDDVal = lpDDInterface->SetDisplayMode(winw, winh, SCREEN_BPP); -#else - hDDVal = lpDDInterface->lpVtbl->SetDisplayMode(lpDDInterface, winw, winh, SCREEN_BPP); -#endif - } - if (hDDVal != DD_OK) { - ErrDlg(IDD_DIALOG1, hDDVal, "C:\\Src\\Diablo\\Source\\dx.cpp", 183); - } - } - - dx_create_primary_surface(); - palette_init(); - GdiSetBatchLimit(1); - dx_create_back_buffer(); - bSuccess = SDrawManualInitialize(hWnd, lpDDInterface, lpDDSPrimary, NULL, NULL, lpDDSBackBuf, lpDDPalette, NULL); - /// ASSERT: assert(bSuccess); -} - -void dx_create_back_buffer() +static void dx_create_back_buffer() { DDSCAPS caps; HRESULT error_code; @@ -160,7 +76,7 @@ void dx_create_back_buffer() ErrDlg(IDD_DIALOG1, error_code, "C:\\Src\\Diablo\\Source\\dx.cpp", 96); } -void dx_create_primary_surface() +static void dx_create_primary_surface() { DDSURFACEDESC ddsd; HRESULT error_code; @@ -178,7 +94,7 @@ void dx_create_primary_surface() ErrDlg(IDD_DIALOG1, error_code, "C:\\Src\\Diablo\\Source\\dx.cpp", 109); } -HRESULT dx_DirectDrawCreate(LPGUID guid, LPDIRECTDRAW *lplpDD, LPUNKNOWN pUnkOuter) +static HRESULT dx_DirectDrawCreate(LPGUID guid, LPDIRECTDRAW *lplpDD, LPUNKNOWN pUnkOuter) { HRESULT(WINAPI * DirectDrawCreate) (LPGUID lpGuid, LPDIRECTDRAW * lplpDD, LPUNKNOWN pUnkOuter); @@ -197,15 +113,91 @@ HRESULT dx_DirectDrawCreate(LPGUID guid, LPDIRECTDRAW *lplpDD, LPUNKNOWN pUnkOut return DirectDrawCreate(guid, lplpDD, pUnkOuter); } -void lock_buf(BYTE idx) +void dx_init(HWND hWnd) { -#ifdef _DEBUG - ++locktbl[idx]; + HRESULT hDDVal; + int winw, winh; + BOOL bSuccess; + GUID *lpGUID; + + /// ASSERT: assert(! gpBuffer); + /// ASSERT: assert(! sgdwLockCount); + /// ASSERT: assert(! sgpBackBuf); + + SetFocus(hWnd); + ShowWindow(hWnd, SW_SHOWNORMAL); + + lpGUID = NULL; + if (gbEmulate) { + lpGUID = (GUID *)DDCREATE_EMULATIONONLY; + } + hDDVal = dx_DirectDrawCreate(lpGUID, &lpDDInterface, NULL); + if (hDDVal != DD_OK) { + ErrDlg(IDD_DIALOG1, hDDVal, "C:\\Src\\Diablo\\Source\\dx.cpp", 149); + } + +#ifdef COLORFIX +#ifdef __DDRAWI_INCLUDED__ + ((LPDDRAWI_DIRECTDRAW_INT)lpDDInterface)->lpLcl->dwAppHackFlags |= 0x800; +#else + ((DWORD **)lpDDInterface)[1][18] |= 0x800; #endif - lock_buf_priv(); +#endif + +#ifndef _DEBUG + fullscreen = TRUE; +#endif + if (!fullscreen) { +#ifdef __cplusplus + hDDVal = lpDDInterface->SetCooperativeLevel(hWnd, DDSCL_NORMAL | DDSCL_ALLOWREBOOT); +#else + hDDVal = lpDDInterface->lpVtbl->SetCooperativeLevel(lpDDInterface, hWnd, DDSCL_NORMAL | DDSCL_ALLOWREBOOT); +#endif + if (hDDVal == DDERR_EXCLUSIVEMODEALREADYSET) { + TriggerBreak(); + } else if (hDDVal != DD_OK) { + ErrDlg(IDD_DIALOG1, hDDVal, "C:\\Diablo\\Direct\\dx.cpp", 155); + } + SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); + } else { +#ifdef __cplusplus + hDDVal = lpDDInterface->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT | DDSCL_FULLSCREEN); +#else + hDDVal = lpDDInterface->lpVtbl->SetCooperativeLevel(lpDDInterface, hWnd, DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT | DDSCL_FULLSCREEN); +#endif + if (hDDVal == DDERR_EXCLUSIVEMODEALREADYSET) { + TriggerBreak(); + } else if (hDDVal != DD_OK) { + ErrDlg(IDD_DIALOG1, hDDVal, "C:\\Src\\Diablo\\Source\\dx.cpp", 170); + } +#ifdef __cplusplus + hDDVal = lpDDInterface->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP); +#else + hDDVal = lpDDInterface->lpVtbl->SetDisplayMode(lpDDInterface, SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP); +#endif + if (hDDVal != DD_OK) { + winw = GetSystemMetrics(SM_CXSCREEN); + winh = GetSystemMetrics(SM_CYSCREEN); +#ifdef __cplusplus + hDDVal = lpDDInterface->SetDisplayMode(winw, winh, SCREEN_BPP); +#else + hDDVal = lpDDInterface->lpVtbl->SetDisplayMode(lpDDInterface, winw, winh, SCREEN_BPP); +#endif + } + if (hDDVal != DD_OK) { + ErrDlg(IDD_DIALOG1, hDDVal, "C:\\Src\\Diablo\\Source\\dx.cpp", 183); + } + } + + dx_create_primary_surface(); + palette_init(); + GdiSetBatchLimit(1); + dx_create_back_buffer(); + bSuccess = SDrawManualInitialize(hWnd, lpDDInterface, lpDDSPrimary, NULL, NULL, lpDDSBackBuf, lpDDPalette, NULL); + /// ASSERT: assert(bSuccess); } -void lock_buf_priv() +static void lock_buf_priv() { DDSURFACEDESC ddsd; HRESULT error_code; @@ -244,17 +236,15 @@ void lock_buf_priv() sgdwLockCount++; } -void unlock_buf(BYTE idx) +void lock_buf(BYTE idx) { #ifdef _DEBUG - if (!locktbl[idx]) - app_fatal("Draw lock underflow: 0x%x", idx); - --locktbl[idx]; + ++locktbl[idx]; #endif - unlock_buf_priv(); + lock_buf_priv(); } -void unlock_buf_priv() +static void unlock_buf_priv() { HRESULT error_code; @@ -282,6 +272,16 @@ void unlock_buf_priv() #endif } +void unlock_buf(BYTE idx) +{ +#ifdef _DEBUG + if (!locktbl[idx]) + app_fatal("Draw lock underflow: 0x%x", idx); + --locktbl[idx]; +#endif + unlock_buf_priv(); +} + void dx_cleanup() { if (ghMainWnd) @@ -359,3 +359,9 @@ void dx_reinit() sgMemCrit.Leave(); #endif } + +/* check extern remove stub */ +void j_dx_reinit() +{ + dx_reinit(); +} diff --git a/Source/dx.h b/Source/dx.h index 91344a85d..39c0fbef1 100644 --- a/Source/dx.h +++ b/Source/dx.h @@ -12,13 +12,8 @@ extern char gbEmulate; extern HMODULE ghDiabMod; void dx_init(HWND hWnd); -void dx_create_back_buffer(); -void dx_create_primary_surface(); -HRESULT dx_DirectDrawCreate(LPGUID guid, LPDIRECTDRAW *lplpDD, LPUNKNOWN pUnkOuter); void lock_buf(BYTE idx); -void lock_buf_priv(); void unlock_buf(BYTE idx); -void unlock_buf_priv(); void dx_cleanup(); void dx_reinit(); void j_dx_reinit(); diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 2e0a1ad6a..cae1da70b 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -2731,7 +2731,7 @@ static void DrawMain(int dwHgt, BOOL draw_desc, BOOL draw_hp, BOOL draw_mana, BO break; } retry = FALSE; - dx_reinit(); + j_dx_reinit(); ysize = SCREEN_HEIGHT; dwTicks = GetTickCount(); }