From dec0ed8ed52998ecea09ca3c771e7d5c951335ea Mon Sep 17 00:00:00 2001 From: n-a-c-h <> Date: Sat, 8 Jan 2005 21:23:43 +0000 Subject: [PATCH] Fixing timing with MinGW. Direct X failing now gives informative message. --- zsnes/src/makefile.ms | 9 +++--- zsnes/src/win/winlink.cpp | 58 +++++++++++++++++++-------------------- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/zsnes/src/makefile.ms b/zsnes/src/makefile.ms index 0cd50f83..b3e6a29f 100644 --- a/zsnes/src/makefile.ms +++ b/zsnes/src/makefile.ms @@ -25,7 +25,8 @@ DELETECOMMAND=rm SLASH=/ ASM=nasm ASMFLAGSORIG=-O1 -CFLAGSORIG=-O3 -march=i586 -ffast-math -fomit-frame-pointer -fno-unroll-loops -Wall -Wno-unused +CFLAGSORIG=-march=i586 -ffast-math -fomit-frame-pointer -fno-unroll-loops -Wall -Wno-unused +COPT=-O3 LIBSORIG=-lz -lpng ifeq ($(PLATFORM),) @@ -163,10 +164,10 @@ endif .SUFFIXES: .c .cpp .asm %.o: %.c - ${CC} ${CFLAGS} -o $@ -c $< + ${CC} ${COPT} ${CFLAGS} -o $@ -c $< %.o: %.cpp - ${CPPC} ${CFLAGS} -o $@ -c $< + ${CPPC} ${COPT} ${CFLAGS} -o $@ -c $< %.o: %.asm ${ASM} ${ASMFLAGS} -o $@ $< @@ -289,7 +290,7 @@ ${WINDIR}/ztcp.o: $< ${WINDIR}/zsnes.o: ${WINDIR}/zsnes.rc ${WINDRES} --include-dir ${WINDIR} ${WINDIR}/zsnes.rc -o${WINDIR}/zsnes.o ${WINDIR}/winlink.o: ${WINDIR}/winlink.cpp ${WINDIR}/resource.h - ${CPPC} ${CFLAGS} -masm=intel -O0 -o $@ -c ${WINDIR}/winlink.cpp + ${CPPC} -O0 ${CFLAGS} -masm=intel -o $@ -c ${WINDIR}/winlink.cpp clean: ${DELETECOMMAND} ${EXE} diff --git a/zsnes/src/win/winlink.cpp b/zsnes/src/win/winlink.cpp index b9e49a15..626349e5 100644 --- a/zsnes/src/win/winlink.cpp +++ b/zsnes/src/win/winlink.cpp @@ -22,7 +22,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - #define DIRECTINPUT_VERSION 0x0800 #define DIRECTSOUND_VERSION 0x0800 @@ -236,6 +235,14 @@ extern "C" void FreeDirectX() exit(0); } +extern "C" void DXLoadError() +{ + if (MessageBox(NULL, "Sorry, you need to install or reinstall DirectX v8.0 or higher\nto use ZSNESW.\nWould you like to go to the DirectX homepage?", "Error", MB_ICONINFORMATION | MB_YESNO) == IDYES) + { + ShellExecute(NULL, NULL, "http://www.microsoft.com/directx/", NULL, NULL, 0); + } + FreeDirectX(); +} extern "C" void ImportDirectX() { @@ -243,9 +250,7 @@ extern "C" void ImportDirectX() if (hM_dinput8 == NULL) { - if (MessageBox(NULL, "Sorry, you need DirectX v8.0 or higher to use\nZSNESW. Would you like to go to the DirectX homepage?", "Error", MB_ICONINFORMATION | MB_YESNO) == IDYES) - ShellExecute(NULL, NULL, "http://www.microsoft.com/directx/", NULL, NULL, 0); - FreeDirectX(); + DXLoadError(); } pDirectInput8Create = (lpDirectInput8Create) GetProcAddress(hM_dinput8, dinput8_imp); @@ -255,7 +260,7 @@ extern "C" void ImportDirectX() char err[256]; wsprintf(err,"Failed to import %s:%s", dinput8_dll, dinput8_imp); MessageBox(NULL, err, "Error", MB_ICONERROR); - FreeDirectX(); + DXLoadError(); } hM_ddraw = LoadLibrary(ddraw_dll); @@ -265,7 +270,7 @@ extern "C" void ImportDirectX() char err[256]; wsprintf(err,"Failed to import %s",ddraw_dll); MessageBox(NULL, err,"Error",MB_ICONERROR); - FreeDirectX(); + DXLoadError(); } pDirectDrawCreateEx = (lpDirectDrawCreateEx) GetProcAddress(hM_ddraw, ddraw_imp); @@ -275,7 +280,7 @@ extern "C" void ImportDirectX() char err[256]; wsprintf(err,"Failed to import %s:%s", ddraw_dll, ddraw_imp); MessageBox(NULL, err, "Error", MB_ICONERROR); - FreeDirectX(); + DXLoadError(); } hM_dsound = LoadLibrary(dsound_dll); @@ -285,7 +290,7 @@ extern "C" void ImportDirectX() char err[256]; wsprintf(err,"Failed to import %s",dsound_dll); MessageBox(NULL, err,"Error",MB_ICONERROR); - FreeDirectX(); + DXLoadError(); } pDirectSoundCreate8 = (lpDirectSoundCreate8) GetProcAddress(hM_dsound, dsound_imp); @@ -295,23 +300,17 @@ extern "C" void ImportDirectX() char err[256]; wsprintf(err,"Failed to import %s:%s", dsound_dll, dsound_imp); MessageBox(NULL, err, "Error", MB_ICONERROR); - FreeDirectX(); + DXLoadError(); } } -//Nach: I'm not sure why we have such a number for NTSC, but MinGW -//is using floating point arithmetic with it and going really slow. -//So for MinGW I set it to the same idea as PAL -#ifdef __GNUC__ -#define UPDATE_TICKS_GAME (1000/60) -#else -#define UPDATE_TICKS_GAME (1000.855001760297741789468390082/60) // milliseconds per world update -#endif -#define UPDATE_TICKS_GAMEPAL (1000/50) // milliseconds per world update -#define UPDATE_TICKS_GUI (1000/36) // milliseconds per world update -#define UPDATE_TICKS_UDP (1000/60) // milliseconds per world update +// milliseconds per world update +#define UPDATE_TICKS_GAME (1000.855001760297741789468390082/60.0) +#define UPDATE_TICKS_GAMEPAL (20.0) +#define UPDATE_TICKS_GUI (1000.0/36.0) +#define UPDATE_TICKS_UDP (1000.0/60.0) -__int64 start, end, freq, update_ticks_pc, start2, end2, update_ticks_pc2; +double start, end, freq, update_ticks_pc, start2, end2, update_ticks_pc2; void ReleaseDirectDraw(); void ReleaseDirectSound(); @@ -1777,15 +1776,15 @@ extern unsigned char romispal; void Start60HZ(void) { - update_ticks_pc2 = UPDATE_TICKS_UDP * freq / 1000; + update_ticks_pc2 = UPDATE_TICKS_UDP * freq / 1000.0; if (romispal==1) { - update_ticks_pc = UPDATE_TICKS_GAMEPAL * freq / 1000; + update_ticks_pc = UPDATE_TICKS_GAMEPAL * freq / 1000.0; } else { - update_ticks_pc = (__int64) (UPDATE_TICKS_GAME * freq / 1000); + update_ticks_pc = UPDATE_TICKS_GAME * freq / 1000.0; } QueryPerformanceCounter((LARGE_INTEGER*)&start); @@ -1806,8 +1805,8 @@ void Stop60HZ(void) void Start36HZ(void) { - update_ticks_pc2 = UPDATE_TICKS_UDP * freq / 1000; - update_ticks_pc = UPDATE_TICKS_GUI * freq / 1000; + update_ticks_pc2 = UPDATE_TICKS_UDP * freq / 1000.0; + update_ticks_pc = UPDATE_TICKS_GUI * freq / 1000.0; QueryPerformanceCounter((LARGE_INTEGER*)&start); QueryPerformanceCounter((LARGE_INTEGER*)&start2); @@ -3039,12 +3038,12 @@ void FrameSemaphore() { if (T60HZEnabled == 1) { - int delay; + double delay; QueryPerformanceCounter((LARGE_INTEGER*)&end); - delay = (int) ((update_ticks_pc - (end - start)) * 1000 / freq) - 3; + delay = ((update_ticks_pc - (end - start)) * 1000.0 / freq) - 3.0; - if (delay>0) WaitForSingleObject(hLock, delay); + if (delay>0.0) WaitForSingleObject(hLock, (unsigned int)delay); } } @@ -3057,4 +3056,3 @@ void ZsnesPage() } } -