From e09cd217031ed8385f520b61104a4b148c2f5c2f Mon Sep 17 00:00:00 2001 From: tomcw Date: Sun, 25 Aug 2019 17:07:08 +0100 Subject: [PATCH] Added experiment code for DirectDraw & WaitForVerticalBlank() - #680 --- source/Applewin.cpp | 4 +++ source/Video.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++++ source/Video.h | 3 ++ 3 files changed, 78 insertions(+) diff --git a/source/Applewin.cpp b/source/Applewin.cpp index 6a988215..9daac865 100644 --- a/source/Applewin.cpp +++ b/source/Applewin.cpp @@ -1539,6 +1539,9 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) LogFileOutput("Init: SysClk_InitTimer(), res=%d\n", bSpeechOK ? 1:0); } #endif +#if 0 + DDInit(); // For WaitForVerticalBlank() +#endif // DO ONE-TIME INITIALIZATION g_hInstance = passinstance; @@ -1786,6 +1789,7 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) ChangeDisplaySettings(NULL, 0); // restore default // Release COM + DDUninit(); SysClk_UninitTimer(); LogFileOutput("Exit: SysClk_UninitTimer()\n"); diff --git a/source/Video.cpp b/source/Video.cpp index 3999cd58..4e726de0 100644 --- a/source/Video.cpp +++ b/source/Video.cpp @@ -33,6 +33,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "Disk.h" // DiskUpdateDriveState() #include "Frame.h" #include "Keyboard.h" +#include "Log.h" #include "Memory.h" #include "Registry.h" #include "Video.h" @@ -93,6 +94,8 @@ static VideoStyle_e g_eVideoStyle = VS_HALF_SCANLINES; static bool g_bVideoScannerNTSC = true; // NTSC video scanning (or PAL) +static LPDIRECTDRAW g_lpDD = NULL; + //------------------------------------- // NOTE: KEEP IN SYNC: VideoType_e g_aVideoChoices g_apVideoModeDesc @@ -591,6 +594,7 @@ void VideoRefreshScreen ( uint32_t uRedrawWholeScreenVideoMode /* =0*/, bool bRe SRCCOPY); } + //if (g_lpDD) g_lpDD->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL); GdiFlush(); } @@ -877,6 +881,73 @@ bool VideoGetVblBar(const DWORD uExecutedCycles) //=========================================================================== +#define MAX_DRAW_DEVICES 10 + +static char *draw_devices[MAX_DRAW_DEVICES]; +static GUID draw_device_guid[MAX_DRAW_DEVICES]; +static int num_draw_devices = 0; + +static BOOL CALLBACK DDEnumProc(LPGUID lpGUID, LPCTSTR lpszDesc, LPCTSTR lpszDrvName, LPVOID lpContext) +{ + int i = num_draw_devices; + if (i == MAX_DRAW_DEVICES) + return TRUE; + if (lpGUID != NULL) + memcpy(&draw_device_guid[i], lpGUID, sizeof (GUID)); + draw_devices[i] = _strdup(lpszDesc); + + if (g_fh) fprintf(g_fh, "%d: %s - %s\n",i,lpszDesc,lpszDrvName); + + num_draw_devices++; + return TRUE; +} + +bool DDInit(void) +{ + HRESULT hr = DirectDrawEnumerate((LPDDENUMCALLBACK)DDEnumProc, NULL); + if (FAILED(hr)) + { + LogFileOutput("DSEnumerate failed (%08X)\n", hr); + return false; + } + + LogFileOutput("Number of draw devices = %d\n", num_draw_devices); + + bool bCreatedOK = false; + for (int x=0; xRelease(); (p)=NULL; } } + +void DDUninit(void) +{ + SAFE_RELEASE(g_lpDD); +} + +#undef SAFE_RELEASE + +//=========================================================================== + #define SCREENSHOT_BMP 1 #define SCREENSHOT_TGA 0 diff --git a/source/Video.h b/source/Video.h index 693e7dc7..197ac278 100644 --- a/source/Video.h +++ b/source/Video.h @@ -236,3 +236,6 @@ bool IsVideoStyle(VideoStyle_e mask); VideoRefreshRate_e GetVideoRefreshRate(void); void SetVideoRefreshRate(VideoRefreshRate_e rate); + +bool DDInit(void); +void DDUninit(void);