diff --git a/stella/Changes.txt b/stella/Changes.txt index 97a9d33e8..024cb153f 100644 --- a/stella/Changes.txt +++ b/stella/Changes.txt @@ -30,6 +30,12 @@ calculation. Also, re-enabled changing the framerate from within the UI. + * Added '-timing' commandline argument, which sets the type of waiting + between processing frames. Setting it to 'sleep' emulates the + previous behaviour in Stella; setting it to 'busy' emulates z26, + and can in some cases eliminate screen tearing (at the expense of + using all available CPU time). + * Fixed issue with debugger disassembly and mirrored $40 TIA write addresses. They were actually defined at $30, and generating incorrect labels. diff --git a/stella/docs/index.html b/stella/docs/index.html index 36b502d9d..81ea2d38b 100644 --- a/stella/docs/index.html +++ b/stella/docs/index.html @@ -240,6 +240,12 @@ calculation. Also, re-enabled changing the framerate from within the UI. +
  • Added '-timing' commandline argument, which sets the type of waiting + between processing frames. Setting it to 'sleep' emulates the + previous behaviour in Stella; setting it to 'busy' emulates z26, + and can in some cases eliminate screen tearing (at the expense of + using all available CPU time).
  • +
  • Fixed issue with debugger disassembly and mirrored $40 TIA write addresses. They were actually defined at $30, and generating incorrect labels.
  • @@ -657,6 +663,16 @@ Enable/disable the PAL color-loss effect. + +
    -timing <sleep|busy>
    + Determines type of wait to perform between processing frames. + Sleep will release the CPU as much as possible, and is the + preferred method on laptops (and other low-powered devices) + and when using GL VSync. Busy will emulate z26 busy-wait + behaviour, and use all possible CPU time, but may eliminate + graphical 'tearing'. + +
    -framerate <number>
    Display the given number of frames per second. Normally, Stella diff --git a/stella/src/emucore/OSystem.cxx b/stella/src/emucore/OSystem.cxx index 54ef61009..da4d27525 100644 --- a/stella/src/emucore/OSystem.cxx +++ b/stella/src/emucore/OSystem.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: OSystem.cxx,v 1.128 2008-05-21 14:50:41 stephena Exp $ +// $Id: OSystem.cxx,v 1.129 2008-05-21 16:49:07 stephena Exp $ //============================================================================ #include @@ -797,20 +797,42 @@ void OSystem::stateChanged(EventHandler::State state) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void OSystem::mainLoop() { - for(;;) + if(mySettings->getString("timing") == "sleep") { - myTimingInfo.start = getTicks(); - myEventHandler->poll(myTimingInfo.start); - if(myQuitLoop) break; // Exit if the user wants to quit - myFrameBuffer->update(); - myTimingInfo.current = getTicks(); - myTimingInfo.virt += myTimePerFrame; + // Sleep-based wait: good for CPU, bad for graphical sync + for(;;) + { + myTimingInfo.start = getTicks(); + myEventHandler->poll(myTimingInfo.start); + if(myQuitLoop) break; // Exit if the user wants to quit + myFrameBuffer->update(); + myTimingInfo.current = getTicks(); + myTimingInfo.virt += myTimePerFrame; - if(myTimingInfo.current < myTimingInfo.virt) - SDL_Delay((myTimingInfo.virt - myTimingInfo.current) / 1000); + if(myTimingInfo.current < myTimingInfo.virt) + SDL_Delay((myTimingInfo.virt - myTimingInfo.current) / 1000); - myTimingInfo.totalTime += (getTicks() - myTimingInfo.start); - myTimingInfo.totalFrames++; + myTimingInfo.totalTime += (getTicks() - myTimingInfo.start); + myTimingInfo.totalFrames++; + } + } + else + { + // Busy-wait: bad for CPU, good for graphical sync + for(;;) + { + myTimingInfo.start = getTicks(); + myEventHandler->poll(myTimingInfo.start); + if(myQuitLoop) break; // Exit if the user wants to quit + myFrameBuffer->update(); + myTimingInfo.virt += myTimePerFrame; + + while(getTicks() < myTimingInfo.virt) + ; // busy-wait + + myTimingInfo.totalTime += (getTicks() - myTimingInfo.start); + myTimingInfo.totalFrames++; + } } } diff --git a/stella/src/emucore/Settings.cxx b/stella/src/emucore/Settings.cxx index afa17eb9d..507f6fd9d 100644 --- a/stella/src/emucore/Settings.cxx +++ b/stella/src/emucore/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.146 2008-05-21 14:01:30 stephena Exp $ +// $Id: Settings.cxx,v 1.147 2008-05-21 16:49:07 stephena Exp $ //============================================================================ #include @@ -55,6 +55,7 @@ Settings::Settings(OSystem* osystem) setInternal("grabmouse", "false"); setInternal("palette", "standard"); setInternal("colorloss", "false"); + setInternal("timing", "sleep"); // Sound options setInternal("sound", "true"); @@ -214,6 +215,10 @@ void Settings::validate() if(s != "soft" && s != "gl") setInternal("video", "soft"); + s = getString("timing"); + if(s != "sleep" && s != "busy") + setInternal("timing", "sleep"); + #ifdef DISPLAY_OPENGL s = getString("gl_filter"); if(s != "linear" && s != "nearest") @@ -308,6 +313,7 @@ void Settings::usage() << " user>\n" << " -colorloss <1|0> Enable PAL color-loss effect\n" << " -framerate Display the given number of frames per second (0 to auto-calculate)\n" + << " -timing Use the given type of wait between frames\n" << endl #ifdef SOUND_SUPPORT << " -sound <1|0> Enable sound generation\n"