From a6d330fa2cc55d7210b9e9bba7f011ed8867b731 Mon Sep 17 00:00:00 2001 From: stephena Date: Sun, 4 Aug 2002 00:28:18 +0000 Subject: [PATCH] Removed "Experimental timing" as an option from the Makefile. Option is now always compiled into the SDL and X11 versions. Default is to use the CPU-intensive (normal) timing code. The less CPU- intensive timing can be selected with the commandline argument '-nohog', or by setting 'nohog = 1' in the rc file. Note that the nohog setting works much better in SDL vs. X11, since SDL_Delay() seems to have a finer granularity than usleep(). git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@105 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/build/makefile | 20 ++-- stella/src/stellarc | 1 + stella/src/ui/common/Settings.cxx | 15 ++- stella/src/ui/common/Settings.hxx | 6 +- stella/src/ui/sdl/mainSDL.cxx | 157 +++++++++++++++--------------- stella/src/ui/x11/mainX11.cxx | 156 ++++++++++++++--------------- 6 files changed, 191 insertions(+), 164 deletions(-) diff --git a/stella/src/build/makefile b/stella/src/build/makefile index 5d016976e..a9cf15196 100644 --- a/stella/src/build/makefile +++ b/stella/src/build/makefile @@ -13,7 +13,7 @@ ## See the file "license" for information on usage and redistribution of ## this file, and for a DISCLAIMER OF ALL WARRANTIES. ## -## $Id: makefile,v 1.18 2002-08-03 22:52:39 stephena Exp $ +## $Id: makefile,v 1.19 2002-08-04 00:28:18 stephena Exp $ ##============================================================================ ##============================================================================ @@ -35,8 +35,8 @@ OPTIMIZATIONS = # -malign-functions=2 -malign-jumps=2 -malign-loops=2 ### to get full optimization under gcc/x Athlon based OS's.. # OPTIMIZATIONS = -O3 -mcpu=athlon -march=athlon -Wall -Wno-unused \ - -funroll-loops -fstrength-reduce -fomit-frame-pointer -ffast-math \ - -falign-functions=2 -falign-jumps=2 -falign-loops=2 +# -funroll-loops -fstrength-reduce -fomit-frame-pointer -ffast-math \ +# -falign-functions=2 -falign-jumps=2 -falign-loops=2 ### if your C++ compiler doesn't support the bool type # BSPF_BOOL = 1 @@ -55,10 +55,10 @@ OPTIMIZATIONS = ### Only X11 and SDL ports supported for now # SNAPSHOT_SUPPORT = 1 -### to enable EXPERIMENTAL TIMING code -### Enables emulator to not use 100% CPU -### Only X11 and SDL ports supported for now -# EXPERIMENTAL_TIMING = 1 +### comment this out if your system doesn't +### have the gettimeofday function +### Currently, the X11 version won't compile without it +HAVE_GETTIMEOFDAY = 1 ##============================================================================ ## All done, type make to get a list of frontends @@ -124,9 +124,9 @@ OPTS.SDL += -DHAVE_PNG=1 LIBS.SDL += -lpng endif -ifdef EXPERIMENTAL_TIMING -OPTS.X11 += -DEXPERIMENTAL_TIMING=1 -OPTS.SDL += -DEXPERIMENTAL_TIMING=1 +ifdef HAVE_GETTIMEOFDAY +OPTS.X11 += -DHAVE_GETTIMEOFDAY=1 +OPTS.SDL += -DHAVE_GETTIMEOFDAY=1 endif default: diff --git a/stella/src/stellarc b/stella/src/stellarc index c70b7893e..22eff341b 100644 --- a/stella/src/stellarc +++ b/stella/src/stellarc @@ -27,3 +27,4 @@ ;ssdir = ;ssname = ;sssingle = <0|1> +;nohog = <0|1> diff --git a/stella/src/ui/common/Settings.cxx b/stella/src/ui/common/Settings.cxx index b47afe179..5fb77b6d6 100644 --- a/stella/src/ui/common/Settings.cxx +++ b/stella/src/ui/common/Settings.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Settings.cxx,v 1.1 2002-03-21 22:47:00 stephena Exp $ +// $Id: Settings.cxx,v 1.2 2002-08-04 00:28:18 stephena Exp $ //============================================================================ #include "Settings.hxx" @@ -28,6 +28,7 @@ Settings::Settings() theHideCursorFlag = false; theUsePrivateColormapFlag = false; theMultipleSnapShotFlag = true; + theHogCPUFlag = true; theDesiredVolume = 75; theDesiredFrameRate = 60; thePaddleMode = 0; @@ -106,6 +107,10 @@ bool Settings::handleCommandLineArgs(int argc, char* argv[]) { theShowInfoFlag = true; } + else if(string(argv[i]) == "-nohog") + { + theHogCPUFlag = false; + } else if(string(argv[i]) == "-zoom") { uInt32 size = atoi(argv[++i]); @@ -251,6 +256,14 @@ void Settings::handleRCFile(istream& in) else if(option == 0) theShowInfoFlag = false; } + else if(key == "nohog") + { + uInt32 option = atoi(value.c_str()); + if(option == 1) + theHogCPUFlag = false; + else if(option == 0) + theShowInfoFlag = true; + } else if(key == "zoom") { // They're setting the initial window size diff --git a/stella/src/ui/common/Settings.hxx b/stella/src/ui/common/Settings.hxx index 845b0640e..c8fc1e464 100644 --- a/stella/src/ui/common/Settings.hxx +++ b/stella/src/ui/common/Settings.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Settings.hxx,v 1.1 2002-03-21 22:47:00 stephena Exp $ +// $Id: Settings.hxx,v 1.2 2002-08-04 00:28:18 stephena Exp $ //============================================================================ #ifndef SETTINGS_HXX @@ -53,6 +53,10 @@ class Settings // overwriting the same file. Set to true by default. bool theMultipleSnapShotFlag; + // Indicates whether to use more/less accurate emulation, + // resulting in more/less CPU usage. + bool theHogCPUFlag; + // Indicates what the desired volume is uInt32 theDesiredVolume; diff --git a/stella/src/ui/sdl/mainSDL.cxx b/stella/src/ui/sdl/mainSDL.cxx index 16603ac9c..11f3c4112 100644 --- a/stella/src/ui/sdl/mainSDL.cxx +++ b/stella/src/ui/sdl/mainSDL.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: mainSDL.cxx,v 1.24 2002-05-14 18:29:44 stephena Exp $ +// $Id: mainSDL.cxx,v 1.25 2002-08-04 00:28:18 stephena Exp $ //============================================================================ #include @@ -52,7 +52,6 @@ #define SDL_DISABLE 0 #endif -#define HAVE_GETTIMEOFDAY 1 #define MESSAGE_INTERVAL 2 // function prototypes @@ -1329,6 +1328,7 @@ void usage() " -sssingle Generate single snapshot instead of many", #endif " -pro Use the given properties file instead of stella.pro", + " -nohog Don't take all the CPU (gives less accurate emulation)", "", 0 }; @@ -1576,89 +1576,94 @@ int main(int argc, char* argv[]) return 0; } -#ifdef EXPERIMENTAL_TIMING - // Set up timing stuff - uInt32 startTime, frameTime, virtualTime, currentTime; - uInt32 numberOfFrames = 0; - uInt32 timePerFrame = (uInt32) (1000000.0 / (double) settings->theDesiredFrameRate); + // These variables are common to both timing options + // and are needed to calculate the overall frames per second. + uInt32 frameTime = 0, numberOfFrames = 0; - // Set the base for the timers - virtualTime = getTicks(); - frameTime = 0; - - // Main game loop - for(;;) + if(settings->theHogCPUFlag) // normal, CPU-intensive timing { - // Exit if the user wants to quit - if(theQuitIndicator) - { - break; - } + // Set up accurate timing stuff + uInt32 startTime, delta; + uInt32 timePerFrame = (uInt32) (1000000.0 / (double) settings->theDesiredFrameRate); - startTime = getTicks(); - if(!thePauseIndicator) - { - theConsole->mediaSource().update(); - } - updateDisplay(theConsole->mediaSource()); - handleEvents(); + // Set the base for the timers + frameTime = 0; - currentTime = getTicks(); - virtualTime += timePerFrame; - if(currentTime < virtualTime) - { - SDL_Delay((virtualTime - currentTime)/1000); - } - - currentTime = getTicks() - startTime; - frameTime += currentTime; - ++numberOfFrames; - } -#else - // Set up timing stuff - uInt32 startTime, frameTime, delta; - uInt32 numberOfFrames = 0; - uInt32 timePerFrame = (uInt32) (1000000.0 / (double) settings->theDesiredFrameRate); - - // Set the base for the timers - frameTime = 0; - - // Main game loop - for(;;) - { - // Exit if the user wants to quit - if(theQuitIndicator) - { - break; - } - - // Call handleEvents here to see if user pressed pause - handleEvents(); - if(thePauseIndicator) - { - updateDisplay(theConsole->mediaSource()); - SDL_Delay(10); - continue; - } - - startTime = getTicks(); - theConsole->mediaSource().update(); - updateDisplay(theConsole->mediaSource()); - handleEvents(); - - // Now, waste time if we need to so that we are at the desired frame rate + // Main game loop for(;;) { - delta = getTicks() - startTime; - - if(delta >= timePerFrame) + // Exit if the user wants to quit + if(theQuitIndicator) + { break; - } + } - frameTime += getTicks() - startTime; - ++numberOfFrames; + // Call handleEvents here to see if user pressed pause + handleEvents(); + if(thePauseIndicator) + { + updateDisplay(theConsole->mediaSource()); + SDL_Delay(10); + continue; + } + + startTime = getTicks(); + theConsole->mediaSource().update(); + updateDisplay(theConsole->mediaSource()); + handleEvents(); + + // Now, waste time if we need to so that we are at the desired frame rate + for(;;) + { + delta = getTicks() - startTime; + + if(delta >= timePerFrame) + break; + } + + frameTime += getTicks() - startTime; + ++numberOfFrames; + } + } + else // less accurate, less CPU-intensive timing + { + // Set up less accurate timing stuff + uInt32 startTime, virtualTime, currentTime; + uInt32 timePerFrame = (uInt32) (1000000.0 / (double) settings->theDesiredFrameRate); + + // Set the base for the timers + virtualTime = getTicks(); + frameTime = 0; + + // Main game loop + for(;;) + { + // Exit if the user wants to quit + if(theQuitIndicator) + { + break; + } + + startTime = getTicks(); + if(!thePauseIndicator) + { + theConsole->mediaSource().update(); + } + updateDisplay(theConsole->mediaSource()); + handleEvents(); + + currentTime = getTicks(); + virtualTime += timePerFrame; + if(currentTime < virtualTime) + { + SDL_Delay((virtualTime - currentTime)/1000); + } + + currentTime = getTicks() - startTime; + frameTime += currentTime; + ++numberOfFrames; + } } -#endif if(settings->theShowInfoFlag) { diff --git a/stella/src/ui/x11/mainX11.cxx b/stella/src/ui/x11/mainX11.cxx index 40ca0f795..cf2a28408 100644 --- a/stella/src/ui/x11/mainX11.cxx +++ b/stella/src/ui/x11/mainX11.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: mainX11.cxx,v 1.24 2002-05-14 18:29:45 stephena Exp $ +// $Id: mainX11.cxx,v 1.25 2002-08-04 00:28:18 stephena Exp $ //============================================================================ #include @@ -53,7 +53,6 @@ #include #endif -#define HAVE_GETTIMEOFDAY 1 #define MESSAGE_INTERVAL 2 // A graphic context for each of the 2600's colors @@ -1468,89 +1467,94 @@ int main(int argc, char* argv[]) return 0; } -#ifdef EXPERIMENTAL_TIMING - // Set up timing stuff - uInt32 startTime, frameTime, virtualTime, currentTime; - uInt32 numberOfFrames = 0; - uInt32 timePerFrame = (uInt32) (1000000.0 / (double) settings->theDesiredFrameRate); + // These variables are common to both timing options + // and are needed to calculate the overall frames per second. + uInt32 frameTime = 0, numberOfFrames = 0; - // Set the base for the timers - virtualTime = getTicks(); - frameTime = 0; - - // Main game loop - for(;;) + if(settings->theHogCPUFlag) // normal, CPU-intensive timing { - // Exit if the user wants to quit - if(theQuitIndicator) - { - break; - } + // Set up timing stuff + uInt32 startTime, delta; + uInt32 timePerFrame = (uInt32) (1000000.0 / (double) settings->theDesiredFrameRate); - startTime = getTicks(); - if(!thePauseIndicator) - { - theConsole->mediaSource().update(); - } - updateDisplay(theConsole->mediaSource()); - handleEvents(); + // Set the base for the timers + frameTime = 0; - currentTime = getTicks(); - virtualTime += timePerFrame; - if(currentTime < virtualTime) - { - usleep(virtualTime - currentTime); - } - - currentTime = getTicks() - startTime; - frameTime += currentTime; - ++numberOfFrames; - } -#else - // Set up timing stuff - uInt32 startTime, frameTime, delta; - uInt32 numberOfFrames = 0; - uInt32 timePerFrame = (uInt32) (1000000.0 / (double) settings->theDesiredFrameRate); - - // Set the base for the timers - frameTime = 0; - - // Main game loop - for(;;) - { - // Exit if the user wants to quit - if(theQuitIndicator) - { - break; - } - - // Call handleEvents here to see if user pressed pause - handleEvents(); - if(thePauseIndicator) - { - updateDisplay(theConsole->mediaSource()); - usleep(10000); - continue; - } - - startTime = getTicks(); - theConsole->mediaSource().update(); - updateDisplay(theConsole->mediaSource()); - handleEvents(); - - // Now, waste time if we need to so that we are at the desired frame rate + // Main game loop for(;;) { - delta = getTicks() - startTime; - - if(delta >= timePerFrame) + // Exit if the user wants to quit + if(theQuitIndicator) + { break; - } + } - frameTime += getTicks() - startTime; - ++numberOfFrames; + // Call handleEvents here to see if user pressed pause + handleEvents(); + if(thePauseIndicator) + { + updateDisplay(theConsole->mediaSource()); + usleep(10000); + continue; + } + + startTime = getTicks(); + theConsole->mediaSource().update(); + updateDisplay(theConsole->mediaSource()); + handleEvents(); + + // Now, waste time if we need to so that we are at the desired frame rate + for(;;) + { + delta = getTicks() - startTime; + + if(delta >= timePerFrame) + break; + } + + frameTime += getTicks() - startTime; + ++numberOfFrames; + } + } + else // less accurate, less CPU-intensive timing + { + // Set up timing stuff + uInt32 startTime, virtualTime, currentTime; + uInt32 timePerFrame = (uInt32) (1000000.0 / (double) settings->theDesiredFrameRate); + + // Set the base for the timers + virtualTime = getTicks(); + frameTime = 0; + + // Main game loop + for(;;) + { + // Exit if the user wants to quit + if(theQuitIndicator) + { + break; + } + + startTime = getTicks(); + if(!thePauseIndicator) + { + theConsole->mediaSource().update(); + } + updateDisplay(theConsole->mediaSource()); + handleEvents(); + + currentTime = getTicks(); + virtualTime += timePerFrame; + if(currentTime < virtualTime) + { + usleep(virtualTime - currentTime); + } + + currentTime = getTicks() - startTime; + frameTime += currentTime; + ++numberOfFrames; + } } -#endif if(settings->theShowInfoFlag) {