diff --git a/src/libretro/EventHandlerLIBRETRO.cxx b/src/libretro/EventHandlerLIBRETRO.cxx deleted file mode 100644 index 05b87b931..000000000 --- a/src/libretro/EventHandlerLIBRETRO.cxx +++ /dev/null @@ -1,39 +0,0 @@ -//============================================================================ -// -// SSSS tt lll lll -// SS SS tt ll ll -// SS tttttt eeee ll ll aaaa -// SSSS tt ee ee ll ll aa -// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" -// SS SS tt ee ll ll aa aa -// SSSS ttt eeeee llll llll aaaaa -// -// Copyright (c) 1995-2022 by Bradford W. Mott, Stephen Anthony -// and the Stella Team -// -// See the file "License.txt" for information on usage and redistribution of -// this file, and for a DISCLAIMER OF ALL WARRANTIES. -//============================================================================ - -#include "EventHandlerLIBRETRO.hxx" - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -EventHandlerLIBRETRO::EventHandlerLIBRETRO(OSystem& osystem) - : EventHandler(osystem) -{ -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -EventHandlerLIBRETRO::~EventHandlerLIBRETRO() -{ -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void EventHandlerLIBRETRO::enableTextEvents(bool enable) -{ -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void EventHandlerLIBRETRO::pollEvent() -{ -} diff --git a/src/libretro/EventHandlerLIBRETRO.hxx b/src/libretro/EventHandlerLIBRETRO.hxx index d06d6f286..1f929c0df 100644 --- a/src/libretro/EventHandlerLIBRETRO.hxx +++ b/src/libretro/EventHandlerLIBRETRO.hxx @@ -33,19 +33,19 @@ class EventHandlerLIBRETRO : public EventHandler /** Create a new LIBRETRO event handler object */ - explicit EventHandlerLIBRETRO(OSystem& osystem); - ~EventHandlerLIBRETRO() override; + explicit EventHandlerLIBRETRO(OSystem& osystem) : EventHandler(osystem) { } + ~EventHandlerLIBRETRO() override = default; private: /** Enable/disable text events (distinct from single-key events). */ - void enableTextEvents(bool enable) override; + void enableTextEvents(bool enable) override { } /** Collects and dispatches any pending SDL2 events. */ - void pollEvent() override; + void pollEvent() override { } private: // Following constructors and assignment operators not supported diff --git a/src/libretro/FBBackendLIBRETRO.cxx b/src/libretro/FBBackendLIBRETRO.cxx deleted file mode 100644 index ae60fd15d..000000000 --- a/src/libretro/FBBackendLIBRETRO.cxx +++ /dev/null @@ -1,38 +0,0 @@ -//============================================================================ -// -// SSSS tt lll lll -// SS SS tt ll ll -// SS tttttt eeee ll ll aaaa -// SSSS tt ee ee ll ll aa -// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" -// SS SS tt ee ll ll aa aa -// SSSS ttt eeeee llll llll aaaaa -// -// Copyright (c) 1995-2022 by Bradford W. Mott, Stephen Anthony -// and the Stella Team -// -// See the file "License.txt" for information on usage and redistribution of -// this file, and for a DISCLAIMER OF ALL WARRANTIES. -//============================================================================ - -#include "bspf.hxx" -#include "FBSurfaceLIBRETRO.hxx" -#include "FBBackendLIBRETRO.hxx" - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FBBackendLIBRETRO::queryHardware(vector& fullscreenRes, - vector& windowedRes, - VariantList& renderers) -{ - fullscreenRes.emplace_back(1920, 1080); - windowedRes.emplace_back(1920, 1080); - - VarList::push_back(renderers, "software", "Software"); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -unique_ptr FBBackendLIBRETRO::createSurface( - uInt32 w, uInt32 h, ScalingInterpolation, const uInt32*) const -{ - return make_unique(w, h); -} diff --git a/src/libretro/FBBackendLIBRETRO.hxx b/src/libretro/FBBackendLIBRETRO.hxx index c8b9d4c3b..1079560a3 100644 --- a/src/libretro/FBBackendLIBRETRO.hxx +++ b/src/libretro/FBBackendLIBRETRO.hxx @@ -22,6 +22,7 @@ class OSystem; #include "bspf.hxx" #include "FBBackend.hxx" +#include "FBSurfaceLIBRETRO.hxx" /** This class implements a standard LIBRETRO framebuffer backend. Most of @@ -58,7 +59,13 @@ class FBBackendLIBRETRO : public FBBackend */ void queryHardware(vector& fullscreenRes, vector& windowedRes, - VariantList& renderers) override; + VariantList& renderers) override + { + fullscreenRes.emplace_back(1920, 1080); + windowedRes.emplace_back(1920, 1080); + + VarList::push_back(renderers, "software", "Software"); + } /** This method is called to create a surface with the given attributes. @@ -68,7 +75,10 @@ class FBBackendLIBRETRO : public FBBackend */ unique_ptr createSurface(uInt32 w, uInt32 h, ScalingInterpolation, - const uInt32*) const override; + const uInt32*) const override + { + return make_unique(w, h); + } /** This method is called to provide information about the backend. diff --git a/src/libretro/FBSurfaceLIBRETRO.cxx b/src/libretro/FBSurfaceLIBRETRO.cxx deleted file mode 100644 index 736a441c9..000000000 --- a/src/libretro/FBSurfaceLIBRETRO.cxx +++ /dev/null @@ -1,31 +0,0 @@ -//============================================================================ -// -// SSSS tt lll lll -// SS SS tt ll ll -// SS tttttt eeee ll ll aaaa -// SSSS tt ee ee ll ll aa -// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" -// SS SS tt ee ll ll aa aa -// SSSS ttt eeeee llll llll aaaaa -// -// Copyright (c) 1995-2022 by Bradford W. Mott, Stephen Anthony -// and the Stella Team -// -// See the file "License.txt" for information on usage and redistribution of -// this file, and for a DISCLAIMER OF ALL WARRANTIES. -//============================================================================ - -#include "FBSurfaceLIBRETRO.hxx" - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -FBSurfaceLIBRETRO::FBSurfaceLIBRETRO(uInt32 width, uInt32 height) - : myWidth{width}, - myHeight{height}, - myPixelData{make_unique(myWidth * myHeight)} -{ - //////////////////////////////////////////////////// - // These *must* be set for the parent class - myPixels = myPixelData.get(); - myPitch = myWidth; - //////////////////////////////////////////////////// -} diff --git a/src/libretro/FBSurfaceLIBRETRO.hxx b/src/libretro/FBSurfaceLIBRETRO.hxx index 482f45abb..35346c33b 100644 --- a/src/libretro/FBSurfaceLIBRETRO.hxx +++ b/src/libretro/FBSurfaceLIBRETRO.hxx @@ -30,7 +30,17 @@ class FBSurfaceLIBRETRO : public FBSurface { public: - FBSurfaceLIBRETRO(uInt32 width, uInt32 height); + FBSurfaceLIBRETRO(uInt32 width, uInt32 height) + : myWidth{width}, + myHeight{height}, + myPixelData{make_unique(myWidth * myHeight)} + { + //////////////////////////////////////////////////// + // These *must* be set for the parent class + myPixels = myPixelData.get(); + myPitch = myWidth; + //////////////////////////////////////////////////// + } ~FBSurfaceLIBRETRO() override { } // Most of the surface drawing primitives are implemented in FBSurface; diff --git a/src/libretro/Makefile.common b/src/libretro/Makefile.common index 13926bb04..782ce2e4c 100644 --- a/src/libretro/Makefile.common +++ b/src/libretro/Makefile.common @@ -7,12 +7,7 @@ endif SOURCES_CXX := \ $(CORE_DIR)/libretro/libretro.cxx \ - $(CORE_DIR)/libretro/EventHandlerLIBRETRO.cxx \ $(CORE_DIR)/libretro/FSNodeLIBRETRO.cxx \ - $(CORE_DIR)/libretro/FBBackendLIBRETRO.cxx \ - $(CORE_DIR)/libretro/FBSurfaceLIBRETRO.cxx \ - $(CORE_DIR)/libretro/OSystemLIBRETRO.cxx \ - $(CORE_DIR)/libretro/SoundLIBRETRO.cxx \ $(CORE_DIR)/libretro/StellaLIBRETRO.cxx \ $(CORE_DIR)/common/AudioQueue.cxx \ $(CORE_DIR)/common/AudioSettings.cxx \ diff --git a/src/libretro/OSystemLIBRETRO.cxx b/src/libretro/OSystemLIBRETRO.cxx deleted file mode 100644 index d702792c3..000000000 --- a/src/libretro/OSystemLIBRETRO.cxx +++ /dev/null @@ -1,63 +0,0 @@ -//============================================================================ -// -// SSSS tt lll lll -// SS SS tt ll ll -// SS tttttt eeee ll ll aaaa -// SSSS tt ee ee ll ll aa -// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" -// SS SS tt ee ll ll aa aa -// SSSS ttt eeeee llll llll aaaaa -// -// Copyright (c) 1995-2022 by Bradford W. Mott, Stephen Anthony -// and the Stella Team -// -// See the file "License.txt" for information on usage and redistribution of -// this file, and for a DISCLAIMER OF ALL WARRANTIES. -//============================================================================ - -#include "FSNode.hxx" -#include "OSystemLIBRETRO.hxx" -#include "repository/KeyValueRepositoryNoop.hxx" -#include "repository/CompositeKeyValueRepositoryNoop.hxx" - -#ifdef _WIN32 - const string slash = "\\"; -#else - const string slash = "/"; -#endif - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void OSystemLIBRETRO::getBaseDirectories(string& basedir, string& homedir, - bool useappdir, const string& usedir) -{ - basedir = homedir = "." + slash; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void OSystemLIBRETRO::initPersistence(FSNode& basedir) -{ -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string OSystemLIBRETRO::describePresistence() -{ - return "none"; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -shared_ptr OSystemLIBRETRO::getSettingsRepository() -{ - return make_shared(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -shared_ptr OSystemLIBRETRO::getPropertyRepository() -{ - return make_shared(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -shared_ptr OSystemLIBRETRO::getHighscoreRepository() -{ - return make_shared(); -} diff --git a/src/libretro/OSystemLIBRETRO.hxx b/src/libretro/OSystemLIBRETRO.hxx index 764817322..3e03ccf9e 100644 --- a/src/libretro/OSystemLIBRETRO.hxx +++ b/src/libretro/OSystemLIBRETRO.hxx @@ -18,7 +18,17 @@ #ifndef OSYSTEM_LIBRETRO_HXX #define OSYSTEM_LIBRETRO_HXX +#include "FSNode.hxx" #include "OSystem.hxx" +#include "OSystemLIBRETRO.hxx" +#include "repository/KeyValueRepositoryNoop.hxx" +#include "repository/CompositeKeyValueRepositoryNoop.hxx" + +#ifdef _WIN32 + const string slash = "\\"; +#else + const string slash = "/"; +#endif /** This class defines an OSystem object for libretro. @@ -47,19 +57,29 @@ class OSystemLIBRETRO : public OSystem they are free to ignore it */ void getBaseDirectories(string& basedir, string& homedir, - bool useappdir, const string& usedir) override; + bool useappdir, const string& usedir) override + { + basedir = homedir = "." + slash; + } - shared_ptr getSettingsRepository() override; + shared_ptr + getSettingsRepository() override { + return make_shared(); + } - shared_ptr getPropertyRepository() override; + shared_ptr + getPropertyRepository() override { + return make_shared(); + } - shared_ptr getHighscoreRepository() override; + shared_ptr + getHighscoreRepository() override { + return make_shared(); + } protected: - - void initPersistence(FSNode& basedir) override; - - string describePresistence() override; + void initPersistence(FSNode& basedir) override { } + string describePresistence() override { return "none"; } }; #endif diff --git a/src/libretro/SoundLIBRETRO.cxx b/src/libretro/SoundLIBRETRO.cxx deleted file mode 100644 index f582a02a2..000000000 --- a/src/libretro/SoundLIBRETRO.cxx +++ /dev/null @@ -1,117 +0,0 @@ -//============================================================================ -// -// SSSS tt lll lll -// SS SS tt ll ll -// SS tttttt eeee ll ll aaaa -// SSSS tt ee ee ll ll aa -// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" -// SS SS tt ee ll ll aa aa -// SSSS ttt eeeee llll llll aaaaa -// -// Copyright (c) 1995-2022 by Bradford W. Mott, Stephen Anthony -// and the Stella Team -// -// See the file "License.txt" for information on usage and redistribution of -// this file, and for a DISCLAIMER OF ALL WARRANTIES. -//============================================================================ - -#ifdef SOUND_SUPPORT - -#include -#include -#include - -#include "Logger.hxx" -#include "FrameBuffer.hxx" -#include "Settings.hxx" -#include "System.hxx" -#include "OSystem.hxx" -#include "Console.hxx" -#include "SoundLIBRETRO.hxx" -#include "AudioQueue.hxx" -#include "EmulationTiming.hxx" -#include "AudioSettings.hxx" - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -SoundLIBRETRO::SoundLIBRETRO(OSystem& osystem, AudioSettings& audioSettings) - : Sound(osystem), - myAudioSettings{audioSettings} -{ - Logger::debug("SoundLIBRETRO::SoundLIBRETRO started ..."); - Logger::debug("SoundLIBRETRO::SoundLIBRETRO initialized"); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -SoundLIBRETRO::~SoundLIBRETRO() -{ -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void SoundLIBRETRO::open(shared_ptr audioQueue, - EmulationTiming* emulationTiming) -{ - myEmulationTiming = emulationTiming; - - Logger::debug("SoundLIBRETRO::open started ..."); - - audioQueue->ignoreOverflows(!myAudioSettings.enabled()); - - myAudioQueue = audioQueue; - myUnderrun = true; - myCurrentFragment = nullptr; - - Logger::debug("SoundLIBRETRO::open finished"); - - myIsInitializedFlag = true; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void SoundLIBRETRO::close() -{ - if(!myIsInitializedFlag) return; - - if (myAudioQueue) myAudioQueue->closeSink(myCurrentFragment); - myAudioQueue.reset(); - myCurrentFragment = nullptr; - - Logger::debug("SoundLIBRETRO::close"); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void SoundLIBRETRO::dequeue(Int16* stream, uInt32* samples) -{ - uInt32 outIndex = 0; - - while (myAudioQueue->size()) - { - Int16* nextFragment = myAudioQueue->dequeue(myCurrentFragment); - - if (!nextFragment) - { - *samples = outIndex / 2; - return; - } - - myCurrentFragment = nextFragment; - - for (uInt32 i = 0; i < myAudioQueue->fragmentSize(); ++i) - { - Int16 sampleL, sampleR; - - if (myAudioQueue->isStereo()) - { - sampleL = static_cast(myCurrentFragment[2*i + 0]); - sampleR = static_cast(myCurrentFragment[2*i + 1]); - } - else - sampleL = sampleR = static_cast(myCurrentFragment[i]); - - stream[outIndex++] = sampleL; - stream[outIndex++] = sampleR; - } - } - - *samples = outIndex / 2; -} - -#endif // SOUND_SUPPORT diff --git a/src/libretro/SoundLIBRETRO.hxx b/src/libretro/SoundLIBRETRO.hxx index 79961baab..d626190f1 100644 --- a/src/libretro/SoundLIBRETRO.hxx +++ b/src/libretro/SoundLIBRETRO.hxx @@ -20,13 +20,21 @@ #ifndef SOUND_LIBRETRO_HXX #define SOUND_LIBRETRO_HXX -class OSystem; -class AudioQueue; -class EmulationTiming; -class AudioSettings; +#include +#include +#include #include "bspf.hxx" +#include "Logger.hxx" +#include "FrameBuffer.hxx" +#include "Settings.hxx" +#include "System.hxx" +#include "OSystem.hxx" +#include "Console.hxx" #include "Sound.hxx" +#include "AudioQueue.hxx" +#include "EmulationTiming.hxx" +#include "AudioSettings.hxx" /** This class implements the sound API for LIBRETRO. @@ -40,8 +48,14 @@ class SoundLIBRETRO : public Sound Create a new sound object. The init method must be invoked before using the object. */ - SoundLIBRETRO(OSystem& osystem, AudioSettings& audioSettings); - ~SoundLIBRETRO() override; + SoundLIBRETRO(OSystem& osystem, AudioSettings& audioSettings) + : Sound(osystem), + myAudioSettings{audioSettings} + { + Logger::debug("SoundLIBRETRO::SoundLIBRETRO started ..."); + Logger::debug("SoundLIBRETRO::SoundLIBRETRO initialized"); + } + ~SoundLIBRETRO() override = default; public: /** @@ -49,13 +63,38 @@ class SoundLIBRETRO : public Sound calls are made to derived methods. */ void open(shared_ptr audioQueue, - EmulationTiming* emulationTiming) override; + EmulationTiming* emulationTiming) override + { + myEmulationTiming = emulationTiming; + + Logger::debug("SoundLIBRETRO::open started ..."); + + audioQueue->ignoreOverflows(!myAudioSettings.enabled()); + + myAudioQueue = audioQueue; + myUnderrun = true; + myCurrentFragment = nullptr; + + Logger::debug("SoundLIBRETRO::open finished"); + + myIsInitializedFlag = true; + } /** Should be called to close the sound device. Once called the sound device can be started again using the open method. */ - void close() override; + void close() override + { + if (!myIsInitializedFlag) + return; + if (myAudioQueue) + myAudioQueue->closeSink(myCurrentFragment); + myAudioQueue.reset(); + myCurrentFragment = nullptr; + + Logger::debug("SoundLIBRETRO::close"); + } /** Empties the playback buffer. @@ -63,7 +102,40 @@ class SoundLIBRETRO : public Sound @param stream Output audio buffer @param samples Number of audio samples read */ - void dequeue(Int16* stream, uInt32* samples); + void dequeue(Int16* stream, uInt32* samples) + { + uInt32 outIndex = 0; + + while (myAudioQueue->size()) + { + Int16* nextFragment = myAudioQueue->dequeue(myCurrentFragment); + + if (!nextFragment) + { + *samples = outIndex / 2; + return; + } + + myCurrentFragment = nextFragment; + + for (uInt32 i = 0; i < myAudioQueue->fragmentSize(); ++i) + { + Int16 sampleL, sampleR; + + if (myAudioQueue->isStereo()) + { + sampleL = static_cast(myCurrentFragment[2*i + 0]); + sampleR = static_cast(myCurrentFragment[2*i + 1]); + } + else + sampleL = sampleR = static_cast(myCurrentFragment[i]); + + stream[outIndex++] = sampleL; + stream[outIndex++] = sampleR; + } + } + *samples = outIndex / 2; + } protected: //////////////////////////////////////////////////////////////////////