diff --git a/Makefile b/Makefile index 19245e6..2a0a627 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,8 @@ WINDRES=windres CFLAGS=-DHAVE_LIBPNG -Iinc -Wall -Wl,--enable-stdcall-fixup -O3 -s LIBS=lib/libpng14.a lib/libz.a -lgdi32 -lopengl32 -lwinmm -FILES = src/main.c \ +FILES = src/debug.c \ + src/main.c \ src/mouse.c \ src/palette.c \ src/surface.c \ diff --git a/inc/debug.h b/inc/debug.h new file mode 100644 index 0000000..eb961e9 --- /dev/null +++ b/inc/debug.h @@ -0,0 +1,24 @@ +#pragma once +#define WIN32_LEAN_AND_MEAN +#include +#include + +void DebugPrint(const char *format, ...); + +//#define _DEBUG 1 + +//use OutputDebugStringA rather than printf +//#define _DEBUGstring 1 + +//log everything (slow) +//#define _DEBUGx 1 + +#ifdef _DEBUG + +#ifdef _DEBUGstring +#define printf(format, ...) DebugPrint("xDBG " format, ##__VA_ARGS__) +#endif + +#else +#define printf(format, ...) +#endif diff --git a/inc/main.h b/inc/main.h index db555cb..4f65e1b 100644 --- a/inc/main.h +++ b/inc/main.h @@ -19,13 +19,10 @@ #include #include "ddraw.h" +#include "debug.h" #include #include -#ifndef _DEBUG -#define printf(format, ...) -#endif - struct IDirectDrawImpl; struct IDirectDrawImplVtbl; struct IDirectDrawSurfaceImpl; diff --git a/src/debug.c b/src/debug.c new file mode 100644 index 0000000..22c7bc8 --- /dev/null +++ b/src/debug.c @@ -0,0 +1,12 @@ +#define WIN32_LEAN_AND_MEAN +#include +#include + +void DebugPrint(const char *format, ...) +{ + va_list args; + va_start(args, format); + char buffer[512]; + _vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, format, args); + OutputDebugStringA(buffer); +} diff --git a/src/main.c b/src/main.c index dcb4513..0efcb6a 100644 --- a/src/main.c +++ b/src/main.c @@ -702,7 +702,7 @@ HRESULT __stdcall ddraw_SetCooperativeLevel(IDirectDrawImpl *This, HWND hWnd, DW HRESULT __stdcall ddraw_WaitForVerticalBlank(IDirectDrawImpl *This, DWORD a, HANDLE b) { -#if _DEBUG +#if _DEBUGx printf("DirectDraw::WaitForVerticalBlank(This=%p, ...)\n", This); #endif return DD_OK; @@ -819,7 +819,7 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk #if _DEBUG if(!stdout_open) { - freopen("stdout.txt", "w", stdout); + freopen("ra95stdout.txt", "w", stdout); setvbuf(stdout, NULL, _IONBF, 0); stdout_open = 1; } diff --git a/src/palette.c b/src/palette.c index d573476..6991403 100644 --- a/src/palette.c +++ b/src/palette.c @@ -42,7 +42,7 @@ HRESULT __stdcall ddraw_palette_SetEntries(IDirectDrawPaletteImpl *This, DWORD d { int i; -#if _DEBUG +#if _DEBUGx printf("DirectDrawPalette::SetEntries(This=%p, dwFlags=%d, dwStartingEntry=%d, dwCount=%d, lpEntries=%p)\n", This, (int)dwFlags, (int)dwStartingEntry, (int)dwCount, lpEntries); #endif diff --git a/src/render.c b/src/render.c index a176ce9..d564413 100644 --- a/src/render.c +++ b/src/render.c @@ -147,6 +147,19 @@ DWORD WINAPI render_main(void) while(ddraw->render.run && WaitForSingleObject(ddraw->render.sem, INFINITE) != WAIT_FAILED) { +#if _DEBUG + static DWORD tick_fps = 0; + static DWORD frame_count = 0; + tick_start = timeGetTime(); + if (tick_start >= tick_fps) + { + printf("Frames: %lu - Elapsed: %lu ms\n", frame_count, (tick_start - tick_fps) + 1000); + frame_count = 0; + tick_fps = tick_start + 1000; + } + frame_count++; +#endif + static int index = 0; scale_w = (float)ddraw->width/tex_width; scale_h = (float)ddraw->height/tex_height; diff --git a/src/render_soft.c b/src/render_soft.c index 5121381..0d12372 100644 --- a/src/render_soft.c +++ b/src/render_soft.c @@ -97,6 +97,19 @@ DWORD WINAPI render_soft_main(void) while (ddraw->render.run && WaitForSingleObject(ddraw->render.sem, INFINITE) != WAIT_FAILED) { +#if _DEBUG + static DWORD tick_fps = 0; + static DWORD frame_count = 0; + tick_start = timeGetTime(); + if (tick_start >= tick_fps) + { + printf("Frames: %lu - Elapsed: %lu ms\n", frame_count, (tick_start - tick_fps) + 1000); + frame_count = 0; + tick_fps = tick_start + 1000; + } + frame_count++; +#endif + if(ddraw->render.maxfps > 0) { tick_start = timeGetTime(); diff --git a/src/surface.c b/src/surface.c index 02090ed..c4ceb2a 100644 --- a/src/surface.c +++ b/src/surface.c @@ -81,7 +81,7 @@ HRESULT __stdcall ddraw_surface_Blt(IDirectDrawSurfaceImpl *This, LPRECT lpDestR { IDirectDrawSurfaceImpl *Source = (IDirectDrawSurfaceImpl *)lpDDSrcSurface; -#if _DEBUG +#if _DEBUGx printf("DirectDrawSurface::Blt(This=%p, lpDestRect=%p, lpDDSrcSurface=%p, lpSrcRect=%p, dwFlags=%d, lpDDBltFx=%p)\n", This, lpDestRect, lpDDSrcSurface, lpSrcRect, (int)dwFlags, lpDDBltFx); if(lpDestRect) { @@ -151,7 +151,7 @@ HRESULT __stdcall ddraw_surface_DeleteAttachedSurface(IDirectDrawSurfaceImpl *Th HRESULT __stdcall ddraw_surface_GetSurfaceDesc(IDirectDrawSurfaceImpl *This, LPDDSURFACEDESC lpDDSurfaceDesc) { -#if _DEBUG +#if _DEBUGx printf("IDirectDrawSurface::GetSurfaceDesc(This=%p, lpDDSurfaceDesc=%p)\n", This, lpDDSurfaceDesc); #endif @@ -197,7 +197,7 @@ HRESULT __stdcall ddraw_surface_EnumOverlayZOrders(IDirectDrawSurfaceImpl *This, HRESULT __stdcall ddraw_surface_Flip(IDirectDrawSurfaceImpl *This, LPDIRECTDRAWSURFACE a, DWORD b) { -#if _DEBUG +#if _DEBUGx printf("IDirectDrawSurface::Flip(This=%p, ...)\n", This); #endif @@ -219,7 +219,7 @@ HRESULT __stdcall ddraw_surface_GetAttachedSurface(IDirectDrawSurfaceImpl *This, HRESULT __stdcall ddraw_surface_GetBltStatus(IDirectDrawSurfaceImpl *This, DWORD a) { -#if _DEBUG +#if _DEBUGx printf("IDirectDrawSurface::GetBltStatus(This=%p, ...)\n", This); #endif return DD_OK; @@ -283,7 +283,7 @@ HRESULT __stdcall ddraw_surface_Initialize(IDirectDrawSurfaceImpl *This, LPDIREC HRESULT __stdcall ddraw_surface_IsLost(IDirectDrawSurfaceImpl *This) { -#if _DEBUG +#if _DEBUGx printf("IDirectDrawSurface::IsLost(This=%p)\n", This); #endif return DD_OK; @@ -291,7 +291,7 @@ HRESULT __stdcall ddraw_surface_IsLost(IDirectDrawSurfaceImpl *This) HRESULT __stdcall ddraw_surface_Lock(IDirectDrawSurfaceImpl *This, LPRECT lpDestRect, LPDDSURFACEDESC lpDDSurfaceDesc, DWORD dwFlags, HANDLE hEvent) { -#if _DEBUG +#if _DEBUGx printf("DirectDrawSurface::Lock(This=%p, lpDestRect=%p, lpDDSurfaceDesc=%p, dwFlags=%d, hEvent=%p)\n", This, lpDestRect, lpDDSurfaceDesc, (int)dwFlags, hEvent); if(dwFlags & DDLOCK_SURFACEMEMORYPTR) @@ -367,7 +367,7 @@ HRESULT __stdcall ddraw_surface_SetPalette(IDirectDrawSurfaceImpl *This, LPDIREC HRESULT __stdcall ddraw_surface_Unlock(IDirectDrawSurfaceImpl *This, LPVOID lpRect) { -#if _DEBUG +#if _DEBUGx printf("DirectDrawSurface::Unlock(This=%p, lpRect=%p)\n", This, lpRect); #endif