diff --git a/Changes.txt b/Changes.txt index 2e83aa932..a1434a111 100644 --- a/Changes.txt +++ b/Changes.txt @@ -24,6 +24,9 @@ this, further optimized the TIA rendering code. Thanks to Thomas Jentzsch for the bulk of the work in this area. + * Added 'threads' commandline argument and associated UI item to + enable/disable multi-threading. + * Updated CDF scheme to latest version from Spiceware. In addition, this scheme now supports versioning, so older and newer ROMs will continue to work. diff --git a/src/common/tv_filters/AtariNTSC.cxx b/src/common/tv_filters/AtariNTSC.cxx index 743bceebe..8079b9598 100644 --- a/src/common/tv_filters/AtariNTSC.cxx +++ b/src/common/tv_filters/AtariNTSC.cxx @@ -35,22 +35,6 @@ void AtariNTSC::initialize(const Setup& setup, const uInt8* palette) { init(myImpl, setup); initializePalette(palette); - - uInt32 systemThreads = std::thread::hardware_concurrency(); - if(systemThreads <= 1) - { - myWorkerThreads = 0; - myTotalThreads = 1; - } - else - { - systemThreads = std::min(4u, systemThreads); - - myWorkerThreads = systemThreads - 1; - myTotalThreads = systemThreads; - - myThreads = make_unique(myWorkerThreads); - } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -82,6 +66,26 @@ void AtariNTSC::initializePalette(const uInt8* palette) } } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void AtariNTSC::enableThreading(bool enable) +{ + uInt32 systemThreads = enable ? std::thread::hardware_concurrency() : 0; + if(systemThreads <= 1) + { + myWorkerThreads = 0; + myTotalThreads = 1; + } + else + { + systemThreads = std::min(4u, systemThreads); + + myWorkerThreads = systemThreads - 1; + myTotalThreads = systemThreads; + + myThreads = make_unique(myWorkerThreads); + } +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void AtariNTSC::render(const uInt8* atari_in, const uInt32 in_width, const uInt32 in_height, void* rgb_out, const uInt32 out_pitch, uInt32* rgb_in) diff --git a/src/common/tv_filters/AtariNTSC.hxx b/src/common/tv_filters/AtariNTSC.hxx index 44ffc294c..1ec08c8c0 100644 --- a/src/common/tv_filters/AtariNTSC.hxx +++ b/src/common/tv_filters/AtariNTSC.hxx @@ -51,6 +51,9 @@ class AtariNTSC entry_size = 2 * 14, }; + // By default, threading is turned off + AtariNTSC() { enableThreading(false); } + // Image parameters, ranging from -1.0 to 1.0. Actual internal values shown // in parenthesis and should remain fairly stable in future versions. struct Setup @@ -80,6 +83,9 @@ class AtariNTSC void initialize(const Setup& setup, const uInt8* palette); void initializePalette(const uInt8* palette); + // Set up threading + void enableThreading(bool enable); + // Set phosphor palette, for use in Blargg + phosphor mode void setPhosphorPalette(uInt8 palette[256][256]) { memcpy(myPhosphorPalette, palette, 256 * 256); diff --git a/src/common/tv_filters/NTSCFilter.hxx b/src/common/tv_filters/NTSCFilter.hxx index bdb63f3f9..987687fc5 100644 --- a/src/common/tv_filters/NTSCFilter.hxx +++ b/src/common/tv_filters/NTSCFilter.hxx @@ -120,6 +120,12 @@ class NTSCFilter myNTSC.render(src_buf, src_width, src_height, dest_buf, dest_pitch, prev_buf); } + // Enable threading for the NTSC rendering + inline void enableThreading(bool enable) + { + myNTSC.enableThreading(enable); + } + private: // Convert from atari_ntsc_setup_t values to equivalent adjustables void convertToAdjustable(Adjustable& adjustable, diff --git a/src/emucore/Settings.cxx b/src/emucore/Settings.cxx index 9e792e4a7..9b97f4522 100644 --- a/src/emucore/Settings.cxx +++ b/src/emucore/Settings.cxx @@ -139,6 +139,7 @@ Settings::Settings(OSystem& osystem) setInternal("avoxport", ""); setInternal("stats", "false"); setInternal("fastscbios", "true"); + setInternal("threads", "false"); setExternal("romloadcount", "0"); setExternal("maxres", ""); @@ -424,6 +425,7 @@ void Settings::usage() const << " -autoslot <1|0> Automatically switch to next save slot when state saving\n" << " -stats <1|0> Overlay console info during emulation\n" << " -fastscbios <1|0> Disable Supercharger BIOS progress loading bars\n" + << " -threads <1|0> Whether to using multi-threading during emulation\n" << " -snapsavedir The directory to save snapshot files to\n" << " -snaploaddir The directory to load snapshot files from\n" << " -snapname Name snapshots according to internal database or ROM\n" diff --git a/src/emucore/TIASurface.cxx b/src/emucore/TIASurface.cxx index 98ccac443..f46162b94 100644 --- a/src/emucore/TIASurface.cxx +++ b/src/emucore/TIASurface.cxx @@ -56,6 +56,9 @@ TIASurface::TIASurface(OSystem& system) myBaseTiaSurface = myFB.allocateSurface(kTIAW*2, kTIAH); memset(myRGBFramebuffer, 0, AtariNTSC::outWidth(kTIAW) * kTIAH); + + // Enable/disable threading in the NTSC TV effects renderer + myNTSCFilter.enableThreading(myOSystem.settings().getBool("threads")); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -